aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools')
-rw-r--r--js/tools/BrushTool.js8
-rwxr-xr-xjs/tools/PenTool.js271
2 files changed, 215 insertions, 64 deletions
diff --git a/js/tools/BrushTool.js b/js/tools/BrushTool.js
index 0be378fd..03edef79 100644
--- a/js/tools/BrushTool.js
+++ b/js/tools/BrushTool.js
@@ -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._draggingPlane);
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 10eb03c9..cc8ec394 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
@@ -95,6 +95,12 @@ exports.PenTool = Montage.create(ShapeTool, {
95 ENTRY_SELECT_PATH: { value: 2, writable: false}, 95 ENTRY_SELECT_PATH: { value: 2, writable: false},
96 _entryEditMode: {value: this.ENTRY_SELECT_NONE, writable: true}, 96 _entryEditMode: {value: this.ENTRY_SELECT_NONE, writable: true},
97 97
98 //constants used for determining whether a subtool has been selected (mutually exclusive i.e. cannot be OR-ed)
99 SUBTOOL_NONE: {value: 0, writable: false},
100 SUBTOOL_PENPLUS: {value: 1, writable: false},
101 SUBTOOL_PENMINUS: {value: 2, writable: false},
102 _subtool: {value: this.SUBTOOL_NONE, writable: true},
103
98 //constants used for limiting size of the subpath canvas 104 //constants used for limiting size of the subpath canvas
99 _MAX_CANVAS_DIMENSION: {value: 3000, writable: false}, 105 _MAX_CANVAS_DIMENSION: {value: 3000, writable: false},
100 106
@@ -179,6 +185,70 @@ exports.PenTool = Montage.create(ShapeTool, {
179 } 185 }
180 }, 186 },
181 187
188 _removeSelectedSubpathAndCanvas:{
189 value: function(removeSelectedSubpath){
190 if (removeSelectedSubpath){
191 this._selectedSubpath.clearAllAnchors(); //perhaps unnecessary
192 this._selectedSubpath = null;
193 if (this._entryEditMode === this.ENTRY_SELECT_PATH){
194 this._entryEditMode = this.ENTRY_SELECT_NONE;
195 }
196 this._subtool = this.SUBTOOL_NONE;
197 } else {
198 this._selectedSubpath.setCanvas(null);
199 }
200 //clear the canvas
201 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas();
202
203 //undo/redo...go through ElementController and NJEvent
204 var els = [];
205 ElementController.removeElement(this._selectedSubpathCanvas);
206 els.push(this._selectedSubpathCanvas);
207 NJevent( "elementsRemoved", els );
208 this._selectedSubpathCanvas = null;
209 }
210 },
211
212 _removeSelectedAnchorPoint:{
213 value: function(){
214 this._hoveredAnchorIndex=-1;
215 this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex());
216 if (this._selectedSubpath.getNumAnchors()===1){
217 //convert the remaining anchor point to stage world coords
218 var xDelta = snapManager.getStageWidth()*0.5;
219 var yDelta = snapManager.getStageHeight()*0.5;
220 var anchor = this._selectedSubpath.getAnchor(0);
221 var swPos = ViewUtils.localToStageWorld([anchor.getPosX(),anchor.getPosY(),anchor.getPosZ()], this._selectedSubpathCanvas);
222 anchor.setPos(swPos[0]+xDelta, swPos[1]+yDelta, swPos[2]);
223 swPos = ViewUtils.localToStageWorld([anchor.getPrevX(),anchor.getPrevY(),anchor.getPrevZ()], this._selectedSubpathCanvas);
224 anchor.setPrevPos(swPos[0]+xDelta, swPos[1]+yDelta, swPos[2]);
225 swPos = ViewUtils.localToStageWorld([anchor.getNextX(),anchor.getNextY(),anchor.getNextZ()], this._selectedSubpathCanvas);
226 anchor.setNextPos(swPos[0]+xDelta, swPos[1]+yDelta, swPos[2]);
227 }
228 //clear the canvas
229 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas();
230 var removeSelectedSubpath=true;
231 var newNumAnchors = this._selectedSubpath.getNumAnchors();
232 if (newNumAnchors>1) {
233 this._selectedSubpath.createSamples(false);
234 this.PrepareSelectedSubpathForRendering();
235 this.ShowSelectedSubpath();
236 }
237 else {
238 //since we have 0 or 1 anchors, we will remove the selected canvas (as the path does not exist)
239 if (newNumAnchors===0){
240 removeSelectedSubpath = true;
241 } else{
242 removeSelectedSubpath = false; //don't remove the selected subpath if there is still one anchor
243 }
244 this._removeSelectedSubpathAndCanvas(removeSelectedSubpath);
245 }
246 if (!removeSelectedSubpath){
247 this.DrawSubpathAnchors(this._selectedSubpath);
248 }
249 }
250 },
251
182 // ********************************************************************************************************** 252 // **********************************************************************************************************
183 // Mouse down handler 253 // Mouse down handler
184 // IF the selected subpath is null, it means we're going to start a new subpath 254 // IF the selected subpath is null, it means we're going to start a new subpath
@@ -220,6 +290,11 @@ exports.PenTool = Montage.create(ShapeTool, {
220 if (this._entryEditMode !== this.ENTRY_SELECT_PATH && this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._makeMultipleSubpaths) { 290 if (this._entryEditMode !== this.ENTRY_SELECT_PATH && this._selectedSubpath && this._selectedSubpath.getIsClosed() && this._makeMultipleSubpaths) {
221 this._selectedSubpath = null; 291 this._selectedSubpath = null;
222 } 292 }
293
294 if (this._subtool !== this.SUBTOOL_NONE && this._selectedSubpath===null) {
295 //do nothing because the pen plus and pen minus subtools need a selected subpath
296 return;
297 }
223 if (this._selectedSubpath === null) { 298 if (this._selectedSubpath === null) {
224 this._selectedSubpath = new SubPath(); 299 this._selectedSubpath = new SubPath();
225 this._selectedSubpathCanvas = null; 300 this._selectedSubpathCanvas = null;
@@ -255,7 +330,7 @@ exports.PenTool = Montage.create(ShapeTool, {
255 colorArray = [1,1,1,0]; 330 colorArray = [1,1,1,0];
256 } 331 }
257 this._selectedSubpath.setFillColor(colorArray); 332 this._selectedSubpath.setFillColor(colorArray);
258 } 333 } //if the selectedSubpath was null and needed to be constructed
259 334
260 //build the hit record for the current mouse position (on the stage or the plane of the path canvas) 335 //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); 336 var hitRec = this.getHitRecord(event.pageX, event.pageY, false);
@@ -273,14 +348,36 @@ exports.PenTool = Montage.create(ShapeTool, {
273 var swMousePos = hitRec.calculateStageWorldPoint(); 348 var swMousePos = hitRec.calculateStageWorldPoint();
274 swMousePos[0]+= snapManager.getStageWidth()*0.5; swMousePos[1]+= snapManager.getStageHeight()*0.5; 349 swMousePos[0]+= snapManager.getStageWidth()*0.5; swMousePos[1]+= snapManager.getStageHeight()*0.5;
275 350
276 this._selectedSubpath.addAnchor(new AnchorPoint()); 351 //check if the mouse click location is close to the existing anchor
277 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 352 var indexAndCode = this._selectedSubpath.pickAnchor(swMousePos[0], swMousePos[1], swMousePos[2], this._PICK_POINT_RADIUS);
278 newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]); 353 if (indexAndCode[0]>=0){
279 newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]); 354 //the anchor point was hit, so we do not add another anchor
280 newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]); 355 switch(indexAndCode[1]){
281 //set the mode so that dragging will update the next and previous locations 356 case this._selectedSubpath.SEL_ANCHOR:
282 this._editMode = this.EDIT_PREV_NEXT; 357 this._editMode = this.EDIT_ANCHOR;
283 } 358 break;
359 case this._selectedSubpath.SEL_PREV:
360 this._editMode = this.EDIT_PREV;
361 break;
362 case this._selectedSubpath.SEL_NEXT:
363 this._editMode = this.EDIT_NEXT;
364 break;
365 default:
366 this._editMode = this.EDIT_ANCHOR;
367 console.log("WARNING picked anchor point with incorrect mode");
368 break;
369 }
370
371 } else {
372 this._selectedSubpath.addAnchor(new AnchorPoint());
373 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
374 newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]);
375 newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]);
376 newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]);
377 //set the mode so that dragging will update the next and previous locations
378 this._editMode = this.EDIT_PREV_NEXT;
379 }
380 } //if we have not yet created a canvas for this path
284 381
285 //the selected subpath has a canvas, so test within that canvas' space 382 //the selected subpath has a canvas, so test within that canvas' space
286 else 383 else
@@ -311,6 +408,11 @@ exports.PenTool = Montage.create(ShapeTool, {
311 if (whichPoint !== this._selectedSubpath.SEL_NONE){ 408 if (whichPoint !== this._selectedSubpath.SEL_NONE){
312 //if we hit the anchor point itself 409 //if we hit the anchor point itself
313 if (whichPoint & this._selectedSubpath.SEL_ANCHOR) { 410 if (whichPoint & this._selectedSubpath.SEL_ANCHOR) {
411 if (this._subtool===this.SUBTOOL_PENMINUS){
412 //remove the selected anchor, similar to HandleDelete
413 this._removeSelectedAnchorPoint();
414 return;
415 }
314 //if we're in ENTRY_SELECT_PATH mode AND we have not yet clicked on the endpoint AND if we have now clicked on the endpoint 416 //if we're in ENTRY_SELECT_PATH mode AND we have not yet clicked on the endpoint AND if we have now clicked on the endpoint
315 if (this._entryEditMode === this.ENTRY_SELECT_PATH && this._isPickedEndPointInSelectPathMode === false){ 417 if (this._entryEditMode === this.ENTRY_SELECT_PATH && this._isPickedEndPointInSelectPathMode === false){
316 var selAnchorIndex = this._selectedSubpath.getSelectedAnchorIndex(); 418 var selAnchorIndex = this._selectedSubpath.getSelectedAnchorIndex();
@@ -416,6 +518,7 @@ exports.PenTool = Montage.create(ShapeTool, {
416 "url('images/cursors/penCursors/Pen_newPath.png') 5 1, default"; 518 "url('images/cursors/penCursors/Pen_newPath.png') 5 1, default";
417 } 519 }
418 520
521
419 if (!this._selectedSubpath ){ 522 if (!this._selectedSubpath ){
420 return; //nothing to do in case no subpath is selected 523 return; //nothing to do in case no subpath is selected
421 } 524 }
@@ -454,19 +557,18 @@ exports.PenTool = Montage.create(ShapeTool, {
454 else if (this._editMode & this.EDIT_PREV) { 557 else if (this._editMode & this.EDIT_PREV) {
455 localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorPos[0]); 558 localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorPos[0]);
456 selAnchor.translatePrev(localTranslation[0], localTranslation[1], localTranslation[2]); 559 selAnchor.translatePrev(localTranslation[0], localTranslation[1], localTranslation[2]);
457 560