diff options
author | Pushkar Joshi | 2012-05-04 16:04:04 -0700 |
---|---|---|
committer | Pushkar Joshi | 2012-05-04 16:04:04 -0700 |
commit | ba890518b5a35d5e6893f9fc72d2eee30ae07e17 (patch) | |
tree | 76ac11d2787bfb5fe6411befcbdbccc2585b5131 | |
parent | cd5d64aae3d0b0395e3163fab17e09e9eda01a85 (diff) | |
download | ninja-ba890518b5a35d5e6893f9fc72d2eee30ae07e17.tar.gz |
handle delete more correctly than before (selected subpaths are deleted)....this is buggy when the second anchor of a two-anchor subpath is deleted (since the first anchor needs to be converted back into stage world coords)
-rwxr-xr-x | js/tools/PenTool.js | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 2e2570e3..fb7f6d6d 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js | |||
@@ -1402,38 +1402,57 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
1402 | value: function(event){ | 1402 | value: function(event){ |
1403 | //clear the selected subpath...the only new additions to this function w.r.t. ToolBase | 1403 | //clear the selected subpath...the only new additions to this function w.r.t. ToolBase |
1404 | if (this._selectedSubpath){ | 1404 | if (this._selectedSubpath){ |
1405 | var removeSelectedSubpathCanvas = false; | ||
1406 | var removeSelectedSubpath = true; //this is applicable only if the subpath canvas is to be removed | ||
1405 | if (this._selectedSubpath.getSelectedAnchorIndex()>=0){ | 1407 | if (this._selectedSubpath.getSelectedAnchorIndex()>=0){ |
1406 | this._hoveredAnchorIndex=-1; | 1408 | this._hoveredAnchorIndex=-1; |
1407 | this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex()); | 1409 | this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex()); |
1408 | this._selectedSubpath.createSamples(false); | 1410 | this._selectedSubpath.createSamples(false); |
1409 | //clear the canvas | 1411 | //clear the canvas |
1410 | this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); | 1412 | this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); |
1413 | |||
1411 | this.PrepareSelectedSubpathForRendering(); | 1414 | this.PrepareSelectedSubpathForRendering(); |
1412 | this.DrawSubpathAnchors(this._selectedSubpath); | 1415 | this.DrawSubpathAnchors(this._selectedSubpath); |
1413 | this.ShowSelectedSubpath(); | 1416 | var newNumAnchors = this._selectedSubpath.getNumAnchors(); |
1417 | if (newNumAnchors>1) { | ||
1418 | this.ShowSelectedSubpath(); | ||
1419 | } else { | ||
1420 | if (newNumAnchors===0){ | ||
1421 | removeSelectedSubpath = true; | ||
1422 | } else{ | ||
1423 | removeSelectedSubpath = false; //don't remove the selected subpath if there is still one anchor | ||
1424 | } | ||
1425 | removeSelectedSubpathCanvas = true; | ||
1426 | } | ||
1427 | } else { | ||
1428 | //if no anchor was selected but the subpath was selected, we will remove the subpath | ||
1429 | removeSelectedSubpathCanvas = true; | ||
1430 | } | ||
1431 | if (removeSelectedSubpathCanvas) { | ||
1432 | if (removeSelectedSubpath){ | ||
1433 | this._selectedSubpath.clearAllAnchors(); //perhaps unnecessary | ||
1434 | this._selectedSubpath = null; | ||
1435 | if (this._entryEditMode === this.ENTRY_SELECT_PATH){ | ||
1436 | this._entryEditMode = this.ENTRY_SELECT_NONE; | ||
1437 | } | ||
1438 | } | ||
1439 | //clear the canvas | ||
1440 | this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); | ||
1441 | |||
1442 | //undo/redo...go through ElementController and NJEvent | ||
1443 | var els = []; | ||
1444 | ElementController.removeElement(this._selectedSubpathCanvas); | ||
1445 | els.push(this._selectedSubpathCanvas); | ||
1446 | NJevent( "elementsRemoved", els ); | ||
1447 | this._selectedSubpathCanvas = null; | ||
1414 | } | 1448 | } |
1415 | else { | ||
1416 | this._selectedSubpath.clearAllAnchors(); //perhaps unnecessary | ||
1417 | this._selectedSubpath = null; | ||
1418 | if (this._entryEditMode === this.ENTRY_SELECT_PATH){ | ||
1419 | this._entryEditMode = this.ENTRY_SELECT_NONE; | ||
1420 | } | ||
1421 | //clear the canvas | ||
1422 | this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); | ||
1423 | |||
1424 | //undo/redo...go through ElementController and NJEvent | ||
1425 | var els = []; | ||
1426 | ElementController.removeElement(this._selectedSubpathCanvas); | ||
1427 | els.push(this._selectedSubpathCanvas); | ||
1428 | NJevent( "elementsRemoved", els ); | ||
1429 | this._selectedSubpathCanvas = null; | ||
1430 | } | ||
1431 | } | 1449 | } |
1432 | else { | 1450 | else { |
1433 | //undo/redo...go through ElementMediator (see ElementMediator.handleDeleting() from where the much of this function is copied) | 1451 | //undo/redo...go through ElementMediator (see ElementMediator.handleDeleting() from where the much of this function is copied) |
1434 | //clear the canvas | 1452 | //clear the canvas |
1435 | this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); | 1453 | this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); |
1436 | var els = []; | 1454 | var els = []; |
1455 | var len = this.application.ninja.selectedElements.length; | ||
1437 | for(var i = 0; i<len; i++) { | 1456 | for(var i = 0; i<len; i++) { |
1438 | els.push(this.application.ninja.selectedElements[i]); | 1457 | els.push(this.application.ninja.selectedElements[i]); |
1439 | } | 1458 | } |
@@ -1442,6 +1461,8 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
1442 | } | 1461 | } |
1443 | NJevent( "elementsRemoved", els ); | 1462 | NJevent( "elementsRemoved", els ); |
1444 | 1463 | ||
1464 | console.log("handleDelete with "+len+" selected elements"); | ||
1465 | |||
1445 | //clear out the selected path if it exists | 1466 | //clear out the selected path if it exists |
1446 | if (this._selectedSubpath) { | 1467 | if (this._selectedSubpath) { |
1447 | this._selectedSubpath.clearAllAnchors(); | 1468 | this._selectedSubpath.clearAllAnchors(); |