diff options
Diffstat (limited to 'js/tools/PenTool.js')
-rwxr-xr-x | js/tools/PenTool.js | 95 |
1 files changed, 83 insertions, 12 deletions
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 10eb03c9..4d439dd3 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js | |||
@@ -273,14 +273,36 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
273 | var swMousePos = hitRec.calculateStageWorldPoint(); | 273 | var swMousePos = hitRec.calculateStageWorldPoint(); |
274 | swMousePos[0]+= snapManager.getStageWidth()*0.5; swMousePos[1]+= snapManager.getStageHeight()*0.5; | 274 | swMousePos[0]+= snapManager.getStageWidth()*0.5; swMousePos[1]+= snapManager.getStageHeight()*0.5; |
275 | 275 | ||
276 | this._selectedSubpath.addAnchor(new AnchorPoint()); | 276 | //check if the mouse click location is close to the existing anchor |
277 | var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); | 277 | var indexAndCode = this._selectedSubpath.pickAnchor(swMousePos[0], swMousePos[1], swMousePos[2], this._PICK_POINT_RADIUS); |
278 | newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]); | 278 | if (indexAndCode[0]>=0){ |
279 | newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]); | 279 | //the anchor point was hit, so we do not add another anchor |
280 | newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]); | 280 | switch(indexAndCode[1]){ |
281 | //set the mode so that dragging will update the next and previous locations | 281 | case this._selectedSubpath.SEL_ANCHOR: |
282 | this._editMode = this.EDIT_PREV_NEXT; | 282 | this._editMode = this.EDIT_ANCHOR; |
283 | } | 283 | break; |
284 | case this._selectedSubpath.SEL_PREV: | ||
285 | this._editMode = this.EDIT_PREV; | ||
286 | break; | ||
287 | case this._selectedSubpath.SEL_NEXT: | ||
288 | this._editMode = this.EDIT_NEXT; | ||
289 | break; | ||
290 | default: | ||
291 | this._editMode = this.EDIT_ANCHOR; | ||
292 | console.log("WARNING picked anchor point with incorrect mode"); | ||
293 | break; | ||
294 | } | ||
295 | |||
296 | } else { | ||
297 | this._selectedSubpath.addAnchor(new AnchorPoint()); | ||
298 | var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); | ||
299 | newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]); | ||
300 | newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]); | ||
301 | newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]); | ||
302 | //set the mode so that dragging will update the next and previous locations | ||
303 | this._editMode = this.EDIT_PREV_NEXT; | ||
304 | } | ||
305 | } //if we have not yet created a canvas for this path | ||
284 | 306 | ||
285 | //the selected subpath has a canvas, so test within that canvas' space | 307 | //the selected subpath has a canvas, so test within that canvas' space |
286 | else | 308 | else |
@@ -714,14 +736,24 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
714 | this._isDrawing = false; | 736 | this._isDrawing = false; |
715 | this._editMode = this.EDIT_NONE; | 737 | this._editMode = this.EDIT_NONE; |
716 | 738 | ||
739 | //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 | ||
740 | if (this._selectedSubpath.getIsClosed() && this._entryEditMode !== this.ENTRY_SELECT_PATH){ | ||
741 | this._selectedSubpath = null; | ||
742 | } | ||
743 | |||
717 | if (this._selectedSubpath){ | 744 | if (this._selectedSubpath){ |
718 | this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas | 745 | this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas |
746 | }else{ | ||
747 | //clear the canvas | ||
748 | this.application.ninja.stage.clearDrawingCanvas(); | ||
719 | } | 749 | } |
720 | 750 | ||
721 | if (!this._trackMouseMoveWhenUp){ | 751 | if (!this._trackMouseMoveWhenUp){ |
722 | NJevent("disableStageMove"); | 752 | NJevent("disableStageMove"); |
723 | } | 753 | } |
724 | this._hoveredAnchorIndex = -1; | 754 | this._hoveredAnchorIndex = -1; |
755 | |||
756 | |||
725 | } | 757 | } |
726 | }, | 758 | }, |
727 | 759 | ||
@@ -1255,10 +1287,45 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
1255 | } //value: function() { | 1287 | } //value: function() { |
1256 | }, //DrawSubpathAnchors { | 1288 | }, //DrawSubpathAnchors { |
1257 | 1289 | ||
1290 | deselectPenTool:{ | ||
1291 | value: function() { | ||
1292 | this._selectedSubpath = null; | ||
1293 | this._selectedSubpathCanvas = null; | ||
1294 | this._selectedSubpathPlaneMat = null; | ||
1295 | this._snapTargetIndex = -1; | ||
1296 | } | ||
1297 | }, | ||
1298 | //if the document is opened with the pen tool being active, we do the same thing as when configure(false) is called | ||
1299 | handleOpenDocument: { | ||
1300 | value: function() { | ||
1301 | this.deselectPenTool(); | ||
1302 | //clear the canvas | ||
1303 | this.application.ninja.stage.clearDrawingCanvas(); | ||
1304 | } | ||
1305 | }, | ||
1306 | //if the document is switched with the pen tool being active, we do the same thing as when configure(false) is called | ||
1307 | handleSwitchDocument: { | ||
1308 | value: function() { | ||
1309 | this.deselectPenTool(); | ||
1310 | //clear the canvas | ||
1311 | this.application.ninja.stage.clearDrawingCanvas(); | ||
1312 | } | ||
1313 | }, | ||
1314 | //if the document is closed with the pen tool being active, we do the same thing as when configure(false) is called | ||
1315 | handleCloseDocument: { | ||
1316 | value: function() { | ||
1317 | this.deselectPenTool(); | ||
1318 | //clear the canvas | ||
1319 | this.application.ninja.stage.clearDrawingCanvas(); | ||
1320 | } | ||
1321 | }, | ||
1258 | 1322 | ||
1259 | Configure: { | 1323 | Configure: { |
1260 | value: function (wasSelected) { | 1324 | value: function (wasSelected) { |
1261 | if (wasSelected) { | 1325 | if (wasSelected) { |
1326 | //first nullify any set values | ||
1327 | this.deselectPenTool(); | ||
1328 | |||
1262 | defaultEventManager.addEventListener("resetPenTool", this, false); | 1329 | defaultEventManager.addEventListener("resetPenTool", this, false); |
1263 | this.application.ninja.elementMediator.deleteDelegate = this; | 1330 | this.application.ninja.elementMediator.deleteDelegate = this; |
1264 | this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; | 1331 | this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; |
@@ -1312,17 +1379,21 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
1312 | if (this._trackMouseMoveWhenUp){ | 1379 | if (this._trackMouseMoveWhenUp){ |
1313 | NJevent("enableStageMove"); | 1380 | NJevent("enableStageMove"); |
1314 | } | 1381 | } |
1382 | this.eventManager.addEventListener("openDocument", this, false); | ||
1383 | this.eventManager.addEventListener("switchDocument", this, false); | ||
1384 | this.eventManager.addEventListener("closeDocument", this, false); | ||
1315 | } //if the pen tool was selected | 1385 | } //if the pen tool was selected |
1316 | else { | 1386 | else { |
1317 | if (this._trackMouseMoveWhenUp){ | 1387 | if (this._trackMouseMoveWhenUp){ |
1318 | NJevent("disableStageMove"); | 1388 | NJevent("disableStageMove"); |
1319 | } | 1389 | } |
1320 | this._selectedSubpath = null; | 1390 | this.deselectPenTool(); |
1321 | this._selectedSubpathCanvas = null; | ||
1322 | this._selectedSubpathPlaneMat = null; | ||
1323 | this._snapTargetIndex = -1; | ||
1324 | defaultEventManager.removeEventListener("resetPenTool", this, false); | 1391 | defaultEventManager.removeEventListener("resetPenTool", this, false); |
1325 | this.application.ninja.elementMediator.deleteDelegate = null; | 1392 | this.application.ninja.elementMediator.deleteDelegate = null; |
1393 | |||
1394 | this.eventManager.removeEventListener("openDocument", this, false); | ||
1395 | this.eventManager.removeEventListener("switchDocument", this, false); | ||
1396 | this.eventManager.removeEventListener("closeDocument", this, false); | ||
1326 | } //if the pen tool was de-selected | 1397 | } //if the pen tool was de-selected |
1327 | } | 1398 | } |
1328 | }, | 1399 | }, |