diff options
-rwxr-xr-x | js/tools/EyedropperTool.js | 110 |
1 files changed, 64 insertions, 46 deletions
diff --git a/js/tools/EyedropperTool.js b/js/tools/EyedropperTool.js index 710c96ef..11c15158 100755 --- a/js/tools/EyedropperTool.js +++ b/js/tools/EyedropperTool.js | |||
@@ -71,7 +71,7 @@ exports.EyedropperTool = Montage.create(toolBase, { | |||
71 | this._escape = false; | 71 | this._escape = false; |
72 | } | 72 | } |
73 | 73 | ||
74 | this._updateColor(this._color); | 74 | this._updateColor(this._color, true); |
75 | 75 | ||
76 | this._color = null; | 76 | this._color = null; |
77 | 77 | ||
@@ -86,18 +86,7 @@ exports.EyedropperTool = Montage.create(toolBase, { | |||
86 | if(this._color && this._color.value) | 86 | if(this._color && this._color.value) |
87 | { | 87 | { |
88 | var color = this.application.ninja.colorController.getColorObjFromCss(this._previousColor); | 88 | var color = this.application.ninja.colorController.getColorObjFromCss(this._previousColor); |
89 | 89 | this._updateColor(color, true); | |
90 | if (color && color.value) { | ||
91 | color.value.wasSetByCode = true; | ||
92 | color.value.type = 'change'; | ||
93 | if (color.value.a) { | ||
94 | this.application.ninja.colorController.colorModel.alpha = {value: color.value.a, | ||
95 | wasSetByCode: true, | ||
96 | type: 'change'}; | ||
97 | } | ||
98 | this.application.ninja.colorController.colorModel[color.mode] = color.value; | ||
99 | this._color = null; | ||
100 | } | ||
101 | } | 90 | } |
102 | this._escape = true; | 91 | this._escape = true; |
103 | } | 92 | } |
@@ -151,21 +140,11 @@ exports.EyedropperTool = Montage.create(toolBase, { | |||
151 | } | 140 | } |
152 | else | 141 | else |
153 | { | 142 | { |
154 | color = c; | 143 | color = this.application.ninja.colorController.getColorObjFromCss(c.color.css); |
155 | } | 144 | } |
156 | } | 145 | } |
157 | 146 | ||
158 | if (color && color.value) { | 147 | this._updateColor(color, false); |
159 | color.value.wasSetByCode = true; | ||
160 | color.value.type = 'changing'; | ||
161 | if (color.value.a) { | ||
162 | this.application.ninja.colorController.colorModel.alpha = {value: color.value.a, | ||
163 | wasSetByCode: true, | ||
164 | type: 'changing'}; | ||
165 | } | ||
166 | this.application.ninja.colorController.colorModel[color.mode] = color.value; | ||
167 | this._color = color; | ||
168 | } | ||
169 | } | 148 | } |
170 | else | 149 | else |
171 | { | 150 | { |
@@ -177,32 +156,75 @@ exports.EyedropperTool = Montage.create(toolBase, { | |||
177 | }, | 156 | }, |
178 | 157 | ||
179 | _updateColor: { | 158 | _updateColor: { |
180 | value: function(color) { | 159 | value: function(color, updateColorToolBar) { |
181 | if (color && color.value) { | 160 | var eventType = "changing"; |
182 | var input = this.application.ninja.colorController.colorModel.input; | 161 | if(updateColorToolBar) |
162 | { | ||
163 | eventType = "change"; | ||
164 | if (color && color.value) | ||
165 | { | ||
166 | var input = this.application.ninja.colorController.colorModel.input; | ||
167 | |||
168 | if(input === "fill") | ||
169 | { | ||
170 | this.application.ninja.colorController.colorToolbar.fill_btn.color(color.mode, color.value); | ||
171 | } | ||
172 | else | ||
173 | { | ||
174 | this.application.ninja.colorController.colorToolbar.stroke_btn.color(color.mode, color.value); | ||
175 | } | ||
176 | |||
177 | // Updating color chips will set the input type to "chip", so set it back here. | ||
178 | this.application.ninja.colorController.colorModel.input = input; | ||
179 | } | ||
180 | } | ||
181 | |||
182 | if(color) | ||
183 | { | ||
184 | if(color.color) | ||
185 | { | ||
186 | color.color.wasSetByCode = true; | ||
187 | color.color.type = eventType; | ||
188 | } | ||
183 | 189 | ||
184 | if(input === "fill") | 190 | if(color.mode === "gradient") |
185 | { | 191 | { |
186 | this.application.ninja.colorController.colorToolbar.fill_btn.color(color.mode, color.value); | 192 | this.application.ninja.colorController.colorModel["gradient"] = |
193 | {value: color.color, wasSetByCode: true, type: eventType}; | ||
187 | } | 194 | } |
188 | else | 195 | else |
189 | { | 196 | { |
190 | this.application.ninja.colorController.colorToolbar.stroke_btn.color(color.mode, color.value); | 197 | if (color.color.a !== undefined) |
198 | { | ||
199 | this.application.ninja.colorController.colorModel.alpha = | ||
200 | {value: color.color.a, wasSetByCode: true, type: eventType}; | ||
201 | } | ||
202 | if(color.color.mode) | ||
203 | { | ||
204 | this.application.ninja.colorController.colorModel[color.color.mode] = color.color; | ||
205 | } | ||
206 | else | ||
207 | { | ||
208 | this.application.ninja.colorController.colorModel["rgb"] = color.color; | ||
209 | } | ||
191 | } | 210 | } |
192 | 211 | ||
193 | // Updating color chips will set the input type to "chip", so set it back here. | 212 | if(updateColorToolBar) |
194 | this.application.ninja.colorController.colorModel.input = input; | 213 | { |
195 | 214 | this._previousColor = color.color.css; | |
196 | color.value.wasSetByCode = true; | ||
197 | color.value.type = 'change'; | ||
198 | if (color.value.a) { | ||
199 | this.application.ninja.colorController.colorModel.alpha = {value: color.value.a, | ||
200 | wasSetByCode: true, | ||
201 | type: 'change'}; | ||
202 | } | 215 | } |
203 | this.application.ninja.colorController.colorModel[color.mode] = color.value; | ||
204 | this._previousColor = color.value.css; | ||
205 | } | 216 | } |
217 | else | ||
218 | { | ||
219 | this.application.ninja.colorController.colorModel.alpha = {value: 1, wasSetByCode: true, type: eventType}; | ||
220 | this.application.ninja.colorController.colorModel.applyNoColor(); | ||
221 | if(updateColorToolBar) | ||
222 | { | ||
223 | this._previousColor = "none"; | ||
224 | } | ||
225 | } | ||
226 | |||
227 | this._color = color; | ||
206 | } | 228 | } |
207 | }, | 229 | }, |
208 | 230 | ||
@@ -288,8 +310,6 @@ exports.EyedropperTool = Montage.create(toolBase, { | |||
288 | this._imageDataCanvas.width = w; | 310 | this._imageDataCanvas.width = w; |
289 | this._imageDataCanvas.height = h; | 311 | this._imageDataCanvas.height = h; |
290 | 312 | ||
291 | // this.application.ninja.currentDocument.documentRoot.appendChild(this._imageDataCanvas); | ||
292 | |||
293 | this._imageDataContext = this._imageDataCanvas.getContext("2d"); | 313 | this._imageDataContext = this._imageDataCanvas.getContext("2d"); |
294 | this._imageDataContext.drawImage(elt, 0, 0); | 314 | this._imageDataContext.drawImage(elt, 0, 0); |
295 | } | 315 | } |
@@ -306,7 +326,6 @@ exports.EyedropperTool = Montage.create(toolBase, { | |||
306 | _getColorFromCanvas: { | 326 | _getColorFromCanvas: { |
307 | value: function(ctx, pt) | 327 | value: function(ctx, pt) |
308 | { | 328 | { |
309 | // var imageData = ctx.getImageData(pt.x, pt.y, 1, 1).data; | ||
310 | var imageData = ctx.getImageData(pt[0], pt[1], 1, 1).data; | 329 | var imageData = ctx.getImageData(pt[0], pt[1], 1, 1).data; |
311 | if(imageData) | 330 | if(imageData) |
312 | { | 331 | { |
@@ -324,7 +343,6 @@ exports.EyedropperTool = Montage.create(toolBase, { | |||
324 | { | 343 | { |
325 | if(this._imageDataCanvas) | 344 | if(this._imageDataCanvas) |
326 | { | 345 | { |
327 | // this.application.ninja.currentDocument.documentRoot.removeChild(this._imageDataCanvas); | ||
328 | this._imageDataCanvas = null; | 346 | this._imageDataCanvas = null; |
329 | this._imageDataContext = null; | 347 | this._imageDataContext = null; |
330 | } | 348 | } |