aboutsummaryrefslogtreecommitdiff
path: root/js/tools/PenTool.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/PenTool.js')
-rwxr-xr-xjs/tools/PenTool.js46
1 files changed, 23 insertions, 23 deletions
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index 25423f76..7e07680d 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -29,7 +29,7 @@ POSSIBILITY OF SUCH DAMAGE.
29</copyright> */ 29</copyright> */
30 30
31var ShapeTool = require("js/tools/ShapeTool").ShapeTool; 31var ShapeTool = require("js/tools/ShapeTool").ShapeTool;
32var ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; 32var ShapesController = require("js/controllers/elements/shapes-controller").ShapesController;
33var DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase; 33var DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase;
34var defaultEventManager = require("montage/core/event/event-manager").defaultEventManager; 34var defaultEventManager = require("montage/core/event/event-manager").defaultEventManager;
35var Montage = require("montage/core/core").Montage; 35var Montage = require("montage/core/core").Montage;
@@ -148,7 +148,7 @@ exports.PenTool = Montage.create(ShapeTool, {
148 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y)); 148 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y));
149 var pos; 149 var pos;
150 if (getStageWorld){ 150 if (getStageWorld){
151 pos = (snapManager.snap(point.x, point.y, false)).calculateStageWorldPoint(); 151 pos = (snapManager.snap(point.x, point.y, false)).calculateStageWorldPoint();
152 } else { 152 } else {
153 pos = (snapManager.snap(point.x, point.y, false)).getScreenPoint(); 153 pos = (snapManager.snap(point.x, point.y, false)).getScreenPoint();
154 } 154 }
@@ -306,7 +306,7 @@ exports.PenTool = Montage.create(ShapeTool, {
306 //todo NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) 306 //todo NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2)
307 return; 307 return;
308 } 308 }
309 309
310 //set the drawing flags (see the drawing-tool.js base class) 310 //set the drawing flags (see the drawing-tool.js base class)
311 if (this._canDraw) { 311 if (this._canDraw) {
312 this._isDrawing = true; 312 this._isDrawing = true;
@@ -423,7 +423,7 @@ exports.PenTool = Montage.create(ShapeTool, {
423 console.log("WARNING picked anchor point with incorrect mode"); 423 console.log("WARNING picked anchor point with incorrect mode");
424 break; 424 break;
425 } 425 }
426 426
427 } else { 427 } else {
428 this._selectedSubpath.addAnchor(new AnchorPoint()); 428 this._selectedSubpath.addAnchor(new AnchorPoint());
429 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 429 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
@@ -568,7 +568,7 @@ exports.PenTool = Montage.create(ShapeTool, {
568 //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) 568 //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2)
569 return; 569 return;
570 } 570 }
571 571
572 //set the cursor to be the default cursor (depending on whether the selected subpath has any points yet) 572 //set the cursor to be the default cursor (depending on whether the selected subpath has any points yet)
573 if (this._subtool===this.SUBTOOL_NONE){ 573 if (this._subtool===this.SUBTOOL_NONE){
574 if ((this._selectedSubpath && this._selectedSubpath.getNumAnchors()>0 && !this._selectedSubpath.getIsClosed()) 574 if ((this._selectedSubpath && this._selectedSubpath.getNumAnchors()>0 && !this._selectedSubpath.getIsClosed())
@@ -618,7 +618,7 @@ exports.PenTool = Montage.create(ShapeTool, {
618 var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 618 var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
619 var selAnchorPos = selAnchor.getAllPos(); 619 var selAnchorPos = selAnchor.getAllPos();
620 var localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorPos[1]); 620 var localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorPos[1]);
621 621
622 if (this._editMode & this.EDIT_ANCHOR) { 622 if (this._editMode & this.EDIT_ANCHOR) {
623 selAnchor.translateAll(localTranslation[0], localTranslation[1], localTranslation[2]); 623 selAnchor.translateAll(localTranslation[0], localTranslation[1], localTranslation[2]);
624 } 624 }
@@ -691,7 +691,7 @@ exports.PenTool = Montage.create(ShapeTool, {
691 } //if path is not closed 691 } //if path is not closed
692 } else if (this._subtool === this.SUBTOOL_PENMINUS && selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_ANCHOR){ 692 } else if (this._subtool === this.SUBTOOL_PENMINUS && selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_ANCHOR){
693 cursor = "url('images/cursors/penCursors/Pen_minus.png') 5 1, default"; 693 cursor = "url('images/cursors/penCursors/Pen_minus.png') 5 1, default";
694 } 694 }
695 this.application.ninja.stage.drawingCanvas.style.cursor = cursor; 695 this.application.ninja.stage.drawingCanvas.style.cursor = cursor;
696 } else if (selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_PATH) { 696 } else if (selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_PATH) {
697 //change the cursor only if we're not in pen-minus subtool 697 //change the cursor only if we're not in pen-minus subtool
@@ -825,7 +825,7 @@ exports.PenTool = Montage.create(ShapeTool, {
825 //TODO this will not work if there are multiple shapes in the same canvas 825 //TODO this will not work if there are multiple shapes in the same canvas
826 canvas.elementModel.shapeModel.GLGeomObj = subpath; 826 canvas.elementModel.shapeModel.GLGeomObj = subpath;
827 827
828 if(canvas.elementModel.isShape) 828 if(canvas.elementModel.isShape)
829 { 829 {
830 this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the canvas 830 this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the canvas
831 this.application.ninja.selectionController.selectElement(canvas); 831 this.application.ninja.selectionController.selectElement(canvas);
@@ -841,7 +841,7 @@ exports.PenTool = Montage.create(ShapeTool, {
841 // Check if the selected anchor point of the selected subpath should be snapped to another anchor point 841 // Check if the selected anchor point of the selected subpath should be snapped to another anchor point
842 // (also sets open subpaths closed if appropriate) 842 // (also sets open subpaths closed if appropriate)
843 // IF the selected subpath does not have a canvas 843 // IF the selected subpath does not have a canvas
844 // 844 //
845 // Draw the selected subpath anchors and the selected subpath itself in the stage's context 845 // Draw the selected subpath anchors and the selected subpath itself in the stage's context
846 // ********************************************************************************************************** 846 // **********************************************************************************************************
847 HandleLeftButtonUp: { 847 HandleLeftButtonUp: {
@@ -851,7 +851,7 @@ exports.PenTool = Montage.create(ShapeTool, {
851 if (this._subtool===this.SUBTOOL_PENMINUS){ 851 if (this._subtool===this.SUBTOOL_PENMINUS){
852 return; 852 return;
853 } 853 }
854 854
855 // ******************** snapping *********************** 855 // ******************** snapping ***********************
856 // if there was a snapTarget and a selected anchor, move the anchor to the snap target 856 // if there was a snapTarget and a selected anchor, move the anchor to the snap target
857 if (this._snapTargetIndex !== -1 && this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) { 857 if (this._snapTargetIndex !== -1 && this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) {
@@ -903,7 +903,7 @@ exports.PenTool = Montage.create(ShapeTool, {
903 //if (this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._entryEditMode !== this.ENTRY_SELECT_PATH){ 903 //if (this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._entryEditMode !== this.ENTRY_SELECT_PATH){
904 // this._selectedSubpath = null; 904 // this._selectedSubpath = null;
905 //} 905 //}
906 906
907 if (this._selectedSubpath){ 907 if (this._selectedSubpath){
908 this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas 908 this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas
909 }else{ 909 }else{
@@ -937,7 +937,7 @@ exports.PenTool = Montage.create(ShapeTool, {
937 return;//nothing to do 937 return;//nothing to do
938 } 938 }
939 this._selectedSubpath.makeDirty(); 939 this._selectedSubpath.makeDirty();
940 940
941 var bboxMin=null, bboxMax=null; 941 var bboxMin=null, bboxMax=null;
942 if (this._selectedSubpathCanvas) { 942 if (this._selectedSubpathCanvas) {
943 //if there already is a subpath canvas, it means the anchor points are in local space 943 //if there already is a subpath canvas, it means the anchor points are in local space
@@ -980,7 +980,7 @@ exports.PenTool = Montage.create(ShapeTool, {
980 glmat4.multiply( newMat, tMat, newMat); 980 glmat4.multiply( newMat, tMat, newMat);
981 this._selectedSubpathPlaneMat = newMat; 981 this._selectedSubpathPlaneMat = newMat;
982 ViewUtils.setMatrixForElement(this._selectedSubpathCanvas, newMat, true); 982 ViewUtils.setMatrixForElement(this._selectedSubpathCanvas, newMat, true);
983 983
984 //now set the center of the canvas as the center of the bounding box expressed in stage world coordinates 984 //now set the center of the canvas as the center of the bounding box expressed in stage world coordinates
985 var localToStageWorldMat = ViewUtils.getLocalToStageWorldMatrix(this._selectedSubpathCanvas, false, false); 985 var localToStageWorldMat = ViewUtils.getLocalToStageWorldMatrix(this._selectedSubpathCanvas, false, false);
986 this._selectedSubpathCanvasCenter = MathUtils.transformAndDivideHomogeneousPoint(bboxMid, localToStageWorldMat); 986 this._selectedSubpathCanvasCenter = MathUtils.transformAndDivideHomogeneousPoint(bboxMid, localToStageWorldMat);
@@ -1009,7 +1009,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1009 currAnchor.setNextPos(localNext[0],localNext[1],localNext[2]); 1009 currAnchor.setNextPos(localNext[0],localNext[1],localNext[2]);
1010 } 1010 }
1011 } 1011 }
1012 1012
1013 this._selectedSubpath.makeDirty(); 1013 this._selectedSubpath.makeDirty();
1014 this._selectedSubpath.createSamples(false); 1014 this._selectedSubpath.createSamples(false);
1015 this._selectedSubpath.offsetPerBBoxMin(); 1015 this._selectedSubpath.offsetPerBBoxMin();
@@ -1104,10 +1104,10 @@ exports.PenTool = Montage.create(ShapeTool, {
1104 handleScroll: { 1104 handleScroll: {
1105 value: function(event) { 1105 value: function(event) {
1106 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); 1106 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas();
1107 this.DrawSubpathAnchors(this._selectedSubpath); 1107 this.DrawSubpathAnchors(this._selectedSubpath);
1108 } 1108 }
1109 }, 1109 },
1110 1110
1111 BuildSecondCtrlPoint:{ 1111 BuildSecondCtrlPoint:{
1112 value: function(p0, p2, p3) { 1112 value: function(p0, p2, p3) {
1113 var baselineOrig = VecUtils.vecSubtract(3, p3, p0); 1113 var baselineOrig = VecUtils.vecSubtract(3, p3, p0);
@@ -1199,7 +1199,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1199 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); 1199 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas();
1200 1200
1201 this.DrawSubpathAnchors(this._selectedSubpath); 1201 this.DrawSubpathAnchors(this._selectedSubpath);
1202 } //if (this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) 1202 } //if (this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1)
1203 1203
1204 } //value: function () { 1204 } //value: function () {
1205 }, //HandleDoubleClick: { 1205 }, //HandleDoubleClick: {
@@ -1503,7 +1503,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1503 /*if (this.application.ninja.selectedElements.length === 0){ 1503 /*if (this.application.ninja.selectedElements.length === 0){
1504 this._entryEditMode = this.ENTRY_SELECT_NONE; 1504 this._entryEditMode = this.ENTRY_SELECT_NONE;
1505 } 1505 }
1506 1506
1507 else{ 1507 else{
1508 for (var i=0;i<this.application.ninja.selectedElements.length;i++){ 1508 for (var i=0;i<this.application.ninja.selectedElements.length;i++){
1509 var element = this.application.ninja.selectedElements[i]; 1509 var element = this.application.ninja.selectedElements[i];
@@ -1549,7 +1549,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1549 1549
1550 this.handlePenSubToolChange(); 1550 this.handlePenSubToolChange();
1551 //this._subtool = this.SUBTOOL_NONE; //this.SUBTOOL_PENMINUS; 1551 //this._subtool = this.SUBTOOL_NONE; //this.SUBTOOL_PENMINUS;
1552 1552
1553 if (this._trackMouseMoveWhenUp){ 1553 if (this._trackMouseMoveWhenUp){
1554 NJevent("enableStageMove"); 1554 NJevent("enableStageMove");
1555 } 1555 }
@@ -1558,7 +1558,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1558 this.eventManager.addEventListener("closeDocument", this, false); 1558 this.eventManager.addEventListener("closeDocument", this, false);
1559 this.eventManager.addEventListener("penSubToolChange", this, false); 1559 this.eventManager.addEventListener("penSubToolChange", this, false);
1560 this.eventManager.addEventListener("selectionChange", this, false); 1560 this.eventManager.addEventListener("selectionChange", this, false);
1561 1561
1562 } //if the pen tool was selected 1562 } //if the pen tool was selected
1563 else { 1563 else {
1564 if (this._trackMouseMoveWhenUp){ 1564 if (this._trackMouseMoveWhenUp){
@@ -1568,7 +1568,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1568 1568
1569 defaultEventManager.removeEventListener("resetPenTool", this, false); 1569 defaultEventManager.removeEventListener("resetPenTool", this, false);
1570 this.application.ninja.elementMediator.deleteDelegate = null; 1570 this.application.ninja.elementMediator.deleteDelegate = null;
1571 1571
1572 this.eventManager.removeEventListener("openDocument", this, false);