Commit b8f28846 authored by hertzhaft's avatar hertzhaft

store screen positions on drag; trigger positionShape event

parent 983e8075
...@@ -803,6 +803,12 @@ ...@@ -803,6 +803,12 @@
_debug_shape('onCreateShape', shape); _debug_shape('onCreateShape', shape);
}; };
// event handler for positionShape
var onPositionShape = function(event, shape) {
var data = this;
_debug_shape('onPositionShape', shape.properties.screenpos);
};
// event handler for dragShape // event handler for dragShape
var onDragShape = function(event, shape) { var onDragShape = function(event, shape) {
var data = this; var data = this;
...@@ -1216,6 +1222,7 @@ ...@@ -1216,6 +1222,7 @@
$data.on('createShape', onCreateShape); $data.on('createShape', onCreateShape);
$data.on('renderShape', onRenderShape); $data.on('renderShape', onRenderShape);
$data.on('changeShape', onChangeShape); $data.on('changeShape', onChangeShape);
$data.on('positionShape', onPositionShape);
$data.on('dragShape', onDragShape); $data.on('dragShape', onDragShape);
}; };
......
...@@ -492,6 +492,8 @@ ...@@ -492,6 +492,8 @@
// cancel if not left-click // cancel if not left-click
if (evt.which != 1) return; if (evt.which != 1) return;
pStart = geom.position(evt); pStart = geom.position(evt);
shape.properties.screenpos[0] = pStart;
$(data).trigger('positionShape', shape);
if ($.inArray(shapeType, ['Rectangle', 'Circle', 'Ellipse']) > -1) { if ($.inArray(shapeType, ['Rectangle', 'Circle', 'Ellipse']) > -1) {
// save screen points of coordinates // save screen points of coordinates
pt1 = data.imgTrafo.transform(geom.position(shape.geometry.coordinates[0])); pt1 = data.imgTrafo.transform(geom.position(shape.geometry.coordinates[0]));
...@@ -505,6 +507,8 @@ ...@@ -505,6 +507,8 @@
var dragMove = function (evt) { // dragging var dragMove = function (evt) { // dragging
var pt = geom.position(evt); var pt = geom.position(evt);
shape.properties.screenpos[vtx] = pt;
$(data).trigger('positionShape', shape);
pt.clipTo(imgRect); pt.clipTo(imgRect);
// move handle // move handle
$handle.attr({'x': pt.x-hs/2, 'y': pt.y-hs/2}); $handle.attr({'x': pt.x-hs/2, 'y': pt.y-hs/2});
...@@ -556,6 +560,8 @@ ...@@ -556,6 +560,8 @@
var dragEnd = function (evt) { // end dragging var dragEnd = function (evt) { // end dragging
var pt = geom.position(evt); var pt = geom.position(evt);
shape.properties.screenpos[vtx] = pt;
$(data).trigger('positionShape', shape);
if ((pt.distance(pStart) < 5) && evt.type === 'mouseup') { if ((pt.distance(pStart) < 5) && evt.type === 'mouseup') {
// not drag but click to start // not drag but click to start
return false; return false;
...@@ -636,6 +642,7 @@ ...@@ -636,6 +642,7 @@
if (shape.properties != null) { if (shape.properties != null) {
shape.properties._editable = shape.properties.editable; shape.properties._editable = shape.properties.editable;
shape.properties.editable = false; shape.properties.editable = false;
shape.properties.screenpos = [];
} else { } else {
shape.properties = {'editable' : false}; shape.properties = {'editable' : false};
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment