aboutsummaryrefslogtreecommitdiff
path: root/js/tools/EyedropperTool.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/EyedropperTool.js')
-rwxr-xr-xjs/tools/EyedropperTool.js81
1 files changed, 49 insertions, 32 deletions
diff --git a/js/tools/EyedropperTool.js b/js/tools/EyedropperTool.js
index d007da39..710c96ef 100755
--- a/js/tools/EyedropperTool.js
+++ b/js/tools/EyedropperTool.js
@@ -18,6 +18,7 @@ exports.EyedropperTool = Montage.create(toolBase, {
18 _elementUnderMouse: { value: null }, 18 _elementUnderMouse: { value: null },
19 _imageDataCanvas: { value: null }, 19 _imageDataCanvas: { value: null },
20 _imageDataContext: { value: null }, 20 _imageDataContext: { value: null },
21 _canSnap: { value: false },
21 22
22 Configure: { 23 Configure: {
23 value: function ( doActivate ) 24 value: function ( doActivate )
@@ -143,10 +144,14 @@ exports.EyedropperTool = Montage.create(toolBase, {
143 { 144 {
144 this._deleteImageDataCanvas(); 145 this._deleteImageDataCanvas();
145 146
146 c = ElementsMediator.getColor(obj, this._isOverBackground(obj, event)); 147 c = this._getColorFromElement(obj, event);
147 if(c) 148 if(typeof(c) === "string")
149 {
150 color = this.application.ninja.colorController.getColorObjFromCss(c);
151 }
152 else
148 { 153 {
149 color = this.application.ninja.colorController.getColorObjFromCss(c.color.css); 154 color = c;
150 } 155 }
151 } 156 }
152 157
@@ -202,51 +207,63 @@ exports.EyedropperTool = Montage.create(toolBase, {
202 }, 207 },
203 208
204 // TODO - We don't want to calculate this repeatedly 209 // TODO - We don't want to calculate this repeatedly
205 _isOverBackground: { 210 _getColorFromElement: {
206 value: function(elt, event) 211 value: function(elt, event)
207 { 212 {
208 var border = ElementsMediator.getProperty(elt, "border", parseFloat); 213 var border = ElementsMediator.getProperty(elt, "border"),
209 214 borderWidth,
215 bounds3D,
216 innerBounds,
217 pt,
218 bt,
219 br,
220 bb,
221 bl,
222 xAdj,
223 yAdj,
224 tmpPt,
225 x,
226 y;
210 if(border) 227 if(border)
211 { 228 {
212 var bounds3D,
213 innerBounds = [],
214 pt = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)),
215 bt = ElementsMediator.getProperty(elt, "border-top", parseFloat),
216 br = ElementsMediator.getProperty(elt, "border-right", parseFloat),
217 bb = ElementsMediator.getProperty(elt, "border-bottom", parseFloat),
218 bl = ElementsMediator.getProperty(elt, "border-left", parseFloat);
219
220// this.application.ninja.stage.viewUtils.setViewportObj( elt );
221 bounds3D = this.application.ninja.stage.viewUtils.getElementViewBounds3D( elt ); 229 bounds3D = this.application.ninja.stage.viewUtils.getElementViewBounds3D( elt );
222// console.log("bounds"); 230 innerBounds = [];
223// console.dir(bounds3D); 231 pt = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas,
232 new WebKitPoint(event.pageX, event.pageY));
233 borderWidth = parseFloat(border);
234 if(isNaN(borderWidth))
235 {
236 bt = ElementsMediator.getProperty(elt, "border-top", parseFloat);
237 br = ElementsMediator.getProperty(elt, "border-right", parseFloat);
238 bb = ElementsMediator.getProperty(elt, "border-bottom", parseFloat);
239 bl = ElementsMediator.getProperty(elt, "border-left", parseFloat);
240 borderWidth = 0;
241 }
242 xAdj = bl || borderWidth;
243 yAdj = bt || borderWidth;
224 244
225 var xAdj = bl || border,
226 yAdj = bt || border;
227 innerBounds.push([bounds3D[0][0] + xAdj, bounds3D[0][1] + yAdj, 0]); 245 innerBounds.push([bounds3D[0][0] + xAdj, bounds3D[0][1] + yAdj, 0]);
228 246
229 yAdj += bb || border; 247 yAdj = bb || borderWidth;
230 innerBounds.push([bounds3D[1][0] + xAdj, bounds3D[1][1] - yAdj, 0]); 248 innerBounds.push([bounds3D[1][0] + xAdj, bounds3D[1][1] - yAdj, 0]);
231 249
232 xAdj += br || border; 250 xAdj = br || borderWidth;
233 innerBounds.push([bounds3D[2][0] - xAdj, bounds3D[2][1] - yAdj, 0]); 251 innerBounds.push([bounds3D[2][0] - xAdj, bounds3D[2][1] - yAdj, 0]);
234 252
235 yAdj = bt || border; 253 yAdj = bt || borderWidth;
236 innerBounds.push([bounds3D[3][0] - xAdj, bounds3D[3][1] + yAdj, 0]); 254 innerBounds.push([bounds3D[3][0] - xAdj, bounds3D[3][1] + yAdj, 0]);
237// console.log("innerBounds");
238// console.dir(innerBounds);
239 255
240 var tmpPt = this.application.ninja.stage.viewUtils.globalToLocal([pt.x, pt.y], elt); 256 tmpPt = this.application.ninja.stage.viewUtils.globalToLocal([pt.x, pt.y], elt);
241 var x = tmpPt[0], 257 x = tmpPt[0];
242 y = tmpPt[1]; 258 y = tmpPt[1];
243 259
244 if(x < innerBounds[0][0]) return false; 260 if(x < innerBounds[0][0]) return ElementsMediator.getProperty(elt, "border-left-color");
245 if(x > innerBounds[2][0]) return false; 261 if(x > innerBounds[2][0]) return ElementsMediator.getProperty(elt, "border-right-color");
246 if(y < innerBounds[0][1]) return false; 262 if(y < innerBounds[0][1]) return ElementsMediator.getProperty(elt, "border-top-color");
247 if(y > innerBounds[1][1]) return false; 263 if(y > innerBounds[1][1]) return ElementsMediator.getProperty(elt, "border-bottom-color");
248 } 264 }
249 return true; 265
266 return ElementsMediator.getColor(elt, true);
250 } 267 }
251 }, 268 },
252 269