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.js165
2 files changed, 133 insertions, 40 deletions
<
diff --git a/js/tools/BrushTool.js b/js/tools/BrushTool.js
index 5c334b92..5d4e8288 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 16990ca7..fd470af7 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -273,14 +273,36 @@ exports.PenTool = Montage.create(ShapeTool, {
273 var swMousePos = hitRec.calculateStageWorldPoint(); 273 var swMousePos = hitRec.calculateStageWorldPoint();
274 swMousePos[0]+= snapManager.getStageWidth()*0.5; swMousePos[1]+= snapManager.getStageHeight()*0.5; 274 swMousePos[0]+= snapManager.getStageWidth()*0.5; swMousePos[1]+= snapManager.getStageHeight()*0.5;
275 275
276 this._selectedSubpath.addAnchor(new AnchorPoint()); 276 //check if the mouse click location is close to the existing anchor
277 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 277 var indexAndCode = this._selectedSubpath.pickAnchor(swMousePos[0], swMousePos[1], swMousePos[2], this._PICK_POINT_RADIUS);
278 newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]); 278 if (indexAndCode[0]>=0){
279 newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]); 279 //the anchor point was hit, so we do not add another anchor
280 newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]); 280 switch(indexAndCode[1]){
281 //set the mode so that dragging will update the next and previous locations 281 case this._selectedSubpath.SEL_ANCHOR:
282 this._editMode = this.EDIT_PREV_NEXT; 282 this._editMode = this.EDIT_ANCHOR;
283 } 283 break;
284 case this._selectedSubpath.SEL_PREV:
285 this._editMode = this.EDIT_PREV;
286 break;
287 case this._selectedSubpath.SEL_NEXT:
288 this._editMode = this.EDIT_NEXT;
289 break;
290 default:
291 this._editMode = this.EDIT_ANCHOR;
292 console.log("WARNING picked anchor point with incorrect mode");
293 break;
294 }
295
296 } else {
297 this._selectedSubpath.addAnchor(new AnchorPoint());
298 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
299 newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]);
300 newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]);
301 newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]);
302 //set the mode so that dragging will update the next and previous locations
303 this._editMode = this.EDIT_PREV_NEXT;
304 }
305 } //if we have not yet created a canvas for this path
284 306
285 //the selected subpath has a canvas, so test within that canvas' space 307 //the selected subpath has a canvas, so test within that canvas' space
286 else 308 else
@@ -454,19 +476,18 @@ exports.PenTool = Montage.create(ShapeTool, {
454 else if (this._editMode & this.EDIT_PREV) { 476 else if (this._editMode & this.EDIT_PREV) {
455 localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorPos[0]); 477 localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorPos[0]);
456 selAnchor.translatePrev(localTranslation[0], localTranslation[1], localTranslation[2]); 478 selAnchor.translatePrev(localTranslation[0], localTranslation[1], localTranslation[2]);
457 479 if (!this._isAltDown){
458 //move the next point if Alt key is down to ensure relative angle between prev and next 480 //selAnchor.translateNextFromPrev(localTranslation[0], localTranslation[1], localTranslation[2]);
459 if (this._isAltDown) { 481 selAnchor.setNextFromPrev();
460 selAnchor.translateNextFromPrev(localTranslation[0], localTranslation[1], localTranslation[2]);
461 } 482 }
462 } 483 }
463 else if (this._editMode & this.EDIT_NEXT) { 484 else if (this._editMode & this.EDIT_NEXT) {
464 localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorPos[2]); 485 localTranslation = VecUtils.vecSubtract(3, localMousePos, selAnchorPos[2]);
465 selAnchor.translateNext(localTranslation[0], localTranslation[1], localTranslation[2]);
466
467 //move the prev point if Alt key is down to ensure relative angle between prev and next 486 //move the prev point if Alt key is down to ensure relative angle between prev and next
468 if (this._isAltDown) { 487 selAnchor.translateNext(localTranslation[0], localTranslation[1], localTranslation[2]);
469 selAnchor.translatePrevFromNext(localTranslation[0], localTranslation[1], localTranslation[2]); 488 if (!this._isAltDown){
489 //selAnchor.translatePrevFromNext(localTranslation[0], localTranslation[1], localTranslation[2]);
490 selAnchor.setPrevFromNext();
470 } 491 }
471 } 492 }
472 else if (this._editMode & this.EDIT_PREV_NEXT) { 493 else if (this._editMode & this.EDIT_PREV_NEXT) {
@@ -714,14 +735,24 @@ exports.PenTool = Montage.create(ShapeTool, {
714 this._isDrawing = false; 735 this._isDrawing = false;
715 this._editMode = this.EDIT_NONE; 736 this._editMode = this.EDIT_NONE;
716 737
738 //if we're not in edit_path mode and we closed the selected subpath, then we are going to start a new subpath, so we nullify the selected subpath
739 if (this._selectedSubpath.getIsClosed() && this._entryEditMode !== this.ENTRY_SELECT_PATH){
740 this._selectedSubpath = null;
741 }
742
717 if (this._selectedSubpath){ 743 if (this._selectedSubpath){
718 this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas 744 this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas
745 }else{
746 //clear the canvas
747 this.application.ninja.stage.clearDrawingCanvas();
719 } 748 }
720 749
721 if (!this._trackMouseMoveWhenUp){ 750 if (!this._trackMouseMoveWhenUp){
722 NJevent("disableStageMove"); 751 NJevent("disableStageMove");
723 } 752 }
724 this._hoveredAnchorIndex = -1; 753 this._hoveredAnchorIndex = -1;
754
755
725 } 756 }
726 }, 757 },
727 758
@@ -1255,10 +1286,45 @@ exports.PenTool = Montage.create(ShapeTool, {
1255 } //value: function() { 1286 } //value: function() {
1256 }, //DrawSubpathAnchors { 1287 }, //DrawSubpathAnchors {
1257 1288
1289 deselectPenTool:{
1290 value: function() {
1291 this._selectedSubpath = null;
1292 this._selectedSubpathCanvas = null;
1293 this._selectedSubpathPlaneMat = null;
1294 this._snapTargetIndex = -1;
1295 }
1296 },
1297 //if the document is opened with the pen tool being active, we do the same thing as when configure(false) is called
1298 handleOpenDocument: {
1299 value: function() {
1300 this.deselectPenTool();
1301 //clear the canvas
1302 this.application.ninja.stage.clearDrawingCanvas();
1303 }
1304 },
1305 //if the document is switched with the pen tool being active, we do the same thing as when configure(false) is called
1306 handleSwitchDocument: {
1307 value: function() {
1308 this.deselectPenTool();
1309 //clear the canvas
1310 this.application.ninja.stage.clearDrawingCanvas();
1311 }
1312 },
1313 //if the document is closed with the pen tool being active, we do the same thing as when configure(false) is called
1314 handleCloseDocument: {
1315 value: function() {
1316 this.deselectPenTool();
1317 //clear the canvas
1318 this.application.ninja.stage.clearDrawingCanvas();
1319 }
1320 },
1258 1321
1259 Configure: { 1322 Configure: {
1260 value: function (wasSelected) { 1323 value: function (wasSelected) {
1261 if (wasSelected) { 1324 if (wasSelected) {
1325 //first nullify any set values
1326 this.deselectPenTool();
1327
1262 defaultEventManager.addEventListener("resetPenTool", this, false); 1328 defaultEventManager.addEventListener("resetPenTool", this, false);
1263 this.application.ninja.elementMediator.deleteDelegate = this; 1329 this.application.ninja.elementMediator.deleteDelegate = this;
1264 this.application.ninja.stage.drawingCanvas.style.cursor = //"auto"; 1330 this.application.ninja.stage.drawingCanvas.style.cursor = //"auto";
@@ -1312,17 +1378,21 @@ exports.PenTool = Montage.create(ShapeTool, {
1312 if (this._trackMouseMoveWhenUp){ 1378 if (this._trackMouseMoveWhenUp){
1313 NJevent("enableStageMove"); 1379 NJevent("enableStageMove");
1314 } 1380 }
1381 this.eventManager.addEventListener("openDocument", this, false);
1382 this.eventManager.addEventListener("switchDocument", this, false);
1383 this.eventManager.addEventListener("closeDocument", this, false);
1315 } //if the pen tool was selected 1384 } //if the pen tool was selected
1316 else { 1385 else {
1317 if (this._trackMouseMoveWhenUp){ 1386 if (this._trackMouseMoveWhenUp){
1318 NJevent("disableStageMove"); 1387 NJevent("disableStageMove");
1319 } 1388 }
1320 this._selectedSubpath = null; 1389 this.deselectPenTool();
1321 this._selectedSubpathCanvas = null;
1322 this._selectedSubpathPlaneMat = null;
1323 this._snapTargetIndex = -1;
1324 defaultEventManager.removeEventListener("resetPenTool", this, false); 1390 defaultEventManager.removeEventListener("resetPenTool", this, false);
1325 this.application.ninja.elementMediator.deleteDelegate = null; 1391 this.application.ninja.elementMediator.deleteDelegate = null;
1392
1393 this.eventManager.removeEventListener("openDocument", this, false);
1394 this.eventManager.removeEventListener("switchDocument", this, false);
1395 this.eventManager.removeEventListener("closeDocument", this, false);
1326 } //if the pen tool was de-selected 1396 } //if the pen tool was de-selected
1327 } 1397 }
1328 }, 1398 },
@@ -1331,38 +1401,57 @@ exports.PenTool = Montage.create(ShapeTool, {
1331 value: function(event){ 1401 value: function(event){
1332 //clear the selected subpath...the only new additions to this function w.r.t. ToolBase 1402 //clear the selected subpath...the only new additions to this function w.r.t. ToolBase
1333 if (this._selectedSubpath){ 1403 if (this._selectedSubpath){
1404 var removeSelectedSubpathCanvas = false;
1405 var removeSelectedSubpath = true; //this is applicable only if the subpath canvas is to be removed
1334 if (this._selectedSubpath.getSelectedAnchorIndex()>=0){ 1406 if (this._selectedSubpath.getSelectedAnchorIndex()>=0){
1335 this._hoveredAnchorIndex=-1; 1407 this._hoveredAnchorIndex=-1;
1336 this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 1408 this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex());
1337 this._selectedSubpath.createSamples(false); 1409 this._selectedSubpath.createSamples(false);
1338 //clear the canvas 1410 //clear the canvas
1339 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); 1411 this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas();
1412
1340 this.PrepareSelectedSubpathForRendering(); 1413 this.PrepareSelectedSubpathForRendering();
1341 this.DrawSubpathAnchors(this._selectedSubpath); 1414 this.DrawSubpathAnchors(this._selectedSubpath);