aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools')
-rw-r--r--js/tools/BrushTool.js2
-rwxr-xr-xjs/tools/LineTool.js111
-rwxr-xr-xjs/tools/PenTool.js12
-rwxr-xr-xjs/tools/Rotate3DToolBase.js4
-rwxr-xr-xjs/tools/SelectionTool.js34
-rwxr-xr-xjs/tools/ShapeTool.js37
-rwxr-xr-xjs/tools/TagTool.js6
-rwxr-xr-xjs/tools/TextTool.js4
-rwxr-xr-xjs/tools/Translate3DToolBase.js2
-rwxr-xr-xjs/tools/modifier-tool-base.js2
10 files changed, 110 insertions, 104 deletions
diff --git a/js/tools/BrushTool.js b/js/tools/BrushTool.js
index f7f0e4bf..2171d2c6 100644
--- a/js/tools/BrushTool.js
+++ b/js/tools/BrushTool.js
@@ -306,7 +306,7 @@ exports.BrushTool = Montage.create(ShapeTool, {
306 if (!canvas) { 306 if (!canvas) {
307 var newCanvas = NJUtils.makeNJElement("canvas", "Brushstroke", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); 307 var newCanvas = NJUtils.makeNJElement("canvas", "Brushstroke", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true);
308 var elementModel = TagTool.makeElement(w, h, planeMat, midPt, newCanvas); 308 var elementModel = TagTool.makeElement(w, h, planeMat, midPt, newCanvas);
309 ElementMediator.addElement(newCanvas, elementModel.data, true); 309 ElementMediator.addElements(newCanvas, elementModel.data, false);
310 310
311 // create all the GL stuff 311 // create all the GL stuff
312 var world = this.getGLWorld(newCanvas, this._useWebGL); 312 var world = this.getGLWorld(newCanvas, this._useWebGL);
diff --git a/js/tools/LineTool.js b/js/tools/LineTool.js
index a43d4fb6..e6e05b04 100755
--- a/js/tools/LineTool.js
+++ b/js/tools/LineTool.js
@@ -7,7 +7,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
7var Montage = require("montage/core/core").Montage, 7var Montage = require("montage/core/core").Montage,
8 ShapeTool = require("js/tools/ShapeTool").ShapeTool, 8 ShapeTool = require("js/tools/ShapeTool").ShapeTool,
9 DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase, 9 DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase,
10 ElementMediator = require("js/mediators/element-mediator").ElementMediator,
11 NJUtils = require("js/lib/NJUtils").NJUtils, 10 NJUtils = require("js/lib/NJUtils").NJUtils,
12 TagTool = require("js/tools/TagTool").TagTool, 11 TagTool = require("js/tools/TagTool").TagTool,
13 ShapesController = require("js/controllers/elements/shapes-controller").ShapesController, 12 ShapesController = require("js/controllers/elements/shapes-controller").ShapesController,
@@ -53,59 +52,43 @@ exports.LineTool = Montage.create(ShapeTool, {
53 } 52 }
54 }, 53 },
55 54
56 HandleLeftButtonUp: 55 HandleLeftButtonUp: {
57 { 56 value: function (event) {
58 value: function (event) 57 var slope = this._getSlope(), drawData = this.getDrawingData();
59 {
60 var slope = this._getSlope(),
61 drawData = this.getDrawingData();
62 58
63 if(drawData) { 59 if(drawData) {
64 var canvas, 60 var canvas, xAdj = 0, yAdj = 0, w, h;
65 xAdj = 0, 61 if(!this._useExistingCanvas()) {
66 yAdj = 0, 62 if(drawData = this.getDrawingData()) {
67 w = ~~drawData.width, 63 // set the dimensions
68 h = ~~drawData.height; 64 w = ~~drawData.width;
69 if(!this._useExistingCanvas()) 65 h = ~~drawData.height;
70 { 66 if(slope === "horizontal") {
71 // set the dimensions 67 h = Math.max(this._strokeSize, 1);
72 if(slope === "horizontal") 68 } else if(slope === "vertical") {
73 { 69 w = Math.max(this._strokeSize, 1);
74 h = Math.max(this._strokeSize, 1); 70 } else {
75 } 71 // else make the line's stroke fit inside the canvas by growing the canvas
76 else if(slope === "vertical") 72 var theta = Math.atan(slope);
77 { 73 xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta));
78 w = Math.max(this._strokeSize, 1); 74 yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta));
79 } 75
80 else 76 w += ~~(xAdj*2);
81 { 77 h += ~~(yAdj*2);
82 // else make the line's stroke fit inside the canvas by growing the canvas 78 }
83 var theta = Math.atan(slope); 79
84 xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta)); 80 canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true);
85 yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta)); 81 var elementModel = TagTool.makeElement(w, h, drawData.planeMat, drawData.midPt, canvas);
86 82 canvas.elementModel.isShape = true;
87 w += ~~(xAdj*2); 83 this.application.ninja.elementMediator.addElements(canvas, elementModel.data);
88 h += ~~(yAdj*2); 84 } else {
89 } 85 canvas = this._targetedElement;
90 86 canvas.elementModel.controller = ShapesController;
91 canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); 87 if(!canvas.elementModel.shapeModel) {
92 var elementModel = TagTool.makeElement(w, h, drawData.planeMat, drawData.midPt, canvas); 88 canvas.elementModel.shapeModel = Montage.create(ShapeModel);
93 89 }
94 ElementMediator.addElement(canvas, elementModel.data, true);
95 canvas.elementModel.isShape = true;
96 }
97 else
98 {
99 canvas = this._targetedElement;
100 canvas.elementModel.controller = ShapesController;
101 if(!canvas.elementModel.shapeModel)
102 {
103 canvas.elementModel.shapeModel = Montage.create(ShapeModel);
104 } 90 }
105 } 91 }
106 this.RenderShape(w, h, drawData.planeMat, drawData.midPt,
107 canvas, slope, xAdj, yAdj);
108 NJevent("elementAdded", canvas);
109 } 92 }
110 93
111 this.endDraw(event); 94 this.endDraw(event);
@@ -113,11 +96,37 @@ exports.LineTool = Montage.create(ShapeTool, {
113 this._isDrawing = false; 96 this._isDrawing = false;
114 this._hasDraw=false; 97 this._hasDraw=false;
115 98
116
117 this.DrawHandles(); 99 this.DrawHandles();
118 } 100 }
119 }, 101 },
120 102
103 onAddElements: {
104 value: function(el) {
105 var drawData, xAdj = 0, yAdj = 0, w, h, slope = this._getSlope();
106
107 if(drawData = this.getDrawingData()) {
108 // set the dimensions
109 w = ~~drawData.width;
110 h = ~~drawData.height;
111 if(slope === "horizontal") {
112 h = Math.max(this._strokeSize, 1);
113 } else if(slope === "vertical") {
114 w = Math.max(this._strokeSize, 1);
115 } else {
116 // else make the line's stroke fit inside the canvas by growing the canvas
117 var theta = Math.atan(slope);
118 xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta));
119 yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta));
120
121 w += ~~(xAdj*2);
122 h += ~~(yAdj*2);
123 }
124
125 this.RenderShape(w, h, drawData.planeMat, drawData.midPt, el, slope, xAdj, yAdj);
126 }
127 }
128 },
129
121 _getSlope: { 130 _getSlope: {
122 value: function() { 131 value: function() {
123 var hitRec0 = this._mouseDownHitRec, 132 var hitRec0 = this._mouseDownHitRec,
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index 779b7f16..4a16a491 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -585,7 +585,7 @@ exports.PenTool = Montage.create(ShapeTool, {
585 var newCanvas = null; 585 var newCanvas = null;
586 newCanvas = NJUtils.makeNJElement("canvas", "Subpath", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); 586 newCanvas = NJUtils.makeNJElement("canvas", "Subpath", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true);
587 var elementModel = TagTool.makeElement(parseInt(w), parseInt(h), planeMat, midPt, newCanvas); 587 var elementModel = TagTool.makeElement(parseInt(w), parseInt(h), planeMat, midPt, newCanvas);
588 ElementMediator.addElement(newCanvas, elementModel.data, true); 588 ElementMediator.addElements(newCanvas, elementModel.data, false);
589 589
590 // create all the GL stuff 590 // create all the GL stuff
591 var world = this.getGLWorld(newCanvas, this._useWebGL);//this.options.use3D);//this.CreateGLWorld(planeMat, midPt, newCanvas, this._useWebGL);//fillMaterial, strokeMaterial); 591 var world = this.getGLWorld(newCanvas, this._useWebGL);//this.options.use3D);//this.CreateGLWorld(planeMat, midPt, newCanvas, this._useWebGL);//fillMaterial, strokeMaterial);
@@ -978,11 +978,11 @@ exports.PenTool = Montage.create(ShapeTool, {
978 } 978 }
979 else{ 979 else{
980 for (var i=0;i<this.application.ninja.selectedElements.length;i++){ 980 for (var i=0;i<this.application.ninja.selectedElements.length;i++){
981 var element = this.application.ninja.selectedElements[i]._element; 981 var element = this.application.ninja.selectedElements[i]
982 console.log("Entered pen tool, had selected: " + element.elementModel.selection); 982 console.log("Entered pen tool, had selected: " + element.elementModel.selection);
983 if (element.elementModel.selection === 'Subpath'){ //TODO what to do if the canvas is drawn by tag tool? 983 if (element.elementModel.selection === 'Subpath'){ //TODO what to do if the canvas is drawn by tag tool?
984 //set the pen canvas to be the selected canvas 984 //set the pen canvas to be the selected canvas
985 this._penCanvas = this.application.ninja.selectedElements[i]._element; 985 this._penCanvas = this.application.ninja.selectedElements[i];
986 986
987 // get the subpath for this world 987 // get the subpath for this world
988 this._selectedSubpath = null; 988 this._selectedSubpath = null;
@@ -1057,7 +1057,7 @@ exports.PenTool = Montage.create(ShapeTool, {
1057 var els = []; 1057 var els = [];
1058 ElementController.removeElement(this._penCanvas); 1058 ElementController.removeElement(this._penCanvas);
1059 els.push(this._penCanvas); 1059 els.push(this._penCanvas);
1060 NJevent( "deleteSelection", els ); 1060 NJevent( "elementsRemoved", els );
1061 this._penCanvas = null; 1061 this._penCanvas = null;
1062 } 1062 }
1063 } 1063 }
@@ -1073,9 +1073,9 @@ exports.PenTool = Montage.create(ShapeTool, {
1073 els.push(this.application.ninja.selectedElements[i]); 1073 els.push(this.application.ninja.selectedElements[i]);
1074 } 1074 }
1075 for(i=0; i<len; i++) { 1075 for(i=0; i<len; i++) {
1076 ElementController.removeElement(els[i]._element); 1076 ElementController.removeElement(els[i]);
1077 } 1077 }
1078 NJevent( "deleteSelection", els ); 1078 NJevent( "elementsRemoved", els );
1079 1079
1080 //clear out the selected path if it exists 1080 //clear out the selected path if it exists
1081 if (this._selectedSubpath) { 1081 if (this._selectedSubpath) {
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js
index b04e8b0a..eb2cdba4 100755
--- a/js/tools/Rotate3DToolBase.js
+++ b/js/tools/Rotate3DToolBase.js
@@ -262,7 +262,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
262 { 262 {
263 if(len === 1) 263 if(len === 1)
264 { 264 {
265 this.target = this.application.ninja.selectedElements[0]<