aboutsummaryrefslogtreecommitdiff
path: root/js/tools/PenTool.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/PenTool.js')
-rwxr-xr-xjs/tools/PenTool.js49
1 files changed, 32 insertions, 17 deletions
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index e296d0e5..33ca5c71 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -288,16 +288,35 @@ exports.PenTool = Montage.create(ShapeTool, {
288 288
289 //assume we are not starting a new path as we will set this to true if we create a new Subpath() 289 //assume we are not starting a new path as we will set this to true if we create a new Subpath()
290 this._isNewPath = false; 290 this._isNewPath = false;
291
292 //if we had closed the selected subpath previously, or if we have not yet started anything, create a subpath
293 if (this._entryEditMode !== this.ENTRY_SELECT_PATH && this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._makeMultipleSubpaths) {
294 this._selectedSubpath = null;
295 }
296 291
297 if (this._subtool !== this.SUBTOOL_NONE && this._selectedSubpath===null) { 292 if (this._subtool !== this.SUBTOOL_NONE && this._selectedSubpath===null) {
298 //do nothing because the pen plus and pen minus subtools need a selected subpath 293 //do nothing because the pen plus and pen minus subtools need a selected subpath
299 return; 294 return;
300 } 295 }
296
297 //build the hit record for the current mouse position (on the stage or the plane of the path canvas)
298 var hitRec = this.getHitRecord(event.pageX, event.pageY, false);
299 var globalMousePos=null, localMousePos=null, stageWorldMousePos = null, drawingCanvas=null;
300 if (this._selectedSubpathCanvas){
301 globalMousePos = hitRec.getScreenPoint();
302 localMousePos = ViewUtils.globalToLocal(globalMousePos, this._selectedSubpathCanvas);
303 }
304
305 //if we have a selected subpath and canvas, check if the current click location hits the path
306 // todo optimize this...currently pickPath is called twice (see later in this function)
307 var hitPath = false;
308 if (this._selectedSubpath && this._selectedSubpathCanvas ) {
309 var tempSelAnchorAndParamAndCode = this._selectedSubpath.pickPath(localMousePos[0], localMousePos[1], localMousePos[2], this._PICK_POINT_RADIUS, true);
310 if (tempSelAnchorAndParamAndCode[2] !== this._selectedSubpath.SEL_NONE){ // ******* if we hit the path anywhere *********
311 hitPath = true;
312 }
313 }
314
315 //if we had closed the selected subpath previously, or if we have not yet started anything, create a subpath
316 if (this._entryEditMode !== this.ENTRY_SELECT_PATH && this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._makeMultipleSubpaths && !hitPath) {
317 this._selectedSubpath = null;
318 }
319
301 if (this._selectedSubpath === null) { 320 if (this._selectedSubpath === null) {
302 this._selectedSubpath = new SubPath(); 321 this._selectedSubpath = new SubPath();
303 this._selectedSubpathCanvas = null; 322 this._selectedSubpathCanvas = null;
@@ -335,9 +354,7 @@ exports.PenTool = Montage.create(ShapeTool, {
335 this._selectedSubpath.setFillColor(colorArray); 354 this._selectedSubpath.setFillColor(colorArray);
336 } //if the selectedSubpath was null and needed to be constructed 355 } //if the selectedSubpath was null and needed to be constructed
337 356
338 //build the hit record for the current mouse position (on the stage or the plane of the path canvas) 357 //build the current mouse position in stage world space in case we don't already have a canvas
339 var hitRec = this.getHitRecord(event.pageX, event.pageY, false);
340 var globalMousePos=null, localMousePos=null, stageWorldMousePos = null, drawingCanvas=null;
341 if (!this._selectedSubpathCanvas){ 358 if (!this._selectedSubpathCanvas){
342 drawingCanvas = this.application.ninja.currentDocument.model.documentRoot;//ViewUtils.getStageElement(); 359 drawingCanvas = this.application.ninja.currentDocument.model.documentRoot;//ViewUtils.getStageElement();
343 stageWorldMousePos = hitRec.calculateStageWorldPoint(); 360 stageWorldMousePos = hitRec.calculateStageWorldPoint();
@@ -345,10 +362,7 @@ exports.PenTool = Montage.create(ShapeTool, {
345 stageWorldMousePos[1]+= snapManager.getStageHeight()*0.5; 362 stageWorldMousePos[1]+= snapManager.getStageHeight()*0.5;
346 localMousePos = stageWorldMousePos; //since the subpath points are in stage world space, set the 'localMousePos' to be stage world as well 363 localMousePos = stageWorldMousePos; //since the subpath points are in stage world space, set the 'localMousePos' to be stage world as well
347 } 364 }
348 else { 365
349 globalMousePos = hitRec.getScreenPoint();
350 localMousePos = ViewUtils.globalToLocal(globalMousePos, this._selectedSubpathCanvas);
351 }
352 366
353 if (this._selectedSubpathCanvas === null && this._subtool===this.SUBTOOL_NONE){ 367 if (this._selectedSubpathCanvas === null && this._subtool===this.SUBTOOL_NONE){
354 //IF this is the first anchor point of the selected subpath 368 //IF this is the first anchor point of the selected subpath
@@ -358,7 +372,6 @@ exports.PenTool = Montage.create(ShapeTool, {
358 if (this._selectedSubpath.getNumAnchors()===0) { 372 if (this._selectedSubpath.getNumAnchors()===0) {
359 this._selectedSubpathPlaneMat = hitRec.getPlaneMatrix(); 373 this._selectedSubpathPlaneMat = hitRec.getPlaneMatrix();
360 } 374 }
361
362 //check if the mouse click location is close to the existing anchor 375 //check if the mouse click location is close to the existing anchor
363 var indexAndCode = this._selectedSubpath.pickAnchor(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2], this._PICK_POINT_RADIUS); 376 var indexAndCode = this._selectedSubpath.pickAnchor(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2], this._PICK_POINT_RADIUS);
364 if (indexAndCode[0]>=0){ 377 if (indexAndCode[0]>=0){
@@ -526,7 +539,9 @@ exports.PenTool = Montage.create(ShapeTool, {
526 539
527 //set the cursor to be the default cursor (depending on whether the selected subpath has any points yet) 540 //set the cursor to be the default cursor (depending on whether the selected subpath has any points yet)
528 if (this._subtool===this.SUBTOOL_NONE){ 541 if (this._subtool===this.SUBTOOL_NONE){
529 if (this._selectedSubpath && this._selectedSubpath.getNumAnchors()>0){ 542 if ((this._selectedSubpath && this._selectedSubpath.getNumAnchors()>0 && !this._selectedSubpath.getIsClosed())
543 ||
544 this._entryEditMode === this.ENTRY_SELECT_PATH){
530 this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; 545 this.application.ninja.stage.drawingCanvas.style.cursor = //"auto";
531 "url('images/cursors/penCursors/Pen_.png') 5 1, default"; 546 "url('images/cursors/penCursors/Pen_.png') 5 1, default";
532 } 547 }
@@ -853,9 +868,9 @@ exports.PenTool = Montage.create(ShapeTool, {
853 this._editMode = this.EDIT_NONE; 868 this._editMode = this.EDIT_NONE;
854 869
855 //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 870 //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
856 if (this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._entryEditMode !== this.ENTRY_SELECT_PATH){ 871 //if (this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._entryEditMode !== this.ENTRY_SELECT_PATH){
857 this._selectedSubpath = null; 872 // this._selectedSubpath = null;
858 } 873 //}
859 874
860 if (this._selectedSubpath){ 875 if (this._selectedSubpath){
861 this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas 876 this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas