diff options
author | Valerio Virgillito | 2012-06-06 17:04:34 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-06-06 17:04:34 -0700 |
commit | 6442dcc0cc4088d28558a9c121c6a91cba3ff078 (patch) | |
tree | 8f2f2db6097104e44c8d87e11466d1f3124c7f3a /js/tools | |
parent | 488ae8d98deb30009cb8b5b2da464fe52940050b (diff) | |
parent | 47e0e1f047e83b71c3f86812a45d33904201cc7a (diff) | |
download | ninja-6442dcc0cc4088d28558a9c121c6a91cba3ff078.tar.gz |
Merge branch 'refs/heads/master' into element-model-fixes
Conflicts:
js/tools/LineTool.js
js/tools/ShapeTool.js
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/tools')
-rwxr-xr-x | js/tools/FillTool.js | 1 | ||||
-rwxr-xr-x | js/tools/InkBottleTool.js | 1 | ||||
-rwxr-xr-x | js/tools/LineTool.js | 108 | ||||
-rwxr-xr-x | js/tools/SelectionTool.js | 2 | ||||
-rwxr-xr-x | js/tools/ShapeTool.js | 44 | ||||
-rwxr-xr-x | js/tools/TagTool.js | 12 | ||||
-rwxr-xr-x | js/tools/drawing-tool.js | 3 | ||||
-rwxr-xr-x | js/tools/modifier-tool-base.js | 2 |
8 files changed, 101 insertions, 72 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 56d03e81..40475908 100755 --- a/js/tools/LineTool.js +++ b/js/tools/LineTool.js | |||
@@ -54,38 +54,45 @@ 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 | |||
89 | var styles = document.application.njUtils.stylesFromDraw(canvas, w, h, this.drawData); | ||
90 | this.application.ninja.elementMediator.addElements(canvas, styles); | ||
70 | } else { | 91 | } else { |
71 | // else make the line's stroke fit inside the canvas by growing the canvas | 92 | canvas = this._targetedElement; |
72 | var theta = Math.atan(slope); | 93 | canvas.elementModel.controller = ShapesController; |
73 | xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta)); | 94 | if(!canvas.elementModel.shapeModel) { |
74 | yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta)); | 95 | 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 | |||
82 | var styles = document.application.njUtils.stylesFromDraw(canvas, w, h, drawData); | ||
83 | this.application.ninja.elementMediator.addElements(canvas, styles); | ||
84 | } else { | ||
85 | canvas = this._targetedElement; | ||
86 | canvas.elementModel.controller = ShapesController; | ||
87 | if(!canvas.elementModel.shapeModel) { | ||
88 | canvas.elementModel.shapeModel = Montage.create(ShapeModel); | ||
89 | } | 96 | } |
90 | } | 97 | } |
91 | } | 98 | } |
@@ -102,16 +109,18 @@ exports.LineTool = Montage.create(ShapeTool, { | |||
102 | 109 | ||
103 | onAddElements: { | 110 | onAddElements: { |
104 | value: function(el) { | 111 | value: function(el) { |
105 | var drawData, xAdj = 0, yAdj = 0, w, h, slope = this._getSlope(); | 112 | var xAdj = 0, yAdj = 0, w, h, slope = this._getSlope(); |
106 | 113 | ||
107 | if(drawData = this.getDrawingData()) { | 114 | if(this.drawData) { |
108 | // set the dimensions | 115 | // set the dimensions |
109 | w = ~~drawData.width; | 116 | w = Math.floor(this.drawData.width); |
110 | h = ~~drawData.height; | 117 | h = Math.floor(this.drawData.height); |
111 | if(slope === "horizontal") { | 118 | if(slope === "horizontal") { |
112 | h = Math.max(this._strokeSize, 1); | 119 | h = Math.max(this._strokeSize, 1); |
120 | w = Math.max(w, 1); | ||
113 | } else if(slope === "vertical") { | 121 | } else if(slope === "vertical") { |
114 | w = Math.max(this._strokeSize, 1); | 122 | w = Math.max(this._strokeSize, 1); |
123 | h = Math.max(h, 1); | ||
115 | } else { | 124 | } else { |
116 | // else make the line's stroke fit inside the canvas by growing the canvas | 125 | // else make the line's stroke fit inside the canvas by growing the canvas |
117 | var theta = Math.atan(slope); | 126 | var theta = Math.atan(slope); |
@@ -122,7 +131,7 @@ exports.LineTool = Montage.create(ShapeTool, { | |||
122 | h += ~~(yAdj*2); | 131 | h += ~~(yAdj*2); |
123 | } | 132 | } |
124 | 133 | ||
125 | this.RenderShape(w, h, drawData.planeMat, drawData.midPt, el, slope, xAdj, yAdj); | 134 | this.RenderShape(w, h, this.drawData.planeMat, this.drawData.midPt, el, slope, xAdj, yAdj); |
126 | } | 135 | } |
127 | } | 136 | } |
128 | }, | 137 | }, |
@@ -131,28 +140,31 @@ exports.LineTool = Montage.create(ShapeTool, { | |||
131 | value: function() { | 140 | value: function() { |
132 | var hitRec0 = this._mouseDownHitRec, | 141 | var hitRec0 = this._mouseDownHitRec, |
133 | hitRec1 = this._mouseUpHitRec, | 142 | hitRec1 = this._mouseUpHitRec, |
134 | slope; | 143 | slope, |
144 | dx, | ||
145 | dy; | ||
135 | 146 | ||
136 | if (hitRec0 && hitRec1) | 147 | if (hitRec0 && hitRec1) { |
137 | { | ||
138 | var p0 = hitRec0.getLocalPoint(), | 148 | var p0 = hitRec0.getLocalPoint(), |
139 | p1 = hitRec1.getLocalPoint(); | 149 | p1 = hitRec1.getLocalPoint(); |
140 | 150 | ||
151 | dx = Math.floor(p0[0] - p1[0]); | ||
152 | dy = Math.floor(p0[1] - p1[1]); | ||
153 | |||
154 | if( (dx === 0) && (dy === 0) ) { | ||
155 | return null; | ||
156 | } | ||
157 | |||
141 | // check for divide by 0 for vertical line: | 158 | // check for divide by 0 for vertical line: |
142 | if( Math.round(p0[0] - p1[0]) === 0 ) | 159 | if(dx === 0) { |
143 | { | ||
144 | // vertical line | 160 | // vertical line |
145 | slope = "vertical"; | 161 | slope = "vertical"; |
146 | } | 162 | } else if (dy === 0) { |
147 | else if (Math.round(p0[1] - p1[1]) === 0 ) | ||
148 | { | ||
149 | // horizontal line | 163 | // horizontal line |
150 | slope = "horizontal"; | 164 | slope = "horizontal"; |
151 | } | 165 | } else { |
152 | else | ||
153 | { | ||
154 | // if slope is positive, draw a line from top-left to bottom-right | 166 | // if slope is positive, draw a line from top-left to bottom-right |
155 | slope = (p0[1] - p1[1])/(p0[0] - p1[0]); | 167 | slope = dy/dx; |
156 | } | 168 | } |
157 | } | 169 | } |
158 | 170 | ||
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 6956aea8..03ddc391 100755 --- a/js/tools/ShapeTool.js +++ b/js/tools/ShapeTool.js | |||
@@ -55,23 +55,29 @@ 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 | 63 | h = Math.floor(this.drawData.height); | |
64 | var styles = document.application.njUtils.stylesFromDraw(canvas, ~~drawData.width, ~~drawData.height, drawData); | 64 | |
65 | this.application.ninja.elementMediator.addElements(canvas, styles); | 65 | if( (w > 0) && (h > 0) ) { |
66 | <