Commit 4d998b7d authored by hertzhaft's avatar hertzhaft

lock dimension for drawing and editing shapes

parent decbec8d
...@@ -816,12 +816,12 @@ ...@@ -816,12 +816,12 @@
var onPositionShape = function(event, shape) { var onPositionShape = function(event, shape) {
var data = this; var data = this;
if (keystate['x'] != null) { // change only x-Dimension of mouse pointer if (keystate['x'] != null) { // change only x-Dimension of mouse pointer
manipulateShapePos(shape, lockDimension('y')); manipulatePosition(shape, lockDimension('y'));
} }
if (keystate['y'] != null) { // change only y-Dimension of mouse pointer if (keystate['y'] != null) { // change only y-Dimension of mouse pointer
manipulateShapePos(shape, lockDimension('x')); manipulatePosition(shape, lockDimension('x'));
} }
_debug_shape('onPositionShape', keystate, shape.properties.screenpos); // console.debug('onPositionShape', shape.properties.screenpos);
}; };
// event handler for dragShape // event handler for dragShape
...@@ -989,18 +989,22 @@ ...@@ -989,18 +989,22 @@
// returns a screenpoint manipulation function // returns a screenpoint manipulation function
var lockDimension = function(dim) { var lockDimension = function(dim) {
// lock one dimension of the current screen pos to that of the previous // lock one dimension of the current screen pos to that of the previous
var lock = function(screenpos) { var lock = function(shape) {
if (!$.isArray(screenpos) || screenpos.length < 2) return; var props = shape.properties;
var last = screenpos.length-1; var startpos = props.startpos;
screenpos[last][dim] = screenpos[last-1][dim]; var screenpos = props.screenpos;
var vtx = props.vtx;
if (startpos == null || screenpos == null || vtx == null) {
return; }
screenpos[vtx][dim] = startpos[dim];
} }
return lock; return lock;
}; };
// manipulate the screen points of the shape // manipulate the screen points of the shape
var manipulateShapePos = function(shape, func) { var manipulatePosition = function(shape, manipulate) {
// apply the manipulation function // apply the manipulation function
func(shape.properties.screenpos); manipulate(shape);
}; };
// return the current shape type // return the current shape type
......
...@@ -492,7 +492,8 @@ ...@@ -492,7 +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; shape.properties.startpos = pStart;
shape.properties.vtx = vtx;
$(data).trigger('positionShape', shape); $(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
...@@ -642,7 +643,8 @@ ...@@ -642,7 +643,8 @@
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 = []; shape.properties.screenpos = [pt];
shape.properties.startpos = [pt];
} 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