aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xjs/tools/FillTool.js1
-rwxr-xr-xjs/tools/InkBottleTool.js1
-rwxr-xr-xjs/tools/LineTool.js110
-rwxr-xr-xjs/tools/SelectionTool.js2
-rwxr-xr-xjs/tools/ShapeTool.js46
-rwxr-xr-xjs/tools/TagTool.js12
-rwxr-xr-xjs/tools/drawing-tool.js3
-rwxr-xr-xjs/tools/modifier-tool-base.js2
8 files changed, 103 insertions, 74 deletions
diff --git a/js/tools/FillTool.js b/js/tools/FillTool.js
index 69807bc3..e08ec1da 100755
--- a/js/tools/FillTool.js
+++ b/js/tools/FillTool.js
@@ -70,6 +70,7 @@ exports.FillTool = Montage.create(ModifierToolBase, {
70 // Called by modifier tool base's HandleLeftButtonDown after updating selection (if needed) 70 // Called by modifier tool base's HandleLeftButtonDown after updating selection (if needed)
71 startDraw: { 71 startDraw: {
72 value: function(event) { 72 value: function(event) {
73 this.drawData = null;
73 this.isDrawing = true; 74 this.isDrawing = true;
74 75
75 if(this._canColor && this.application.ninja.selectedElements.length) { 76 if(this._canColor && this.application.ninja.selectedElements.length) {
diff --git a/js/tools/InkBottleTool.js b/js/tools/InkBottleTool.js
index dff0b0fa..c5640b10 100755
--- a/js/tools/InkBottleTool.js
+++ b/js/tools/InkBottleTool.js
@@ -65,6 +65,7 @@ exports.InkBottleTool = Montage.create(ModifierToolBase, {
65 // Called by modifier tool base's HandleLeftButtonDown after updating selection (if needed) 65 // Called by modifier tool base's HandleLeftButtonDown after updating selection (if needed)
66 startDraw: { 66 startDraw: {
67 value: function(event) { 67 value: function(event) {
68 this.drawData = null;
68 this.isDrawing = true; 69 this.isDrawing = true;
69 70
70 if(this._canColor && this.application.ninja.selectedElements.length) 71 if(this._canColor && this.application.ninja.selectedElements.length)
diff --git a/js/tools/LineTool.js b/js/tools/LineTool.js
index b2b48383..327d0054 100755
--- a/js/tools/LineTool.js
+++ b/js/tools/LineTool.js
@@ -54,39 +54,46 @@ exports.LineTool = Montage.create(ShapeTool, {
54 54
55 HandleLeftButtonUp: { 55 HandleLeftButtonUp: {
56 value: function (event) { 56 value: function (event) {
57 var slope = this._getSlope(), drawData = this.getDrawingData(); 57 var slope = this._getSlope(),
58 58 canvas,
59 if(drawData) { 59 xAdj = 0,
60 var canvas, xAdj = 0, yAdj = 0, w, h; 60 yAdj = 0,
61 if(!this._useExistingCanvas()) { 61 w,
62 if(drawData = this.getDrawingData()) { 62 h;
63 // set the dimensions 63
64 w = ~~drawData.width; 64 if(slope) {
65 h = ~~drawData.height; 65 this.drawData = this.getDrawingData();
66 if(slope === "horizontal") { 66 if(this.drawData) {
67 h = Math.max(this._strokeSize, 1); 67 w = Math.floor(this.drawData.width);
68 } else if(slope === "vertical") { 68 h = Math.floor(this.drawData.height);
69 w = Math.max(this._strokeSize, 1); 69 if(!this._useExistingCanvas()) {
70 // set the dimensions
71 if(slope === "horizontal") {
72 h = Math.max(this._strokeSize, 1);
73 w = Math.max(w, 1);
74 } else if(slope === "vertical") {
75 w = Math.max(this._strokeSize, 1);
76 h = Math.max(h, 1);
77 } else {
78 // else make the line's stroke fit inside the canvas by growing the canvas
79 var theta = Math.atan(slope);
80 xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta));
81 yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta));
82
83 w += ~~(xAdj*2);
84 h += ~~(yAdj*2);
85 }
86
87 canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument);
88 document.application.njUtils.createModelWithShape(canvas, "Line");
89
90 var styles = document.application.njUtils.stylesFromDraw(canvas, w, h, this.drawData);
91 this.application.ninja.elementMediator.addElements(canvas, styles);
70 } else { 92 } else {
71 // else make the line's stroke fit inside the canvas by growing the canvas 93 canvas = this._targetedElement;
72 var theta = Math.atan(slope); 94 canvas.elementModel.controller = ShapesController;
73 xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta)); 95 if(!canvas.elementModel.shapeModel) {
74 yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta)); 96 canvas.elementModel.shapeModel = Montage.create(ShapeModel);
75
76 w += ~~(xAdj*2);
77 h += ~~(yAdj*2);
78 }
79
80 canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument);
81 document.application.njUtils.createModelWithShape(canvas, "Line");
82
83 var styles = document.application.njUtils.stylesFromDraw(canvas, w, h, drawData);
84 this.application.ninja.elementMediator.addElements(canvas, styles);
85 } else {
86 canvas = this._targetedElement;
87 canvas.elementModel.controller = ShapesController;
88 if(!canvas.elementModel.shapeModel) {
89 canvas.elementModel.shapeModel = Montage.create(ShapeModel);
90 } 97 }
91 } 98 }
92 } 99 }
@@ -103,16 +110,18 @@ exports.LineTool = Montage.create(ShapeTool, {
103 110
104 onAddElements: { 111 onAddElements: {
105 value: function(el) { 112 value: function(el) {
106 var drawData, xAdj = 0, yAdj = 0, w, h, slope = this._getSlope(); 113 var xAdj = 0, yAdj = 0, w, h, slope = this._getSlope();
107 114
108 if(drawData = this.getDrawingData()) { 115 if(this.drawData) {
109 // set the dimensions 116 // set the dimensions
110 w = ~~drawData.width; 117 w = Math.floor(this.drawData.width);
111 h = ~~drawData.height; 118 h = Math.floor(this.drawData.height);
112 if(slope === "horizontal") { 119 if(slope === "horizontal") {
113 h = Math.max(this._strokeSize, 1); 120 h = Math.max(this._strokeSize, 1);
121 w = Math.max(w, 1);
114 } else if(slope === "vertical") { 122 } else if(slope === "vertical") {
115 w = Math.max(this._strokeSize, 1); 123 w = Math.max(this._strokeSize, 1);
124 h = Math.max(h, 1);
116 } else { 125 } else {
117 // else make the line's stroke fit inside the canvas by growing the canvas 126 // else make the line's stroke fit inside the canvas by growing the canvas
118 var theta = Math.atan(slope); 127 var theta = Math.atan(slope);
@@ -123,7 +132,7 @@ exports.LineTool = Montage.create(ShapeTool, {
123 h += ~~(yAdj*2); 132 h += ~~(yAdj*2);
124 } 133 }
125 134
126 this.RenderShape(w, h, drawData.planeMat, drawData.midPt, el, slope, xAdj, yAdj); 135 this.RenderShape(w, h, this.drawData.planeMat, this.drawData.midPt, el, slope, xAdj, yAdj);
127 } 136 }
128 } 137 }
129 }, 138 },
@@ -132,28 +141,31 @@ exports.LineTool = Montage.create(ShapeTool, {
132 value: function() { 141 value: function() {
133 var hitRec0 = this._mouseDownHitRec, 142 var hitRec0 = this._mouseDownHitRec,
134 hitRec1 = this._mouseUpHitRec, 143 hitRec1 = this._mouseUpHitRec,
135 slope; 144 slope,
145 dx,
146 dy;
136 147
137 if (hitRec0 && hitRec1) 148 if (hitRec0 && hitRec1) {
138 {
139 var p0 = hitRec0.getLocalPoint(), 149 var p0 = hitRec0.getLocalPoint(),
140 p1 = hitRec1.getLocalPoint(); 150 p1 = hitRec1.getLocalPoint();
141 151
152 dx = Math.floor(p0[0] - p1[0]);
153 dy = Math.floor(p0[1] - p1[1]);
154
155 if( (dx === 0) && (dy === 0) ) {
156 return null;
157 }
158
142 // check for divide by 0 for vertical line: 159 // check for divide by 0 for vertical line:
143 if( Math.round(p0[0] - p1[0]) === 0 ) 160 if(dx === 0) {
144 {
145 // vertical line 161 // vertical line
146 slope = "vertical"; 162 slope = "vertical";
147 } 163 } else if (dy === 0) {
148 else if (Math.round(p0[1] - p1[1]) === 0 )
149 {
150 // horizontal line 164 // horizontal line
151 slope = "horizontal"; 165 slope = "horizontal";
152 } 166 } else {
153 else
154 {
155 // if slope is positive, draw a line from top-left to bottom-right 167 // if slope is positive, draw a line from top-left to bottom-right
156 slope = (p0[1] - p1[1])/(p0[0] - p1[0]); 168 slope = dy/dx;
157 } 169 }
158 } 170 }
159 171
diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js
index 7b72a857..ed92b893 100755
--- a/js/tools/SelectionTool.js
+++ b/js/tools/SelectionTool.js
@@ -49,6 +49,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
49 49
50 startDraw: { 50 startDraw: {
51 value: function(event) { 51 value: function(event) {
52 this.drawData = null;
53
52 if(!this.application.ninja.selectedElements.length) 54 if(!this.application.ninja.selectedElements.length)
53 { 55 {
54 this._isSelecting = true; 56 this._isSelecting = true;
diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js
index 367ab78d..8886285d 100755
--- a/js/tools/ShapeTool.js
+++ b/js/tools/ShapeTool.js
@@ -55,24 +55,30 @@ exports.ShapeTool = Montage.create(DrawingTool, {
55 55
56 HandleLeftButtonUp: { 56 HandleLeftButtonUp: {
57 value: function (event) { 57 value: function (event) {
58 var canvas, drawData = this.getDrawingData(); 58 var canvas, w, h;
59 59 this.drawData = this.getDrawingData();
60 if(drawData) { 60
61 if(!this._useExistingCanvas()) { 61 if(this.drawData) {
62 canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument); 62 w = Math.floor(this.drawData.width);
63 document.application.njUtils.createModelWithShape(canvas); 63 h = Math.floor(this.drawData.height);
64 64
65 var styles = document.application.njUtils.stylesFromDraw(canvas, ~~drawData.width, ~~drawData.height, drawData); 65 if( (w > 0) && (h > 0) ) {
66 this.application.ninja.elementMediator.addElements(canvas, styles); 66 if(!this._useExistingCanvas()) {
67 } else { 67 canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument);
68 canvas = this._targetedEle