aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
authorPushkar Joshi2012-04-11 12:18:03 -0700
committerPushkar Joshi2012-04-11 12:18:03 -0700
commitc786aafb077f9f510c62bc51faa7a74a23ccda1c (patch)
treefbe92c96ea08df9410502d981e5c9146769b51f7 /js/tools
parent25e406c9924438697564bc2341bd5b045a1dd85c (diff)
downloadninja-c786aafb077f9f510c62bc51faa7a74a23ccda1c.tar.gz
dragging anchor points in 3D (seems to work ok for existing paths --- the left and top change causes the rest of the points to move, which *may* be unavoidable), still has bugs with NEW points being placed at wrong position
Diffstat (limited to 'js/tools')
-rwxr-xr-xjs/tools/PenTool.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index 8065e1a6..c21c1f24 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -327,6 +327,71 @@ exports.PenTool = Montage.create(ShapeTool, {
327 //go through the drawing toolbase to get the position of the mouse 327 //go through the drawing toolbase to get the position of the mouse
328 var currMousePos = DrawingToolBase.getHitRecPos(DrawingToolBase.getUpdatedSnapPoint(point.x, point.y, false, this.mouseDownHitRec)); 328 var currMousePos = DrawingToolBase.getHitRecPos(DrawingToolBase.getUpdatedSnapPoint(point.x, point.y, false, this.mouseDownHitRec));
329 if (currMousePos && this._selectedSubpath && (this._selectedSubpath.getSelectedAnchorIndex() >= 0 && this._selectedSubpath.getSelectedAnchorIndex() < this._selectedSubpath.getNumAnchors())) { 329 if (currMousePos && this._selectedSubpath && (this._selectedSubpath.getSelectedAnchorIndex() >= 0 && this._selectedSubpath.getSelectedAnchorIndex() < this._selectedSubpath.getNumAnchors())) {
330
331 // BEGIN NEW LOCAL COORD BLOCK
332 //build the mouse position in local coordinates
333 var drawingCanvas = this._selectedSubpath.getCanvas();
334 if (!drawingCanvas){
335 drawingCanvas = ViewUtils.getStageElement();
336 }
337 var globalMousePos = this._getUnsnappedScreenPosition(event.pageX, event.pageY);
338 var localMousePos = ViewUtils.globalToLocal(globalMousePos, drawingCanvas);
339
340 //compute the translation from the selected anchor
341 var selAnchorLocalPos = this._selectedSubpath.getAnchorLocalCoord(this._selectedSubpath.getSelectedAnchorIndex());
342 var localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorLocalPos[1]);
343 var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
344
345 if (this._editMode & this.EDIT_ANCHOR) {
346 selAnchor.translateAll(localTranslation[0], localTranslation[1], localTranslation[2]);
347 }
348 else if (this._editMode & this.EDIT_PREV) {
349 localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorLocalPos[0]);
350 selAnchor.translatePrev(localTranslation[0], localTranslation[1], localTranslation[2]);
351
352 //move the next point if Alt key is down to ensure relative angle between prev and next
353 if (this._isAltDown) {
354 selAnchor.translateNextFromPrev(localTranslation[0], localTranslation[1], localTranslation[2]);
355 }
356 }
357 else if (this._editMode & this.EDIT_NEXT) {
358 localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorLocalPos[2]);
359 selAnchor.translateNext(localTranslation[0], localTranslation[1], localTranslation[2]);
360
361 //move the prev point if Alt key is down to ensure relative angle between prev and next
362 if (this._isAltDown) {
363 selAnchor.translatePrevFromNext(localTranslation[0], localTranslation[1], localTranslation[2]);
364 }
365 }
366 else if (this._editMode & this.EDIT_PREV_NEXT) {
367 localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorLocalPos[2]);
368 selAnchor.translateNext(localTranslation[0], localTranslation[1], localTranslation[2]);
369 selAnchor.setPrevFromNext();
370 }
371
372
373 //snapping...check if the new location of the anchor point is close to another anchor point
374 var selX = selAnchor.getPosX();
375 var selY = selAnchor.getPosY();
376 var selZ = selAnchor.getPosZ();
377 this._snapTargetIndex = -1;
378 var numAnchors = this._selectedSubpath.getNumAnchors();
379 for (var i = 0; i < numAnchors; i++) {
380 //check if the selected anchor is close to any other anchors
381 if (i === this._selectedSubpath.getSelectedAnchorIndex())
382 continue;
383 var currAnchor = this._selectedSubpath.getAnchor(i);
384 var distSq = currAnchor.getDistanceSq(selX, selY, selZ);
385 if (distSq < this._PICK_POINT_RADIUS * this._PICK_POINT_RADIUS) {
386 //set the snap target to the location of the first close-enough anchor
387 this._snapTargetIndex = i;
388 break;
389 }
390 }
391
392 // END NEW LOCAL COORD BLOCK
393
394 /* BEGIN OLD GLOBAL COORD COMMENT BLOCK
330 //var scoord = this._getScreenCoord(this._mouseUpHitRec); 395 //var scoord = this._getScreenCoord(this._mouseUpHitRec);
331 var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 396 var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
332 var selX = selAnchor.getPosX(); 397 var selX = selAnchor.getPosX();
@@ -362,6 +427,7 @@ exports.PenTool = Montage.create(ShapeTool, {
362 selAnchor.setPrevFromNext(); 427 selAnchor.setPrevFromNext();
363 } 428 }
364 429
430
365 //snapping...check if the new location of the anchor point is close to another anchor point 431 //snapping...check if the new location of the anchor point is close to another anchor point
366 this._snapTargetIndex = -1; 432 this._snapTargetIndex = -1;
367 var numAnchors = this._selectedSubpath.getNumAnchors(); 433 var numAnchors = this._selectedSubpath.getNumAnchors();
@@ -378,6 +444,8 @@ exports.PenTool = Montage.create(ShapeTool, {
378 } 444 }
379 } 445 }
380 446
447 END OLD GLOBAL COORD COMMENT BLOCK */
448
381 //make the subpath dirty so it will get re-drawn 449 //make the subpath dirty so it will get re-drawn
382 this._selectedSubpath.makeDirty(); 450 this._selectedSubpath.makeDirty();
383 this.DrawSubpathSVG(this._selectedSubpath); 451 this.DrawSubpathSVG(this._selectedSubpath);