Commit 4d998b7d authored by hertzhaft's avatar hertzhaft

lock dimension for drawing and editing shapes

parent decbec8d
......@@ -816,12 +816,12 @@
var onPositionShape = function(event, shape) {
var data = this;
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
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
......@@ -989,18 +989,22 @@
// returns a screenpoint manipulation function
var lockDimension = function(dim) {
// lock one dimension of the current screen pos to that of the previous
var lock = function(screenpos) {
if (!$.isArray(screenpos) || screenpos.length < 2) return;
var last = screenpos.length-1;
screenpos[last][dim] = screenpos[last-1][dim];
var lock = function(shape) {
var props = shape.properties;
var startpos = props.startpos;
var screenpos = props.screenpos;
var vtx = props.vtx;
if (startpos == null || screenpos == null || vtx == null) {
return; }
screenpos[vtx][dim] = startpos[dim];
}
return lock;
};
// manipulate the screen points of the shape
var manipulateShapePos = function(shape, func) {
var manipulatePosition = function(shape, manipulate) {
// apply the manipulation function
func(shape.properties.screenpos);
manipulate(shape);
};
// return the current shape type
......
......@@ -492,7 +492,8 @@
// cancel if not left-click
if (evt.which != 1) return;
pStart = geom.position(evt);
shape.properties.screenpos[0] = pStart;
shape.properties.startpos = pStart;
shape.properties.vtx = vtx;
$(data).trigger('positionShape', shape);
if ($.inArray(shapeType, ['Rectangle', 'Circle', 'Ellipse']) > -1) {
// save screen points of coordinates
......@@ -642,7 +643,8 @@
if (shape.properties != null) {
shape.properties._editable = shape.properties.editable;
shape.properties.editable = false;
shape.properties.screenpos = [];
shape.properties.screenpos = [pt];
shape.properties.startpos = [pt];
} else {
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