aboutsummaryrefslogtreecommitdiff
path: root/js/tools/PenTool.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/PenTool.js')
-rwxr-xr-xjs/tools/PenTool.js67
1 files changed, 34 insertions, 33 deletions
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index 25423f76..1b9c4a5d 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -148,7 +149,7 @@ exports.PenTool = Montage.create(ShapeTool, {
148 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y)); 149 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y));
149 var pos; 150 var pos;
150 if (getStageWorld){ 151 if (getStageWorld){
151 pos = (snapManager.snap(point.x, point.y, false)).calculateStageWorldPoint(); 152 pos = (snapManager.snap(point.x, point.y, false)).calculateStageWorldPoint();
152 } else { 153 } else {
153 pos = (snapManager.snap(point.x, point.y, false)).getScreenPoint(); 154 pos = (snapManager.snap(point.x, point.y, false)).getScreenPoint();
154 } 155 }
@@ -306,7 +307,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) 307 //todo NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2)
307 return; 308 return;
308 } 309 }
309 310
310 //set the drawing flags (see the drawing-tool.js base class) 311 //set the drawing flags (see the drawing-tool.js base class)
311 if (this._canDraw) { 312 if (this._canDraw) {
312 this._isDrawing = true; 313 this._isDrawing = true;
@@ -423,7 +424,7 @@ exports.PenTool = Montage.create(ShapeTool, {
423 console.log("WARNING picked anchor point with incorrect mode"); 424 console.log("WARNING picked anchor point with incorrect mode");
424 break; 425 break;
425 } 426 }
426 427
427 } else { 428 } else {
428 this._selectedSubpath.addAnchor(new AnchorPoint()); 429 this._selectedSubpath.addAnchor(new AnchorPoint());
429 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 430 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
@@ -568,7 +569,7 @@ exports.PenTool = Montage.create(ShapeTool, {
568 //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) 569 //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2)
569 return; 570 return;
570 } 571 }
571 572
572 //set the cursor to be the default cursor (depending on whether the selected subpath has any points yet) 573 //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){ 574 if (this._subtool===this.SUBTOOL_NONE){
574 if ((this._selectedSubpath && this._selectedSubpath.getNumAnchors()>0 && !this._selectedSubpath.getIsClosed()) 575 if ((this._selectedSubpath && this._selectedSubpath.getNumAnchors()>0 && !this._selectedSubpath.getIsClosed())
@@ -618,7 +619,7 @@ exports.PenTool = Montage.create(ShapeTool, {
618 var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 619 var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
619 var selAnchorPos = selAnchor.getAllPos(); 620 var selAnchorPos = selAnchor.getAllPos();
620 var localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorPos[1]); 621 var localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorPos[1]);
621 622
622 if (this._editMode & this.EDIT_ANCHOR) { 623 if (this._editMode & this.EDIT_ANCHOR) {
623 selAnchor.translateAll(localTranslation[0], localTranslation[1], localTranslation[2]); 624 selAnchor.translateAll(localTranslation[0], localTranslation[1], localTranslation[2]);
624 } 625 }
@@ -691,7 +692,7 @@ exports.PenTool = Montage.create(ShapeTool, {
691 } //if path is not closed 692 } //if path is not closed
692 } else if (this._subtool === this.SUBTOOL_PENMINUS && selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_ANCHOR){ 693 } 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"; 694 cursor = "url('images/cursors/penCursors/Pen_minus.png') 5 1, default";
694 } 695 }
695 this.application.ninja.stage.drawingCanvas.style.cursor = cursor; 696 this.application.ninja.stage.drawingCanvas.style.cursor = cursor;
696 } else if (selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_PATH) { 697 } else if (selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_PATH) {
697 //change the cursor only if we're not in pen-minus subtool 698 //change the cursor only if we're not in pen-minus subtool
@@ -825,7 +826,7 @@ exports.PenTool = Montage.create(ShapeTool, {
825 //TODO this will not work if there are multiple shapes in the same canvas 826 //TODO this will not work if there are multiple shapes in the same canvas
826 canvas.elementModel.shapeModel.GLGeomObj = subpath; 827 canvas.elementModel.shapeModel.GLGeomObj = subpath;
827 828
828 if(canvas.elementModel.isShape) 829 if(canvas.elementModel.isShape)
829 { 830 {
830 this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the canvas 831 this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the canvas
831 this.application.ninja.selectionController.selectElement(canvas); 832 this.application.ninja.selectionController.selectElement(canvas);
@@ -841,7 +842,7 @@ exports.PenTool = Montage.create(ShapeTool, {
841 // Check if the selected anchor point of the selected subpath should be snapped to another anchor point 842 // 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) 843 // (also sets open subpaths closed if appropriate)
843 // IF the selected subpath does not have a canvas 844 // IF the selected subpath does not have a canvas
844 // 845 //
845 // Draw the selected subpath anchors and the selected subpath itself in the stage's context 846 // Draw the selected subpath anchors and the selected subpath itself in the stage's context
846 // ********************************************************************************************************** 847 // **********************************************************************************************************
847 HandleLeftButtonUp: { 848 HandleLeftButtonUp: {
@@ -851,7 +852,7 @@ exports.PenTool = Montage.create(ShapeTool, {
851 if (this._subtool===this.SUBTOOL_PENMINUS){ 852 if (this._subtool===this.SUBTOOL_PENMINUS){
852 return; 853 return;
853 } 854 }
854 855
855 // ******************** snapping *********************** 856 // ******************** snapping ***********************
856 // if there was a snapTarget and a selected anchor, move the anchor to the snap target 857 // 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) { 858 if (this._snapTargetIndex !== -1 && this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) {
@@ -903,7 +904,7 @@ exports.PenTool = Montage.create(ShapeTool, {
903 //if (this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._entryEditMode !== this.ENTRY_SELECT_PATH){ 904 //if (this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._entryEditMode !== this.ENTRY_SELECT_PATH){
904 // this._selectedSubpath = null; 905 // this._selectedSubpath = null;
905 //} 906 //}
906 907
907 if (this._selectedSubpath){ 908 if (this._selectedSubpath){
908 this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas 909 this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas
909 }else{ 910 }else{
@@ -937,7 +938,7 @@ exports.PenTool = Montage.create(ShapeTool, {
937 return;//nothing to do 938 return;//nothing to do
938 } 939 }
939 this._selectedSubpath.makeDirty(); 940 this._selectedSubpath.makeDirty();
940 941
941 var bboxMin=null, bboxMax=null; 942 var bboxMin=null, bboxMax=null;
942 if (this._selectedSubpathCanvas) { 943 if (this._selectedSubpathCanvas) {
943 //if there already is a subpath canvas, it means the anchor points are in local space 944 //if there already is a subpath canvas, it means the anchor points are in local space
@@ -980,7 +981,7 @@ exports.PenTool = Montage.create(ShapeTool, {
980 glmat4.multiply( newMat, tMat, newMat); 981 glmat4.multiply( newMat, tMat, newMat);
981 this._selectedSubpathPlaneMat = newMat; 982 this._selectedSubpathPlaneMat = newMat;
982 ViewUtils.setMatrixForElement(this._selectedSubpathCanvas, newMat, true); 983 ViewUtils.setMatrixForElement(this._selectedSubpathCanvas, newMat, true);
983 984
984 //now set the center of the canvas as the center of the bounding box expressed in stage world coordinates 985 //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); 986 var localToStageWorldMat = ViewUtils.getLocalToStageWorldMatrix(this._selectedSubpathCanvas, false, false);
986 this._selectedSubpathCanvasCenter = MathUtils.transformAndDivideHomogeneousPoint(bboxMid, localToStageWorldMat); 987 this._selectedSubpathCanvasCenter = MathUtils.transformAndDivideHomogeneousPoint(bboxMid, localToStageWorldMat);
@@ -1009,7 +1010,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1009 currAnchor.setNextPos(localNext[0],localNext[1],localNext[2]); 1010 currAnchor.setNextPos(localNext[0],localNext[1],localNext[2]);
1010 } 1011 }
1011 } 1012 }
1012 1013
1013 this._selectedSubpath.makeDirty(); 1014 this._selectedSubpath.makeDirty();
1014 this._selectedSubpath.createSamples(false); 1015 this._selectedSubpath.createSamples(false);
1015 this._selectedSubpath.offsetPerBBoxMin(); 1016 this._selectedSubpath.offsetPerBBoxMin();
@@ -1104,10 +1105,10 @@ exports.PenTool = Montage.create(ShapeTool, {
1104 handleScroll: { 1105 handleScroll: {
1105 value: function(event) { 1106 value: function(event) {
1106 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); 1107 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas();
1107 this.DrawSubpathAnchors(this._selectedSubpath); 1108 this.DrawSubpathAnchors(this._selectedSubpath);
1108 } 1109 }
1109 }, 1110 },
1110 1111
1111 BuildSecondCtrlPoint:{ 1112 BuildSecondCtrlPoint:{
1112 value: function(p0, p2, p3) { 1113 value: function(p0, p2, p3) {
1113 var baselineOrig = VecUtils.vecSubtract(3, p3, p0); 1114 var baselineOrig = VecUtils.vecSubtract(3, p3, p0);
@@ -1199,7 +1200,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1199 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); 1200 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas();
1200 1201
1201 this.DrawSubpathAnchors(this._selectedSubpath); 1202 this.DrawSubpathAnchors(this._selectedSubpath);
1202 } //if (this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) 1203 } //if (this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1)
1203 1204
1204 } //value: function () { 1205 } //value: function () {
1205 }, //HandleDoubleClick: { 1206 }, //HandleDoubleClick: {
@@ -1503,7 +1504,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1503 /*if (this.application.ninja.selectedElements.length === 0){ 1504 /*if (this.application.ninja.selectedElements.length === 0){
1504 this._entryEditMode = this.ENTRY_SELECT_NONE; 1505 this._entryEditMode = this.ENTRY_SELECT_NONE;
1505 } 1506 }
1506 1507
1507 else{ 1508 else{
1508 for (var i=0;i<this.application.ninja.selectedElements.length;i++){ 1509 for (var i=0;i<this.application.ninja.selectedElements.length;i++){
1509 var element = this.application.ninja.selectedElements[i]; 1510 var element = this.application.ninja.selectedElements[i];
@@ -1549,7 +1550,7 @@ exports.PenTool = Montage.create(ShapeTool, {