aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools')
-rw-r--r--js/tools/BrushTool.js14
-rwxr-xr-xjs/tools/PenTool.js444
2 files changed, 363 insertions, 95 deletions
</
diff --git a/js/tools/BrushTool.js b/js/tools/BrushTool.js
index 0be378fd..f85978ad 100644
--- a/js/tools/BrushTool.js
+++ b/js/tools/BrushTool.js
@@ -39,7 +39,7 @@ exports.BrushTool = Montage.create(ShapeTool, {
39 //view options 39 //view options
40 _brushStrokeCanvas: {value: null, writable: true}, 40 _brushStrokeCanvas: {value: null, writable: true},
41 _brushStrokePlaneMat: {value: null, writable: true}, 41 _brushStrokePlaneMat: {value: null, writable: true},
42 _draggingPlane: {value: null, writable: true}, 42 dragPlane: {value: null, writable: true},
43 43
44 //the current brush stroke 44 //the current brush stroke
45 _selectedBrushStroke: {value: null, writable: true}, 45 _selectedBrushStroke: {value: null, writable: true},
@@ -67,7 +67,7 @@ exports.BrushTool = Montage.create(ShapeTool, {
67 67
68 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y)); 68 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y));
69 var unsnappedpos = DrawingToolBase.getHitRecPos(snapManager.snap(point.x, point.y, false)); 69 var unsnappedpos = DrawingToolBase.getHitRecPos(snapManager.snap(point.x, point.y, false));
70 this._draggingPlane = snapManager.getDragPlane(); 70 this.dragPlane = snapManager.getDragPlane();
71 71
72 snapManager.enableElementSnap(elemSnap); 72 snapManager.enableElementSnap(elemSnap);
73 snapManager.enableGridSnap(gridSnap); 73 snapManager.enableGridSnap(gridSnap);
@@ -100,7 +100,7 @@ exports.BrushTool = Montage.create(ShapeTool, {
100 } 100 }
101 var tmpPoint = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y)); 101 var tmpPoint = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y));
102 var hitRec = snapManager.snap(tmpPoint.x, tmpPoint.y, false); 102 var hitRec = snapManager.snap(tmpPoint.x, tmpPoint.y, false);
103 this._draggingPlane = snapManager.getDragPlane(); 103 this.dragPlane = snapManager.getDragPlane();
104 if (this._selectedSubpathCanvas){ 104 if (this._selectedSubpathCanvas){
105 snapManager.popWorkingPlane(); 105 snapManager.popWorkingPlane();
106 } 106 }
@@ -225,9 +225,11 @@ exports.BrushTool = Montage.create(ShapeTool, {
225 this._hasDraw = false; 225 this._hasDraw = false;
226 226
227 //finish giving enough info. to the brush stroke 227 //finish giving enough info. to the brush stroke
228 this._selectedBrushStroke.setPlaneMatrix(this._brushStrokePlaneMat); 228 if (this._selectedBrushStroke){
229 this._selectedBrushStroke.setPlaneMatrixInverse(glmat4.inverse(this._brushStrokePlaneMat,[])); 229 this._selectedBrushStroke.setPlaneMatrix(this._brushStrokePlaneMat);
230 this._selectedBrushStroke.setDragPlane(this._draggingPlane); 230 this._selectedBrushStroke.setPlaneMatrixInverse(glmat4.inverse(this._brushStrokePlaneMat,[]));
231 this._selectedBrushStroke.setDragPlane(this.dragPlane);
232 }
231 233
232 //display the previously drawn stroke in a separate canvas 234 //display the previously drawn stroke in a separate canvas
233 this.RenderCurrentBrushStroke(); 235 this.RenderCurrentBrushStroke();
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index 3813123a..4daae420 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -33,10 +33,10 @@ exports.PenTool = Montage.create(ShapeTool, {
33 _parentNode: { enumerable: false, value: null, writable: true }, 33 _parentNode: { enumerable: false, value: null, writable: true },
34 _toolsPropertiesContainer: { enumerable: false, value: null, writable: true }, 34 _toolsPropertiesContainer: { enumerable: false, value: null, writable: true },
35 35
36 //set this to true if you want to keep making subpaths after closing current subpath (debugging only) 36 //set this to true if you want to keep making subpaths after closing current subpath (debugging only...should always be true)
37 _makeMultipleSubpaths: { value: true, writable: true }, 37 _makeMultipleSubpaths: { value: true, writable: true },
38 38
39 //set this to false if you don't want the mouse move handler being called when the mouse is not down (debugging only) 39 //set this to false if you don't want the mouse move handler being called when the mouse is not down (debugging only...should always be true)
40 _trackMouseMoveWhenUp: {value: true, writable: false}, 40 _trackMouseMoveWhenUp: {value: true, writable: false},
41 41
42 //whether the user has held down the Alt key 42 //whether the user has held down the Alt key
@@ -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 },
@@ -95,6 +97,12 @@ exports.PenTool = Montage.create(ShapeTool, {
95 ENTRY_SELECT_PATH: { value: 2, writable: false}, 97 ENTRY_SELECT_PATH: { value: 2, writable: false},
96 _entryEditMode: {value: this.ENTRY_SELECT_NONE, writable: true}, 98 _entryEditMode: {value: this.ENTRY_SELECT_NONE, writable: true},
97 99
100 //constants used for determining whether a subtool has been selected (mutually exclusive i.e. cannot be OR-ed)
101 SUBTOOL_NONE: {value: 0, writable: false},
102 SUBTOOL_PENPLUS: {value: 1, writable: false},
103 SUBTOOL_PENMINUS: {value: 2, writable: false},
104 _subtool: {value: this.SUBTOOL_NONE, writable: true},
105
98 //constants used for limiting size of the subpath canvas 106 //constants used for limiting size of the subpath canvas
99 _MAX_CANVAS_DIMENSION: {value: 3000, writable: false}, 107 _MAX_CANVAS_DIMENSION: {value: 3000, writable: false},
100 108
@@ -179,6 +187,71 @@ exports.PenTool = Montage.create(ShapeTool, {
179 } 187 }
180 }, 188 },
181 189
190 _removeSelectedSubpathAndCanvas:{
191 value: function(removeSelectedSubpath){
192 if (removeSelectedSubpath){
193 this._selectedSubpath.clearAllAnchors(); //perhaps unnecessary
194 this._selectedSubpath = null;
195 if (this._subtool === this.SUBTOOL_NONE){
196 if (this._entryEditMode === this.ENTRY_SELECT_PATH){
197 this._entryEditMode = this.ENTRY_SELECT_NONE;
198 }
199 }
200 } else {
201 this._selectedSubpath.setCanvas(null);
202 }
203 //clear the canvas
204 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas();
205
206 //undo/redo...go through ElementController and NJEvent
207 var els = [];
208 ElementController.removeElement(this._selectedSubpathCanvas);
209 els.push(this._selectedSubpathCanvas);
210 NJevent( "elementsRemoved", els );
211 this._selectedSubpathCanvas = null;
212 }
213 },
214
215 _removeSelectedAnchorPoint:{
216 value: function(){
217 this._hoveredAnchorIndex=-1;
218 this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex());
219 if (this._selectedSubpath.getNumAnchors()===1){
220 //convert the remaining anchor point to stage world coords
221 var xDelta = snapManager.getStageWidth()*0.5;
222 var yDelta = snapManager.getStageHeight()*0.5;
223 var anchor = this._selectedSubpath.getAnchor(0);
224 var swPos = ViewUtils.localToStageWorld([anchor.getPosX(),anchor.getPosY(),anchor.getPosZ()], this._selectedSubpathCanvas);
225 anchor.setPos(swPos[0]+xDelta, swPos[1]+yDelta, swPos[2]);
226 swPos = ViewUtils.localToStageWorld([anchor.getPrevX(),anchor.getPrevY(),anchor.getPrevZ()], this._selectedSubpathCanvas);
227 anchor.setPrevPos(swPos[0]+xDelta, swPos[1]+yDelta, swPos[2]);
228 swPos = ViewUtils.localToStageWorld([anchor.getNextX(),anchor.getNextY(),anchor.getNextZ()], this._selectedSubpathCanvas);
229 anchor.setNextPos(swPos[0]+xDelta, swPos[1]+yDelta, swPos[2]);
230 }
231 //clear the canvas
232 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas();
233 var removeSelectedSubpath=true;
234 var newNumAnchors = this._selectedSubpath.getNumAnchors();
235 if (newNumAnchors>1) {
236 this._selectedSubpath.createSamples(false);
237 this.PrepareSelectedSubpathForRendering();
238 this.ShowSelectedSubpath();
239 }
240 else {
241 //since we have 0 or 1 anchors, we will remove the selected canvas (as the path does not exist)
242 if (newNumAnchors===0){
243 removeSelectedSubpath = true;
244 } else{
245 removeSelectedSubpath = false; //don't remove the selected subpath if there is still one anchor
246 }
247 this._removeSelectedSubpathAndCanvas(removeSelectedSubpath);
248 }
249 if (!removeSelectedSubpath){
250 this.DrawSubpathAnchors(this._selectedSubpath);
251 }
252 }
253 },
254
182 // ********************************************************************************************************** 255 // **********************************************************************************************************
183 // Mouse down handler 256 // Mouse down handler
184 // IF the selected subpath is null, it means we're going to start a new subpath 257 // IF the selected subpath is null, it means we're going to start a new subpath
@@ -204,7 +277,7 @@ exports.PenTool = Montage.create(ShapeTool, {
204 value: function (event) { 277 value: function (event) {
205 //ignore any right or middle clicks 278 //ignore any right or middle clicks
206 if (event.button !== 0) { 279 if (event.button !== 0) {
207 //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) 280 //todo NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2)
208 return; 281 return;
209 } 282 }
210 283
@@ -215,11 +288,16 @@ exports.PenTool = Montage.create(ShapeTool, {
215 288
216 //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()
217 this._isNewPath = false; 290 this._isNewPath = false;
218 291
219 //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
220 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) {
221 this._selectedSubpath = null; 294 this._selectedSubpath = null;
222 } 295 }
296
297 if (this._subtool !== this.SUBTOOL_NONE && this._selectedSubpath===null) {
298 //do nothing because the pen plus and pen minus subtools need a selected subpath
299 return;
300 }
223 if (this._selectedSubpath === null) { 301 if (this._selectedSubpath === null) {
224 this._selectedSubpath = new SubPath(); 302 this._selectedSubpath = new SubPath();
225 this._selectedSubpathCanvas = null; 303 this._selectedSubpathCanvas = null;
@@ -255,12 +333,24 @@ exports.PenTool = Montage.create(ShapeTool, {
255 colorArray = [1,1,1,0]; 333 colorArray = [1,1,1,0];
256 } 334 }
257 this._selectedSubpath.setFillColor(colorArray); 335 this._selectedSubpath.setFillColor(colorArray);
258 } 336 } //if the selectedSubpath was null and needed to be constructed
259 337
260 //build the hit record for the current mouse position (on the stage or the plane of the path canvas) 338 //build the hit record for the current mouse position (on the stage or the plane of the path canvas)
261 var hitRec = this.getHitRecord(event.pageX, event.pageY, false); 339 var hitRec = this.getHitRecord(event.pageX, event.pageY, false);
262 340 var globalMousePos=null, localMousePos=null, stageWorldMousePos = null, drawingCanvas=null;
263 if (this._selectedSubpathCanvas === null){ 341 if (!this._selectedSubpathCanvas){
342 drawingCanvas = this.application.ninja.currentDocument.model.documentRoot;//ViewUtils.getStageElement();
343 stageWorldMousePos = hitRec.calculateStageWorldPoint();