aboutsummaryrefslogtreecommitdiff
path: root/js/tools/PenTool.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/PenTool.js')
-rwxr-xr-xjs/tools/PenTool.js95
1 files changed, 55 insertions, 40 deletions
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index bbde7374..1536a334 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -190,10 +190,11 @@ exports.PenTool = Montage.create(ShapeTool, {
190 if (removeSelectedSubpath){ 190 if (removeSelectedSubpath){
191 this._selectedSubpath.clearAllAnchors(); //perhaps unnecessary 191 this._selectedSubpath.clearAllAnchors(); //perhaps unnecessary
192 this._selectedSubpath = null; 192 this._selectedSubpath = null;
193 if (this._entryEditMode === this.ENTRY_SELECT_PATH){ 193 if (this._subtool === this.SUBTOOL_NONE){
194 this._entryEditMode = this.ENTRY_SELECT_NONE; 194 if (this._entryEditMode === this.ENTRY_SELECT_PATH){
195 this._entryEditMode = this.ENTRY_SELECT_NONE;
196 }
195 } 197 }
196 this._subtool = this.SUBTOOL_NONE;
197 } else { 198 } else {
198 this._selectedSubpath.setCanvas(null); 199 this._selectedSubpath.setCanvas(null);
199 } 200 }
@@ -274,7 +275,7 @@ exports.PenTool = Montage.create(ShapeTool, {
274 value: function (event) { 275 value: function (event) {
275 //ignore any right or middle clicks 276 //ignore any right or middle clicks
276 if (event.button !== 0) { 277 if (event.button !== 0) {
277 //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) 278 //todo NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2)
278 return; 279 return;
279 } 280 }
280 281
@@ -334,8 +335,20 @@ exports.PenTool = Montage.create(ShapeTool, {
334 335
335 //build the hit record for the current mouse position (on the stage or the plane of the path canvas) 336 //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); 337 var hitRec = this.getHitRecord(event.pageX, event.pageY, false);
337 338 var globalMousePos=null, localMousePos=null, stageWorldMousePos = null, drawingCanvas=null;
338 if (this._selectedSubpathCanvas === null){ 339 if (!this._selectedSubpathCanvas){
340 drawingCanvas = this.application.ninja.currentDocument.model.documentRoot;//ViewUtils.getStageElement();
341 stageWorldMousePos = hitRec.calculateStageWorldPoint();
342 stageWorldMousePos[0]+= snapManager.getStageWidth()*0.5;
343 stageWorldMousePos[1]+= snapManager.getStageHeight()*0.5;
344 localMousePos = stageWorldMousePos; //since the subpath points are in stage world space, set the 'localMousePos' to be stage world as well
345 }
346 else {
347 globalMousePos = hitRec.getScreenPoint();
348 localMousePos = ViewUtils.globalToLocal(globalMousePos, this._selectedSubpathCanvas);
349 }
350
351 if (this._selectedSubpathCanvas === null && this._subtool===this.SUBTOOL_NONE){
339 //IF this is the first anchor point of the selected subpath 352 //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) 353 // 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 354 // Add the mouse position (in stage world space) as an anchor point
@@ -344,12 +357,8 @@ exports.PenTool = Montage.create(ShapeTool, {
344 this._selectedSubpathPlaneMat = hitRec.getPlaneMatrix(); 357 this._selectedSubpathPlaneMat = hitRec.getPlaneMatrix();
345 } 358 }
346 359
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 360 //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); 361 var indexAndCode = this._selectedSubpath.pickAnchor(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2], this._PICK_POINT_RADIUS);
353 if (indexAndCode[0]>=0){ 362 if (indexAndCode[0]>=0){
354 //the anchor point was hit, so we do not add another anchor 363 //the anchor point was hit, so we do not add another anchor
355 switch(indexAndCode[1]){ 364 switch(indexAndCode[1]){
@@ -371,9 +380,9 @@ exports.PenTool = Montage.create(ShapeTool, {
371 } else { 380 } else {
372 this._selectedSubpath.addAnchor(new AnchorPoint()); 381 this._selectedSubpath.addAnchor(new AnchorPoint());
373 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 382 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
374 newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]); 383 newAnchor.setPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]);
375 newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]); 384 newAnchor.setPrevPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]);
376 newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]); 385 newAnchor.setNextPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]);
377 //set the mode so that dragging will update the next and previous locations 386 //set the mode so that dragging will update the next and previous locations
378 this._editMode = this.EDIT_PREV_NEXT; 387 this._editMode = this.EDIT_PREV_NEXT;
379 } 388 }
@@ -392,10 +401,6 @@ exports.PenTool = Montage.create(ShapeTool, {
392 // Create a new subpath 401 // Create a new subpath
393 // Add the mouse position (in selected subpath's local space) as an anchor point (call global to local) 402 // Add the mouse position (in selected subpath's local space) as an anchor point (call global to local)
394 403
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 404 //now perform the hit testing
400 var prevSelectedAnchorIndex = this._selectedSubpath.getSelectedAnchorIndex(); 405 var prevSelectedAnchorIndex = this._selectedSubpath.getSelectedAnchorIndex();
401 var selAnchorAndParamAndCode = this._selectedSubpath.pickPath(localMousePos[0], localMousePos[1], localMousePos[2], this._PICK_POINT_RADIUS, false); 406 var selAnchorAndParamAndCode = this._selectedSubpath.pickPath(localMousePos[0], localMousePos[1], localMousePos[2], this._PICK_POINT_RADIUS, false);
@@ -413,6 +418,10 @@ exports.PenTool = Montage.create(ShapeTool, {
413 this._removeSelectedAnchorPoint(); 418 this._removeSelectedAnchorPoint();
414 return; 419 return;
415 } 420 }
421 if (this._subtool === this.SUBTOOL_PENPLUS){
422 //nothing to do for the pen plus subtool
423 return;
424 }
416 //if we're in ENTRY_SELECT_PATH mode AND we have not yet clicked on the endpoint AND if we have now clicked on the endpoint 425 //if we're in ENTRY_SELECT_PATH mode AND we have not yet clicked on the endpoint AND if we have now clicked on the endpoint
417 if (this._entryEditMode === this.ENTRY_SELECT_PATH && this._isPickedEndPointInSelectPathMode === false){ 426 if (this._entryEditMode === this.ENTRY_SELECT_PATH && this._isPickedEndPointInSelectPathMode === false){
418 var selAnchorIndex = this._selectedSubpath.getSelectedAnchorIndex(); 427 var selAnchorIndex = this._selectedSubpath.getSelectedAnchorIndex();
@@ -444,22 +453,24 @@ exports.PenTool = Montage.create(ShapeTool, {
444 } 453 }
445 454
446 //if we hit the prev handle 455 //if we hit the prev handle
447 else if (whichPoint & this._selectedSubpath.SEL_PREV){ 456 else if (whichPoint & this._selectedSubpath.SEL_PREV && this._subtool===this.SUBTOOL_NONE){
448 this._editMode = this.EDIT_PREV; 457 this._editMode = this.EDIT_PREV;
449 } 458 }
450 459
451 //if we hit the next handle 460 //if we hit the next handle
452 else if (whichPoint & this._selectedSubpath.SEL_NEXT){ 461 else if (whichPoint & this._selectedSubpath.SEL_NEXT && this._subtool===this.SUBTOOL_NONE){
453 this._editMode = this.EDIT_NEXT; 462 this._editMode = this.EDIT_NEXT;
454 } 463 }
455 464
456 //if no anchor or handles 465 //if no anchor or handles
457 else if (whichPoint & this._selectedSubpath.SEL_PATH) { 466 else if (whichPoint & this._selectedSubpath.SEL_PATH) {
458 //the click point is close enough to insert point in bezier segment after selected anchor at selParam 467 //the click point is close enough to insert point in bezier segment after selected anchor at selParam
459 if (selParam > 0 && selParam < 1) { 468 if ((selParam > 0 && selParam < 1) && this._subtool!==this.SUBTOOL_PENMINUS) {
460 this._selectedSubpath.insertAnchorAtParameter(this._selectedSubpath.getSelectedAnchorIndex(), selParam); 469 this._selectedSubpath.insertAnchorAtParameter(this._selectedSubpath.getSelectedAnchorIndex(), selParam);
461 //set the mode so that dragging will update anchor point positions 470 //set the mode so that dragging will update anchor point positions
462 //this._editMode = this.EDIT_ANCHOR; 471 //this._editMode = this.EDIT_ANCHOR;
472 } else {
473 this._selectedSubpath.deselectAnchorPoint(); //set that no anchor is selected since the path was not hit anywhere useful
463 } 474 }
464 } 475 }
465 476
@@ -469,7 +480,10 @@ exports.PenTool = Montage.create(ShapeTool, {
469 else { 480 else {
470 //add an anchor point to end of the open selected subpath (in local space), and make it the selected anchor point 481 //add an anchor point to end of the open selected subpath (in local space), and make it the selected anchor point
471 // ONLY if we were not in SELECT_PATH entry mode or we are in SELECT_PATH entry mode and we have picked one of the endpoints 482 // ONLY if we were not in SELECT_PATH entry mode or we are in SELECT_PATH entry mode and we have picked one of the endpoints
472 if (this._entryEditMode !== this.ENTRY_SELECT_PATH || (this._entryEditMode === this.ENTRY_SELECT_PATH && this._isPickedEndPointInSelectPathMode)) { 483 if (this._subtool===this.SUBTOOL_NONE &&
484 (this._entryEditMode !== this.ENTRY_SELECT_PATH ||
485 (this._entryEditMode === this.ENTRY_SELECT_PATH && this._isPickedEndPointInSelectPathMode))
486 ) {
473 if (!this._selectedSubpath.getIsClosed()) { //todo this test is probably unnecessary, but doing it to be safe 487 if (!this._selectedSubpath.getIsClosed()) { //todo this test is probably unnecessary, but doing it to be safe
474 this._selectedSubpath.addAnchor(new AnchorPoint()); 488 this._selectedSubpath.addAnchor(new AnchorPoint());
475 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 489 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
@@ -509,16 +523,21 @@ exports.PenTool = Montage.create(ShapeTool, {
509 } 523 }
510 524
511 //set the cursor to be the default cursor (depending on whether the selected subpath has any points yet) 525 //set the cursor to be the default cursor (depending on whether the selected subpath has any points yet)
512 if (this._selectedSubpath && this._selectedSubpath.getNumAnchors()>0){ 526 if (this._subtool===this.SUBTOOL_NONE){
513 this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; 527 if (this._selectedSubpath && this._selectedSubpath.getNumAnchors()>0){
514 "url('images/cursors/penCursors/Pen_.png') 5 1, default"; 528 this.application.ninja.stage.drawingCanvas.style.cursor = //"auto";
515 } 529 "url('images/cursors/penCursors/Pen_.png') 5 1, default";
516 else { 530 }
531 else {
532 this.application.ninja.stage.drawingCanvas.style.cursor = //"auto";
533 "url('images/cursors/penCursors/Pen_newPath.png') 5 1, default";
534 }
535 } else {
536 //use the standard pen cursor for Pen Plus and Pen Minus
517 this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; 537 this.application.ninja.stage.drawingCanvas.style.cursor = //"auto";
518 "url('images/cursors/penCursors/Pen_newPath.png') 5 1, default"; 538 "url('images/cursors/penCursors/Pen_.png') 5 1, default";
519 } 539 }
520 540
521
522 if (!this._selectedSubpath ){ 541 if (!this._selectedSubpath ){
523 return; //nothing to do in case no subpath is selected 542 return; //nothing to do in case no subpath is selected
524 } 543 }
@@ -531,7 +550,7 @@ exports.PenTool = Montage.create(ShapeTool, {
531 var globalMousePos=null, localMousePos=null, stageWorldMousePos = null; 550 var globalMousePos=null, localMousePos=null, stageWorldMousePos = null;
532 var drawingCanvas = this._selectedSubpath.getCanvas(); 551 var drawingCanvas = this._selectedSubpath.getCanvas();
533 if (!drawingCanvas){ 552 if (!drawingCanvas){
534 drawingCanvas = ViewUtils.getStageElement(); 553 drawingCanvas = this.application.ninja.currentDocument.model.documentRoot; //ViewUtils.getStageElement();
535 stageWorldMousePos = hitRec.calculateStageWorldPoint(); 554 stageWorldMousePos = hitRec.calculateStageWorldPoint();
536 stageWorldMousePos[0]+= snapManager.getStageWidth()*0.5; 555 stageWorldMousePos[0]+= snapManager.getStageWidth()*0.5;
537 stageWorldMousePos[1]+= snapManager.getStageHeight()*0.5; 556 stageWorldMousePos[1]+= snapManager.getStageHeight()*0.5;
@@ -558,8 +577,8 @@ exports.PenTool = Montage.create(ShapeTool, {
558 localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorPos[0]); 577 localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorPos[0]);
559 selAnchor.translatePrev(localTranslation[0], localTranslation[1], localTranslation[2]); 578 selAnchor.translatePrev(localTranslation[0], localTranslation[1], localTranslation[2]);
560 if (!this._isAltDown){ 579 if (!this._isAltDown){
561 //selAnchor.translateNextFromPrev(localTranslation[0], localTranslation[1], localTranslation[2]); 580 selAnchor.translateNextFromPrev(localTranslation[0], localTranslation[1], localTranslation[2]);
562 selAnchor.setNextFromPrev(); 581 //selAnchor.setNextFromPrev();
563 } 582 }
564 } 583 }
565 else if (this._editMode & this.EDIT_