aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-02-14 13:38:56 -0800
committerNivesh Rajbhandari2012-02-14 13:38:56 -0800
commitd77deb60ade63d8526ce16d0b104285411218e14 (patch)
tree5c778fb18729be47c8c74c9f76af7123c9df2ab7 /js
parent9e43e17a07b60dd6004fb03b1f5c5facc8425b4f (diff)
downloadninja-d77deb60ade63d8526ce16d0b104285411218e14.tar.gz
Get color under mouse point from image or canvas.
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js')
-rw-r--r--js/data/tools-data.js2
-rw-r--r--js/tools/EyedropperTool.js40
2 files changed, 34 insertions, 8 deletions
diff --git a/js/data/tools-data.js b/js/data/tools-data.js
index de965dbc..f63d14ae 100644
--- a/js/data/tools-data.js
+++ b/js/data/tools-data.js
@@ -174,7 +174,7 @@ exports.ToolsData = Montage.create(Montage, {
174 "spriteSheet": true, 174 "spriteSheet": true,
175 "action": "EyedropperTool", 175 "action": "EyedropperTool",
176 "toolTip": "Eyedropper Tool", 176 "toolTip": "Eyedropper Tool",
177 "cursor": "url('images/tools/eyedropper_down.png'), default", 177 "cursor": "url('images/tools/eyedropper_down.png') 6 20, default",
178 "lastInGroup": false, 178 "lastInGroup": false,
179 "container": false, 179 "container": false,
180 "selected": false 180 "selected": false
diff --git a/js/tools/EyedropperTool.js b/js/tools/EyedropperTool.js
index 8301480d..43286122 100644
--- a/js/tools/EyedropperTool.js
+++ b/js/tools/EyedropperTool.js
@@ -50,6 +50,13 @@ exports.EyedropperTool = Montage.create(toolBase, {
50 { 50 {
51 this._isMouseDown = false; 51 this._isMouseDown = false;
52 this._escape = false; 52 this._escape = false;
53 this._elementUnderMouse = null;
54 if(this._imageDataCanvas)
55 {
56 this.application.ninja.stage.element.removeChild(this._imageDataCanvas);
57 this._imageDataCanvas = null;
58 this._imageDataContext = null;
59 }
53 } 60 }
54 if(this._isMouseDown) 61 if(this._isMouseDown)
55 { 62 {
@@ -71,6 +78,14 @@ exports.EyedropperTool = Montage.create(toolBase, {
71 this._updateColor(this._color); 78 this._updateColor(this._color);
72 79
73 this._color = null; 80 this._color = null;
81
82 this._elementUnderMouse = null;
83 if(this._imageDataCanvas)
84 {
85 this.application.ninja.stage.element.removeChild(this._imageDataCanvas);
86 this._imageDataCanvas = null;
87 this._imageDataContext = null;
88 }
74 } 89 }
75 } 90 }
76 }, 91 },
@@ -116,8 +131,12 @@ exports.EyedropperTool = Montage.create(toolBase, {
116 } 131 }
117 else if (obj.elementModel.type === "CANVAS") 132 else if (obj.elementModel.type === "CANVAS")
118 { 133 {
119 this._imageDataCanvas = null; 134 if(this._imageDataCanvas)
120 this._imageDataContext = null; 135 {
136 this.application.ninja.stage.element.removeChild(this._imageDataCanvas);
137 this._imageDataCanvas = null;
138 this._imageDataContext = null;
139 }
121 140
122 var pt = webkitConvertPointFromPageToNode(obj, 141 var pt = webkitConvertPointFromPageToNode(obj,
123 new WebKitPoint(event.pageX, event.pageY)), 142 new WebKitPoint(event.pageX, event.pageY)),
@@ -131,8 +150,12 @@ exports.EyedropperTool = Montage.create(toolBase, {
131 } 150 }
132 else 151 else
133 { 152 {
134 this._imageDataCanvas = null; 153 if(this._imageDataCanvas)
135 this._imageDataContext = null; 154 {
155 this.application.ninja.stage.element.removeChild(this._imageDataCanvas);
156 this._imageDataCanvas = null;
157 this._imageDataContext = null;
158 }
136 159
137 // TODO - figure out if user clicked on a border - for now, just get fill 160 // TODO - figure out if user clicked on a border - for now, just get fill
138 c = ElementsMediator.getColor(obj, this._isOverBackground(obj, event)); 161 c = ElementsMediator.getColor(obj, this._isOverBackground(obj, event));
@@ -157,8 +180,12 @@ exports.EyedropperTool = Montage.create(toolBase, {
157 else 180 else
158 { 181 {
159 this._elementUnderMouse = null; 182 this._elementUnderMouse = null;
160 this._imageDataCanvas = null; 183 if(this._imageDataCanvas)
161 this._imageDataContext = null; 184 {
185 this.application.ninja.stage.element.removeChild(this._imageDataCanvas);
186 this._imageDataCanvas = null;
187 this._imageDataContext = null;
188 }
162 } 189 }
163 190
164 } 191 }
@@ -264,7 +291,6 @@ exports.EyedropperTool = Montage.create(toolBase, {
264 this.application.ninja.stage.element.appendChild(this._imageDataCanvas); 291 this.application.ninja.stage.element.appendChild(this._imageDataCanvas);
265 292
266 this._imageDataContext = this._imageDataCanvas.getContext("2d"); 293 this._imageDataContext = this._imageDataCanvas.getContext("2d");
267// this._imageDataContext.drawImage(elt, eltCoords[0], eltCoords[1]);
268 this._imageDataContext.drawImage(elt, 0, 0); 294 this._imageDataContext.drawImage(elt, 0, 0);
269 } 295 }
270 296