aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
authorPushkar Joshi2012-06-06 07:54:11 -0700
committerPushkar Joshi2012-06-06 07:54:11 -0700
commitcfa1402ac2ce831a83a9d4263d06c452c157a414 (patch)
treeadb8f1f1ad1c4dd1e7e9eee1bd206f1ec338d20c /js/tools
parent8606ee7ec851cb0a971e7556eba5d9386f1b3639 (diff)
parent5ba54dc275b07e7b2d0ed14751761d1e663d3d14 (diff)
downloadninja-cfa1402ac2ce831a83a9d4263d06c452c157a414.tar.gz
Merge branch 'pentool' into brushtool
Diffstat (limited to 'js/tools')
-rwxr-xr-xjs/tools/PanTool.js1
-rwxr-xr-xjs/tools/PenTool.js91
-rwxr-xr-xjs/tools/RotateStage3DTool.js11
-rwxr-xr-xjs/tools/drawing-tool-base.js2
4 files changed, 95 insertions, 10 deletions
diff --git a/js/tools/PanTool.js b/js/tools/PanTool.js
index 39f89d17..a8911c0c 100755
--- a/js/tools/PanTool.js
+++ b/js/tools/PanTool.js
@@ -122,7 +122,6 @@ exports.PanTool = Montage.create(toolBase,
122 value: function () 122 value: function ()
123 { 123 {
124 var uc = this.application.ninja.currentDocument.model.documentRoot; 124 var uc = this.application.ninja.currentDocument.model.documentRoot;
125 //var uc = documentManagerModule.DocumentManager.activeDocument
126 var ucMat = viewUtils.getMatrixFromElement(uc); 125 var ucMat = viewUtils.getMatrixFromElement(uc);
127 126
128 var noTrans = ucMat.slice(); 127 var noTrans = ucMat.slice();
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index 1536a334..4daae420 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -46,7 +46,6 @@ exports.PenTool = Montage.create(ShapeTool, {
46 _isEscapeDown: {value: false, writable: true }, 46 _isEscapeDown: {value: false, writable: true },
47 47
48 //whether we have just started a new path (may set true in mousedown, and always set false in mouse up 48 //whether we have just started a new path (may set true in mousedown, and always set false in mouse up
49 //todo this seems to be unnecessary
50 _isNewPath: {value: false, writable: true}, 49 _isNewPath: {value: false, writable: true},
51 50
52 //whether we have clicked one of the endpoints after entering the pen tool in ENTRY_SELECT_PATH edit mode 51 //whether we have clicked one of the endpoints after entering the pen tool in ENTRY_SELECT_PATH edit mode
@@ -73,7 +72,10 @@ exports.PenTool = Montage.create(ShapeTool, {
73 72
74 //the center of the subpath center in stageworld space 73 //the center of the subpath center in stageworld space
75 _selectedSubpathCanvasCenter: {value: null, writable: true}, 74 _selectedSubpathCanvasCenter: {value: null, writable: true},
76 75
76 //this flag is set true by the Configure(true) and set false by Configure(false) or handleSelectionChange
77 _doesSelectionChangeNeedHandling: {value: false, writable: true},
78
77 //constants used for picking points --- todo: these should be user-settable parameters 79 //constants used for picking points --- todo: these should be user-settable parameters
78 _PICK_POINT_RADIUS: { value: 4, writable: false }, 80 _PICK_POINT_RADIUS: { value: 4, writable: false },
79 _DISPLAY_ANCHOR_RADIUS: { value: 5, writable: false }, 81 _DISPLAY_ANCHOR_RADIUS: { value: 5, writable: false },
@@ -286,7 +288,7 @@ exports.PenTool = Montage.create(ShapeTool, {
286 288
287 //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()
288 this._isNewPath = false; 290 this._isNewPath = false;
289 291
290 //if we had closed the selected subpath previously, or if we have not yet started anything, create a subpath 292 //if we had closed the selected subpath previously, or if we have not yet started anything, create a subpath
291 if (this._entryEditMode !== this.ENTRY_SELECT_PATH && this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._makeMultipleSubpaths) { 293 if (this._entryEditMode !== this.ENTRY_SELECT_PATH && this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._makeMultipleSubpaths) {
292 this._selectedSubpath = null; 294 this._selectedSubpath = null;
@@ -691,6 +693,7 @@ exports.PenTool = Montage.create(ShapeTool, {
691 var top = Math.round(midPt[1] - 0.5 * h); 693 var top = Math.round(midPt[1] - 0.5 * h);
692 694
693 if (!canvas) { 695 if (!canvas) {
696 this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the new canvas
694 var newCanvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument); 697 var newCanvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument);
695 document.application.njUtils.createModelWithShape(newCanvas, "Subpath"); 698 document.application.njUtils.createModelWithShape(newCanvas, "Subpath");
696 var styles = document.application.njUtils.stylesFromDraw(newCanvas, parseInt(w), parseInt(h), {midPt: midPt, planeMat: planeMat}); 699 var styles = document.application.njUtils.stylesFromDraw(newCanvas, parseInt(w), parseInt(h), {midPt: midPt, planeMat: planeMat});
@@ -733,8 +736,9 @@ exports.PenTool = Montage.create(ShapeTool, {
733 //now send the event that will add this canvas to the timeline 736 //now send the event that will add this canvas to the timeline
734 NJevent("elementAdded", newCanvas); 737 NJevent("elementAdded", newCanvas);
735 738
736 if(newCanvas.elementModel.isShape) //todo why is this not true for the path canvas? 739 if(newCanvas.elementModel.isShape)
737 { 740 {
741 this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the new canvas
738 this.application.ninja.selectionController.selectElement(newCanvas); 742 this.application.ninja.selectionController.selectElement(newCanvas);
739 } 743 }
740 } //if (!canvas) { 744 } //if (!canvas) {
@@ -775,8 +779,9 @@ exports.PenTool = Montage.create(ShapeTool, {
775 //TODO this will not work if there are multiple shapes in the same canvas 779 //TODO this will not work if there are multiple shapes in the same canvas
776 canvas.elementModel.shapeModel.GLGeomObj = subpath; 780 canvas.elementModel.shapeModel.GLGeomObj = subpath;
777 781
778 if(canvas.elementModel.isShape) //todo why is this not true for the path canvas? 782 if(canvas.elementModel.isShape)
779 { 783 {
784 this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the canvas
780 this.application.ninja.selectionController.selectElement(canvas); 785 this.application.ninja.selectionController.selectElement(canvas);
781 } 786 }
782 } //else of if (!canvas) { 787 } //else of if (!canvas) {
@@ -843,6 +848,7 @@ exports.PenTool = Montage.create(ShapeTool, {
843 this.ShowSelectedSubpath(); 848 this.ShowSelectedSubpath();
844 } //if (this._selectedSubpath.getNumPoints() > 0) { 849 } //if (this._selectedSubpath.getNumPoints() > 0) {
845 850
851
846 //always assume that we're not starting a new path anymore 852 //always assume that we're not starting a new path anymore
847 this._isNewPath = false; 853 this._isNewPath = false;
848 this._editMode = this.EDIT_NONE; 854 this._editMode = this.EDIT_NONE;
@@ -1404,6 +1410,8 @@ exports.PenTool = Montage.create(ShapeTool, {
1404 this._selectedSubpathCanvas = null; 1410 this._selectedSubpathCanvas = null;
1405 this._selectedSubpathPlaneMat = null; 1411 this._selectedSubpathPlaneMat = null;
1406 this._snapTargetIndex = -1; 1412 this._snapTargetIndex = -1;
1413 //clear the canvas
1414 this.application.ninja.stage.clearDrawingCanvas();
1407 } 1415 }
1408 }, 1416 },
1409 //if the document is opened with the pen tool being active, we do the same thing as when configure(false) is called 1417 //if the document is opened with the pen tool being active, we do the same thing as when configure(false) is called
@@ -1442,9 +1450,14 @@ exports.PenTool = Montage.create(ShapeTool, {
1442 this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; 1450 this.application.ninja.stage.drawingCanvas.style.cursor = //"auto";
1443 "url('images/cursors/penCursors/Pen_newPath.png') 5 1, default"; 1451 "url('images/cursors/penCursors/Pen_newPath.png') 5 1, default";
1444 1452
1445 if (this.application.ninja.selectedElements.length === 0){ 1453 //TODO in case of switching between docs, this call to setEntryMode may refer to the old document,
1454 // which is why we set the _doesSelectionChangeNeedHandling flag next
1455 this.setEntryMode();
1456 this._doesSelectionChangeNeedHandling = true; //this will make sure that the setEntry mode gets called by the selectionChange handler
1457 /*if (this.application.ninja.selectedElements.length === 0){
1446 this._entryEditMode = this.ENTRY_SELECT_NONE; 1458 this._entryEditMode = this.ENTRY_SELECT_NONE;
1447 } 1459 }
1460
1448 else{ 1461 else{
1449 for (var i=0;i<this.application.ninja.selectedElements.length;i++){ 1462 for (var i=0;i<this.application.ninja.selectedElements.length;i++){
1450 var element = this.application.ninja.selectedElements[i]; 1463 var element = this.application.ninja.selectedElements[i];
@@ -1486,6 +1499,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1486 } 1499 }
1487 } 1500 }
1488 this._isPickedEndPointInSelectPathMode = false; //only applies to the ENTRY_SELECT_PATH mode 1501 this._isPickedEndPointInSelectPathMode = false; //only applies to the ENTRY_SELECT_PATH mode
1502 */
1489 1503
1490 this.handlePenSubToolChange(); 1504 this.handlePenSubToolChange();
1491 //this._subtool = this.SUBTOOL_NONE; //this.SUBTOOL_PENMINUS; 1505 //this._subtool = this.SUBTOOL_NONE; //this.SUBTOOL_PENMINUS;
@@ -1497,12 +1511,15 @@ exports.PenTool = Montage.create(ShapeTool, {
1497 this.eventManager.addEventListener("switchDocument", this, false); 1511 this.eventManager.addEventListener("switchDocument", this, false);
1498 this.eventManager.addEventListener("closeDocument", this, false); 1512 this.eventManager.addEventListener("closeDocument", this, false);
1499 this.eventManager.addEventListener("penSubToolChange", this, false); 1513 this.eventManager.addEventListener("penSubToolChange", this, false);
1514 this.eventManager.addEventListener("selectionChange", this, false);
1515
1500 } //if the pen tool was selected 1516 } //if the pen tool was selected
1501 else { 1517 else {
1502 if (this._trackMouseMoveWhenUp){ 1518 if (this._trackMouseMoveWhenUp){
1503 NJevent("disableStageMove"); 1519 NJevent("disableStageMove");
1504 } 1520 }
1505 this.deselectPenTool(); 1521 this.deselectPenTool();
1522
1506 defaultEventManager.removeEventListener("resetPenTool", this, false); 1523 defaultEventManager.removeEventListener("resetPenTool", this, false);
1507 this.application.ninja.elementMediator.deleteDelegate = null; 1524 this.application.ninja.elementMediator.deleteDelegate = null;
1508 1525
@@ -1510,10 +1527,70 @@ exports.PenTool = Montage.create(ShapeTool, {
1510 this.eventManager.removeEventListener("switchDocument", this, false); 1527 this.eventManager.removeEventListener("switchDocument", this, false);
1511 this.eventManager.removeEventListener("closeDocument", this, false); 1528 this.eventManager.removeEventListener("closeDocument", this, false);
1512 this.eventManager.removeEventListener("penSubToolChange", this, false); 1529 this.eventManager.removeEventListener("penSubToolChange", this, false);
1530 this.eventManager.removeEventListener("selectionChange", this, false);
1531 this._doesSelectionChangeNeedHandling = false;
1513 } //if the pen tool was de-selected 1532 } //if the pen tool was de-selected
1514 } 1533 }
1515 }, 1534 },
1516 1535
1536 handleSelectionChange: {
1537 value: function(){
1538 if (this._doesSelectionChangeNeedHandling){
1539 this.setEntryMode();
1540 }
1541 this._doesSelectionChangeNeedHandling = false;
1542 }
1543 },
1544 setEntryMode:{
1545 value: function(){
1546 if (this.application.ninja.selectedElements.length === 0){
1547 this._entryEditMode = this.ENTRY_SELECT_NONE;
1548 this._selectedSubpath = null;
1549 }
1550 else {
1551 for (var i=0;i<this.application.ninja.selectedElements.length;i++){
1552 var element = this.application.ninja.selectedElements[i];
1553 //console.log("Entered pen tool, had selected: " + element.elementModel.selection);
1554 if (element.elementModel.selection === 'Subpath'){ //TODO what to do if the canvas is drawn by tag tool?
1555 //set the pen canvas to be the selected canvas
1556 this._selectedSubpathCanvas = this.application.ninja.selectedElements[i];
1557
1558 // get the subpath for this world
1559 this._selectedSubpath = null;
1560 this._entryEditMode = this.ENTRY_SELECT_CANVAS; //by default, we're in this mode...change if we find a subpath contained in this canvas
1561 var world = ElementMediator.getShapeProperty(this._selectedSubpathCanvas, "GLWorld");
1562 if (world === null){
1563 throw("Pen tool handleSelectionChange did not work correctly");
1564 break; //something bad happened //TODO handle this better
1565 }
1566
1567 //TODO assuming that we want the first subpath in this world...fix this!
1568 var go = world.getGeomRoot();
1569 if (go !== null){
1570 while (go.geomType() !== go.GEOM_TYPE_CUBIC_BEZIER && go.getNext()) {
1571 go = go.getNext(); //find the first subpath in this world
1572 }
1573 if (go.geomType() === go.GEOM_TYPE_CUBIC_BEZIER){
1574 this._entryEditMode = this.ENTRY_SELECT_PATH;
1575 this._selectedSubpath = go;
1576 this._selectedSubpath.deselectAnchorPoint();
1577 this.DrawSubpathAnchors(this._selectedSubpath);