aboutsummaryrefslogtreecommitdiff
path: root/js/tools/EyedropperTool.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-03-07 16:23:51 -0800
committerNivesh Rajbhandari2012-03-07 16:23:51 -0800
commit84af1c10ca02dd3ac2b36cb141d180c55bcdebdd (patch)
treeeaddfbcf451cbec13eb7fb2eef914f22e5597b91 /js/tools/EyedropperTool.js
parentb6288e1ffe4ffe29a595bb1e146feb388503e2c4 (diff)
downloadninja-84af1c10ca02dd3ac2b36cb141d180c55bcdebdd.tar.gz
Eyedropper now supports strokes in rectangle shapes.
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/tools/EyedropperTool.js')
-rwxr-xr-xjs/tools/EyedropperTool.js59
1 files changed, 55 insertions, 4 deletions
diff --git a/js/tools/EyedropperTool.js b/js/tools/EyedropperTool.js
index 11c15158..d6a162cd 100755
--- a/js/tools/EyedropperTool.js
+++ b/js/tools/EyedropperTool.js
@@ -6,9 +6,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
6 6
7var Montage = require("montage/core/core").Montage, 7var Montage = require("montage/core/core").Montage,
8 ElementsMediator = require("js/mediators/element-mediator").ElementMediator, 8 ElementsMediator = require("js/mediators/element-mediator").ElementMediator,
9 drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, 9 toolBase = require("js/tools/ToolBase").toolBase,
10 vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, 10 ShapesController = require("js/controllers/elements/shapes-controller").ShapesController;
11 toolBase = require("js/tools/ToolBase").toolBase;
12 11
13exports.EyedropperTool = Montage.create(toolBase, { 12exports.EyedropperTool = Montage.create(toolBase, {
14 13
@@ -133,7 +132,15 @@ exports.EyedropperTool = Montage.create(toolBase, {
133 { 132 {
134 this._deleteImageDataCanvas(); 133 this._deleteImageDataCanvas();
135 134
136 c = this._getColorFromElement(obj, event); 135 if(ShapesController.isElementAShape(obj))
136 {
137 c = this._getColorFromShape(obj, event);
138 }
139 else
140 {
141 c = this._getColorFromElement(obj, event);
142 }
143
137 if(typeof(c) === "string") 144 if(typeof(c) === "string")
138 { 145 {
139 color = this.application.ninja.colorController.getColorObjFromCss(c); 146 color = this.application.ninja.colorController.getColorObjFromCss(c);
@@ -289,6 +296,50 @@ exports.EyedropperTool = Montage.create(toolBase, {
289 } 296 }
290 }, 297 },
291 298
299 // TODO - We don't want to calculate this repeatedly
300 _getColorFromShape: {
301 value: function(elt, event)
302 {
303 var strokeWidth = ShapesController.getShapeProperty(elt, "strokeSize"),
304 bounds3D,
305 innerBounds,
306 pt,
307 tmpPt,
308 x,
309 y;
310 if(strokeWidth)
311 {
312 strokeWidth = parseFloat(strokeWidth);
313 bounds3D = this.application.ninja.stage.viewUtils.getElementViewBounds3D( elt );
314 innerBounds = [];
315 pt = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas,
316 new WebKitPoint(event.pageX, event.pageY));
317
318 innerBounds.push([bounds3D[0][0] + strokeWidth, bounds3D[0][1] + strokeWidth, 0]);
319
320 innerBounds.push([bounds3D[1][0] + strokeWidth, bounds3D[1][1] - strokeWidth, 0]);
321
322 innerBounds.push([bounds3D[2][0] - strokeWidth, bounds3D[2][1] - strokeWidth, 0]);
323
324 innerBounds.push([bounds3D[3][0] - strokeWidth, bounds3D[3][1] + strokeWidth, 0]);
325
326 tmpPt = this.application.ninja.stage.viewUtils.globalToLocal([pt.x, pt.y], elt);
327 x = tmpPt[0];
328 y = tmpPt[1];
329
330 if( (x < innerBounds[0][0]) ||
331 (x > innerBounds[2][0]) ||
332 (y < innerBounds[0][1]) ||
333 (y > innerBounds[1][1]) )
334 {
335 return ShapesController.getColor(elt, false);
336 }
337 }
338
339 return ShapesController.getColor(elt, true);
340 }
341 },
342
292 _getColorAtPoint: { 343 _getColorAtPoint: {
293 value: function(elt, event) 344 value: function(elt, event)
294 { 345 {