Mercurial > hg > digilib
changeset 1349:ad0b58c983c7
lock dimension for drawing and editing shapes
author | hertzhaft |
---|---|
date | Sun, 08 Feb 2015 19:22:24 +0100 |
parents | 6dc8d7cb461d |
children | 81d5135ceafc |
files | webapp/src/main/webapp/jquery/jquery.digilib.measure.js webapp/src/main/webapp/jquery/jquery.digilib.vector.js |
diffstat | 2 files changed, 17 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery.digilib.measure.js Sun Feb 08 18:30:01 2015 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.measure.js Sun Feb 08 19:22:24 2015 +0100 @@ -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
--- a/webapp/src/main/webapp/jquery/jquery.digilib.vector.js Sun Feb 08 18:30:01 2015 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.vector.js Sun Feb 08 19:22:24 2015 +0100 @@ -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}; }