Commit b5f7e682 authored by hertzhaft's avatar hertzhaft

place handles along with shapes

parent 58171744
......@@ -1191,10 +1191,11 @@
var p = props.screenpos;
var g = shape.geometry;
var vtx = props.vtx;
if (vtx > 1 || p.length > 2) {
if (p.length > 2) {
var pt = (vtx > 1) ? p[vtx] : p[2];
var d = p[0].delta(p[1]).toArray();
var line1 = geom.line(p[0], d);
var line2 = geom.line(p[2], d); // parallel (same slope)
var line2 = geom.line(pt, d); // parallel (same slope)
var orth = line1.orthogonal();
p[3] = orth.intersection(line2);
p[2] = p[3].copy().add(d);
......
......@@ -575,18 +575,28 @@
*/
var getVertexDragHandler = function (data, shape, vtx, onComplete) {
var $document = $(document);
var imgRect = data.imgRect;
var $shape = shape.$elem;
var $handle = (shape.$vertexElems != null) ? shape.$vertexElems[vtx] : null;
var shapeType = shape.geometry.type;
var imgRect = data.imgRect;
var props = shape.properties;
var pos = props.screenpos;
var pStart; // save startpoint
var placeHandle = function (i, $handle) {
$handle.moveTo(pos[i]);
};
var placeHandles = function () {
$.each(shape.$vertexElems, placeHandle);
};
var dragStart = function (evt) { // start dragging
// cancel if not left-click
if (evt.which != 1) return;
pStart = geom.position(evt);
shape.properties.startpos = pStart;
shape.properties.vtx = vtx;
props.startpos = pStart;
props.vtx = vtx;
$(data).trigger('positionShape', shape);
$document.on("mousemove.dlVertexDrag", dragMove);
$document.on("mouseup.dlVertexDrag", dragEnd);
......@@ -597,18 +607,17 @@
var dragMove = function (evt) { // dragging
var pt = geom.position(evt);
pt.clipTo(imgRect);
shape.properties.screenpos[vtx] = pt;
pos[vtx] = pt;
$(data).trigger('positionShape', shape);
if (isSupported(data, shapeType)) {
// update shape object and trigger drag event
shape.geometry.coordinates[vtx] = data.imgTrafo.invtransform(pt).toArray();
// update shape SVG element
$shape.place();
// move handles accordingly
placeHandles();
$(data).trigger('dragShape', shape);
}
if ($handle != null) {
$handle.moveTo(pt);
}
return 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