aboutsummaryrefslogtreecommitdiff
path: root/js/tools/PenTool.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/PenTool.js')
-rwxr-xr-xjs/tools/PenTool.js28
1 files changed, 16 insertions, 12 deletions
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index 4b4fd227..a44438ac 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -302,6 +302,7 @@ exports.PenTool = Montage.create(ShapeTool, {
302 HandleLeftButtonDown: 302 HandleLeftButtonDown:
303 { 303 {
304 value: function (event) { 304 value: function (event) {
305 var newAnchor;
305 //ignore any right or middle clicks 306 //ignore any right or middle clicks
306 if (event.button !== 0) { 307 if (event.button !== 0) {
307 //todo NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) 308 //todo NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2)
@@ -427,7 +428,7 @@ exports.PenTool = Montage.create(ShapeTool, {
427 428
428 } else { 429 } else {
429 this._selectedSubpath.addAnchor(new AnchorPoint()); 430 this._selectedSubpath.addAnchor(new AnchorPoint());
430 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 431 newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
431 newAnchor.setPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]); 432 newAnchor.setPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]);
432 newAnchor.setPrevPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]); 433 newAnchor.setPrevPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]);
433 newAnchor.setNextPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]); 434 newAnchor.setNextPos(stageWorldMousePos[0], stageWorldMousePos[1], stageWorldMousePos[2]);
@@ -489,7 +490,7 @@ exports.PenTool = Montage.create(ShapeTool, {
489 if (numAnchors>1 && !this._selectedSubpath.getIsClosed() && this._selectedSubpath.getSelectedAnchorIndex()===0 && prevSelectedAnchorIndex === numAnchors-1){ 490 if (numAnchors>1 && !this._selectedSubpath.getIsClosed() && this._selectedSubpath.getSelectedAnchorIndex()===0 && prevSelectedAnchorIndex === numAnchors-1){
490 //insert an anchor temporarily that will get removed in the mouse up handler 491 //insert an anchor temporarily that will get removed in the mouse up handler
491 this._selectedSubpath.addAnchor(new AnchorPoint()); 492 this._selectedSubpath.addAnchor(new AnchorPoint());
492 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 493 newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
493 newAnchor.setPos(localMousePos[0], localMousePos[1], localMousePos[2]); 494 newAnchor.setPos(localMousePos[0], localMousePos[1], localMousePos[2]);
494 newAnchor.setPrevPos(localMousePos[0], localMousePos[1], localMousePos[2]); 495 newAnchor.setPrevPos(localMousePos[0], localMousePos[1], localMousePos[2]);
495 newAnchor.setNextPos(localMousePos[0], localMousePos[1], localMousePos[2]); 496 newAnchor.setNextPos(localMousePos[0], localMousePos[1], localMousePos[2]);
@@ -534,7 +535,7 @@ exports.PenTool = Montage.create(ShapeTool, {
534 ) { 535 ) {
535 if (!this._selectedSubpath.getIsClosed()) { //todo this test is probably unnecessary, but doing it to be safe 536 if (!this._selectedSubpath.getIsClosed()) { //todo this test is probably unnecessary, but doing it to be safe
536 this._selectedSubpath.addAnchor(new AnchorPoint()); 537 this._selectedSubpath.addAnchor(new AnchorPoint());
537 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 538 newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
538 539
539 newAnchor.setPos(localMousePos[0], localMousePos[1], localMousePos[2]); 540 newAnchor.setPos(localMousePos[0], localMousePos[1], localMousePos[2]);
540 newAnchor.setPrevPos(localMousePos[0], localMousePos[1], localMousePos[2]); 541 newAnchor.setPrevPos(localMousePos[0], localMousePos[1], localMousePos[2]);
@@ -564,6 +565,7 @@ exports.PenTool = Montage.create(ShapeTool, {
564 HandleMouseMove: 565 HandleMouseMove:
565 { 566 {
566 value: function (event) { 567 value: function (event) {
568 var cursor;
567 //ignore any right or middle clicks 569 //ignore any right or middle clicks
568 if (event.button !== 0) { 570 if (event.button !== 0) {
569 //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) 571 //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2)
@@ -678,7 +680,7 @@ exports.PenTool = Montage.create(ShapeTool, {
678 { //the anchor was hit 680 { //the anchor was hit
679 this._hoveredAnchorIndex = selAnchorAndParamAndCode[0]; 681 this._hoveredAnchorIndex = selAnchorAndParamAndCode[0];
680 var lastAnchorIndex = this._selectedSubpath.getNumAnchors()-1; 682 var lastAnchorIndex = this._selectedSubpath.getNumAnchors()-1;
681 var cursor; 683
682 if (this._subtool===this.SUBTOOL_NONE){ 684 if (this._subtool===this.SUBTOOL_NONE){
683 cursor = "url('images/cursors/penCursors/Pen_anchorSelect.png') 5 1, default"; 685 cursor = "url('images/cursors/penCursors/Pen_anchorSelect.png') 5 1, default";
684 if (this._selectedSubpath.getIsClosed()===false){ 686 if (this._selectedSubpath.getIsClosed()===false){
@@ -697,7 +699,7 @@ exports.PenTool = Montage.create(ShapeTool, {
697 } else if (selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_PATH) { 699 } else if (selAnchorAndParamAndCode[2] & this._selectedSubpath.SEL_PATH) {
698 //change the cursor only if we're not in pen-minus subtool 700 //change the cursor only if we're not in pen-minus subtool
699 if (this._subtool!==this.SUBTOOL_PENMINUS){ 701 if (this._subtool!==this.SUBTOOL_PENMINUS){
700 var cursor = "url('images/cursors/penCursors/Pen_plus.png') 5 1, default"; 702 cursor = "url('images/cursors/penCursors/Pen_plus.png') 5 1, default";
701 this.application.ninja.stage.drawingCanvas.style.cursor = cursor; 703 this.application.ninja.stage.drawingCanvas.style.cursor = cursor;
702 } 704 }
703 } 705 }
@@ -735,6 +737,8 @@ exports.PenTool = Montage.create(ShapeTool, {
735 return; 737 return;
736 } 738 }
737 739
740 var world, subpath;
741
738 w = Math.round(w); 742 w = Math.round(w);
739 h = Math.round(h); 743 h = Math.round(h);
740 var left = Math.round(midPt[0] - 0.5 * w); 744 var left = Math.round(midPt[0] - 0.5 * w);
@@ -743,16 +747,16 @@ exports.PenTool = Montage.create(ShapeTool, {
743 if (!canvas) { 747 if (!canvas) {
744 this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the new canvas 748 this._doesSelectionChangeNeedHandling = false; //this will ignore the selection change event triggered by the new canvas
745 var newCanvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument); 749 var newCanvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument);
746 var styles = document.application.njUtils.stylesFromDraw(newCanvas, parseInt(w), parseInt(h), {midPt: midPt, planeMat: planeMat}); 750 var styles = document.application.njUtils.stylesFromDraw(newCanvas, parseInt(w, 10), parseInt(h, 10), {midPt: midPt, planeMat: planeMat});
747 this.application.ninja.elementMediator.addElements(newCanvas, styles, false); 751 this.application.ninja.elementMediator.addElements(newCanvas, styles, false);
748 752
749 // create all the GL stuff 753 // create all the GL stuff
750 var world = this.getGLWorld(newCanvas, this._useWebGL);//this.options.use3D);//this.CreateGLWorld(planeMat, midPt, newCanvas, this._useWebGL);//fillMaterial, strokeMaterial); 754 world = this.getGLWorld(newCanvas, this._useWebGL);//this.options.use3D);//this.CreateGLWorld(planeMat, midPt, newCanvas, this._useWebGL);//fillMaterial, strokeMaterial);
751 //store a reference to this newly created canvas 755 //store a reference to this newly created canvas
752 this._selectedSubpathCanvas = newCanvas; 756 this._selectedSubpathCanvas = newCanvas;
753 this._selectedSubpathPlaneMat = ElementMediator.getMatrix(newCanvas); 757 this._selectedSubpathPlaneMat = ElementMediator.getMatrix(newCanvas);
754 758
755 var subpath = this._selectedSubpath; //new GLSubpath(); 759 subpath = this._selectedSubpath; //new GLSubpath();
756 subpath.setWorld(world); 760 subpath.setWorld(world);
757 subpath.setCanvas(newCanvas); 761 subpath.setCanvas(newCanvas);
758 762
@@ -791,7 +795,7 @@ exports.PenTool = Montage.create(ShapeTool, {
791 } //if (!canvas) { 795 } //if (!canvas) {
792 else { 796 else {
793 797
794 var world = null; 798 world = null;
795 if (canvas.elementModel.shapeModel && canvas.elementModel.shapeModel.GLWorld) { 799 if (canvas.elementModel.shapeModel && canvas.elementModel.shapeModel.GLWorld) {
796 world = canvas.elementModel.shapeModel.GLWorld; 800 world = canvas.elementModel.shapeModel.GLWorld;
797 } else { 801 } else {
@@ -815,7 +819,7 @@ exports.PenTool = Montage.create(ShapeTool, {
815 } 819 }
816 } 820 }
817 821
818 var subpath = this._selectedSubpath; 822 subpath = this._selectedSubpath;
819 823
820 subpath.setDrawingTool(this); 824 subpath.setDrawingTool(this);
821 subpath.setWorld(world); 825 subpath.setWorld(world);
@@ -1358,7 +1362,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1358 ctx.lineWidth = 1; 1362 ctx.lineWidth = 1;
1359 var defFill = "#FFFFFF"; 1363 var defFill = "#FFFFFF";
1360 var defStroke = "green"; 1364 var defStroke = "green";
1361 var selHandleFill = "#000000" 1365 var selHandleFill = "#000000";
1362 1366
1363 ctx.strokeStyle = defStroke; 1367 ctx.strokeStyle = defStroke;
1364 ctx.fillStyle = defFill; 1368 ctx.fillStyle = defFill;
@@ -1608,7 +1612,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1608 var world = ElementMediator.getShapeProperty(this._selectedSubpathCanvas, "GLWorld"); 1612 var world = ElementMediator.getShapeProperty(this._selectedSubpathCanvas, "GLWorld");
1609 if (world === null){ 1613 if (world === null){
1610 throw("Pen tool handleSelectionChange did not work correctly"); 1614 throw("Pen tool handleSelectionChange did not work correctly");
1611 break; //something bad happened //TODO handle this better 1615 //something bad happened //TODO handle this better
1612 } 1616 }
1613 1617
1614 //TODO assuming that we want the first subpath in this world...fix this! 1618 //TODO assuming that we want the first subpath in this world...fix this!