aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPushkar Joshi2012-05-29 14:24:47 -0700
committerPushkar Joshi2012-05-29 14:24:47 -0700
commite2ae637582b8e02125086201a64ee85761b01093 (patch)
tree8aa36a1ef9066a6f8136bbec2677436ee40fed64
parentc385a1d2d8154e2c5b005c0caca5a46318f6928f (diff)
downloadninja-e2ae637582b8e02125086201a64ee85761b01093.tar.gz
More consistent local and global mouse coords which solves a bug with the Pen minus subtool not removing 1 anchor paths
-rwxr-xr-xjs/components/tools-properties/pen-properties.reel/pen-properties.js1
-rwxr-xr-xjs/tools/PenTool.js38
2 files changed, 19 insertions, 20 deletions
diff --git a/js/components/tools-properties/pen-properties.reel/pen-properties.js b/js/components/tools-properties/pen-properties.reel/pen-properties.js
index aba6cb61..c37359e1 100755
--- a/js/components/tools-properties/pen-properties.reel/pen-properties.js
+++ b/js/components/tools-properties/pen-properties.reel/pen-properties.js
@@ -73,7 +73,6 @@ var PenProperties = exports.PenProperties = Montage.create(ToolProperties, {
73 handleClick: { 73 handleClick: {
74 value: function(event) { 74 value: function(event) {
75 this._selectedSubtool = event._event.target.value; 75 this._selectedSubtool = event._event.target.value;
76 console.log("handleClick changing pen tool subtool to "+this.selectedSubtool);
77 NJevent("penSubToolChange"); 76 NJevent("penSubToolChange");
78 } 77 }
79 }, 78 },
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index bbde7374..14ea3563 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -334,8 +334,20 @@ exports.PenTool = Montage.create(ShapeTool, {
334 334
335 //build the hit record for the current mouse position (on the stage or the plane of the path canvas) 335 //build the hit record for the current mouse position (on the stage or the plane of the path canvas)
336 var hitRec = this.getHitRecord(event.pageX, event.pageY, false); 336 var hitRec = this.getHitRecord(event.pageX, event.pageY, false);
337 337 var globalMousePos=null, localMousePos=null, stageWorldMousePos = null, drawingCanvas=null;
338 if (this._selectedSubpathCanvas === null){ 338 if (!this._selectedSubpathCanvas){
339 drawingCanvas = ViewUtils.getStageElement();
340 stageWorldMousePos = hitRec.calculateStageWorldPoint();
341 stageWorldMousePos[0]+= snapManager.getStageWidth()*0.5;
342 stageWorldMousePos[1]+= snapManager.getStageHeight()*0.5;
343 localMousePos = stageWorldMousePos; //since the subpath points are in stage world space, set the 'localMousePos' to be stage world as well
344 }
345 else {
346 globalMousePos = hitRec.getScreenPoint();
347 localMousePos = ViewUtils.globalToLocal(globalMousePos, this._selectedSubpathCanvas);
348 }
349
350 if (this._selectedSubpathCanvas === null && this._subtool===this.SUBTOOL_NONE){
339 //IF this is the first anchor point of the selected subpath 351 //IF this is the first anchor point of the selected subpath
340 // Store the plane mat and drag plane of this hit record (will be used for creating a canvas) 352 // Store the plane mat and drag plane of this hit record (will be used for creating a canvas)
341 // Add the mouse position (in stage world space) as an anchor point 353 // Add the mouse position (in stage world space) as an anchor point
@@ -344,12 +356,8 @@ exports.PenTool = Montage.create(ShapeTool, {
344 this._selectedSubpathPlaneMat = hitRec.getPlaneMatrix(); 356 this._selectedSubpathPlaneMat = hitRec.getPlaneMatrix();
345 } 357 }
346 358
347 //calculate the stage world position from the hit record
348 var swMousePos = hitRec.calculateStageWorldPoint();
349 swMousePos[0]+= snapManager.getStageWidth()*0.5; swMousePos[1]+= snapManager.getStageHeight()*0.5;
350
351 //check if the mouse click location is close to the existing anchor 359 //check if the mouse click location is close to the existing anchor
352 var indexAndCode = this._selectedSubpath.pickAnchor(swMousePos[0], swMousePos[1], swMousePos[2], this._PICK_POINT_RADIUS); 360 var indexAndCode = this._selectedSubpath.pickAnchor(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2], this._PICK_POINT_RADIUS);
353 if (indexAndCode[0]>=0){ 361 if (indexAndCode[0]>=0){
354 //the anchor point was hit, so we do not add another anchor 362 //the anchor point was hit, so we do not add another anchor
355 switch(indexAndCode[1]){ 363 switch(indexAndCode[1]){
@@ -371,9 +379,9 @@ exports.PenTool = Montage.create(ShapeTool, {
371 } else { 379 } else {
372 this._selectedSubpath.addAnchor(new AnchorPoint()); 380 this._selectedSubpath.addAnchor(new AnchorPoint());
373 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 381 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
374 newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]); 382 newAnchor.setPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]);
375 newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]); 383 newAnchor.setPrevPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]);
376 newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]); 384 newAnchor.setNextPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]);
377 //set the mode so that dragging will update the next and previous locations 385 //set the mode so that dragging will update the next and previous locations
378 this._editMode = this.EDIT_PREV_NEXT; 386 this._editMode = this.EDIT_PREV_NEXT;
379 } 387 }
@@ -392,10 +400,6 @@ exports.PenTool = Montage.create(ShapeTool, {
392 // Create a new subpath 400 // Create a new subpath
393 // Add the mouse position (in selected subpath's local space) as an anchor point (call global to local) 401 // Add the mouse position (in selected subpath's local space) as an anchor point (call global to local)
394 402
395 // Compute the mouse position in local (selected subpath canvas) space
396 var globalPos = hitRec.getScreenPoint();
397 var localMousePos = ViewUtils.globalToLocal(globalPos, this._selectedSubpathCanvas);
398
399 //now perform the hit testing 403 //now perform the hit testing
400 var prevSelectedAnchorIndex = this._selectedSubpath.getSelectedAnchorIndex(); 404 var prevSelectedAnchorIndex = this._selectedSubpath.getSelectedAnchorIndex();
401 var selAnchorAndParamAndCode = this._selectedSubpath.pickPath(localMousePos[0], localMousePos[1], localMousePos[2], this._PICK_POINT_RADIUS, false); 405 var selAnchorAndParamAndCode = this._selectedSubpath.pickPath(localMousePos[0], localMousePos[1], localMousePos[2], this._PICK_POINT_RADIUS, false);
@@ -776,6 +780,7 @@ exports.PenTool = Montage.create(ShapeTool, {
776 // ********************************************************************************************************** 780 // **********************************************************************************************************
777 HandleLeftButtonUp: { 781 HandleLeftButtonUp: {
778 value: function (event) { 782 value: function (event) {
783 this._isDrawing = false;
779 //do nothing in case of pen minus tool 784 //do nothing in case of pen minus tool
780 if (this._subtool===this.SUBTOOL_PENMINUS){ 785 if (this._subtool===this.SUBTOOL_PENMINUS){
781 return; 786 return;
@@ -825,7 +830,6 @@ exports.PenTool = Montage.create(ShapeTool, {
825 830
826 //always assume that we're not starting a new path anymore 831 //always assume that we're not starting a new path anymore
827 this._isNewPath = false; 832 this._isNewPath = false;
828 this._isDrawing = false;
829 this._editMode = this.EDIT_NONE; 833 this._editMode = this.EDIT_NONE;
830 834
831 //if we're not in edit_path mode and we closed the selected subpath, then we are going to start a new subpath, so we nullify the selected subpath 835 //if we're not in edit_path mode and we closed the selected subpath, then we are going to start a new subpath, so we nullify the selected subpath
@@ -1500,21 +1504,17 @@ exports.PenTool = Montage.create(ShapeTool, {
1500 switch (this.options.selectedSubtool){ 1504 switch (this.options.selectedSubtool){
1501 case "pen": 1505 case "pen":
1502 this._subtool = this.SUBTOOL_NONE; 1506 this._subtool = this.SUBTOOL_NONE;
1503 console.log("Setting pen tool subtool to NONE");
1504 break; 1507 break;
1505 1508
1506 case "penPlus": 1509 case "penPlus":
1507 console.log("Setting pen tool subtool to PLUS");
1508 this._subtool = this.SUBTOOL_PENPLUS; 1510 this._subtool = this.SUBTOOL_PENPLUS;
1509 break; 1511 break;
1510 1512
1511 case "penMinus": 1513 case "penMinus":
1512 console.log("Setting pen tool subtool to MINUS");
1513 this._subtool = this.SUBTOOL_PENMINUS; 1514 this._subtool = this.SUBTOOL_PENMINUS;
1514 break; 1515 break;
1515 1516
1516 default: 1517 default:
1517 console.log("Setting pen tool subtool to NONE");
1518 this._subtool = this.SUBTOOL_NONE; 1518 this._subtool = this.SUBTOOL_NONE;
1519 break; 1519 break;
1520 } 1520 }