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