diff options
Diffstat (limited to 'js/tools/EyedropperTool.js')
-rw-r--r-- | js/tools/EyedropperTool.js | 162 |
1 files changed, 160 insertions, 2 deletions
diff --git a/js/tools/EyedropperTool.js b/js/tools/EyedropperTool.js index 8bb986a3..62a3eadd 100644 --- a/js/tools/EyedropperTool.js +++ b/js/tools/EyedropperTool.js | |||
@@ -6,7 +6,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
6 | 6 | ||
7 | var Montage = require("montage/core/core").Montage, | 7 | var Montage = require("montage/core/core").Montage, |
8 | ElementsMediator = require("js/mediators/element-mediator").ElementMediator, | 8 | ElementsMediator = require("js/mediators/element-mediator").ElementMediator, |
9 | 9 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, | |
10 | vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, | ||
10 | toolBase = require("js/tools/ToolBase").toolBase; | 11 | toolBase = require("js/tools/ToolBase").toolBase; |
11 | 12 | ||
12 | exports.EyedropperTool = Montage.create(toolBase, { | 13 | exports.EyedropperTool = Montage.create(toolBase, { |
@@ -99,7 +100,7 @@ exports.EyedropperTool = Montage.create(toolBase, { | |||
99 | if (obj) | 100 | if (obj) |
100 | { | 101 | { |
101 | // TODO - figure out if user clicked on a border - for now, just get fill | 102 | // TODO - figure out if user clicked on a border - for now, just get fill |
102 | var c = ElementsMediator.getColor(obj, true); | 103 | var c = ElementsMediator.getColor(obj, this._isOverBorder(obj, event)); |
103 | if(c) | 104 | if(c) |
104 | { | 105 | { |
105 | var color = this.application.ninja.colorController.getColorObjFromCss(c.color.css); | 106 | var color = this.application.ninja.colorController.getColorObjFromCss(c.color.css); |
@@ -147,6 +148,163 @@ exports.EyedropperTool = Montage.create(toolBase, { | |||
147 | this._previousColor = color.value.css; | 148 | this._previousColor = color.value.css; |
148 | } | 149 | } |
149 | } | 150 | } |
151 | }, | ||
152 | |||
153 | // TODO - We don't want to calculate this repeatedly | ||
154 | _isOverBorder: { | ||
155 | value: function(elt, event) | ||
156 | { | ||
157 | var border = ElementsMediator.getProperty(elt, "border", parseFloat); | ||
158 | |||
159 | if(border) | ||
160 | { | ||
161 | var bounds3D, | ||
162 | innerBounds = [], | ||
163 | pt = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)), | ||
164 | bt = ElementsMediator.getProperty(elt, "border-top", parseFloat), | ||
165 | br = ElementsMediator.getProperty(elt, "border-right", parseFloat), | ||
166 | bb = ElementsMediator.getProperty(elt, "border-bottom", parseFloat), | ||
167 | bl = ElementsMediator.getProperty(elt, "border-left", parseFloat); | ||
168 | |||
169 | // this.application.ninja.stage.viewUtils.setViewportObj( elt ); | ||
170 | bounds3D = this.application.ninja.stage.viewUtils.getElementViewBounds3D( elt ); | ||
171 | console.log("bounds"); | ||
172 | console.dir(bounds3D); | ||
173 | |||
174 | var xAdj = bl || border, | ||
175 | yAdj = bt || border; | ||
176 | innerBounds.push([bounds3D[0][0] + xAdj, bounds3D[0][1] + yAdj, 0]); | ||
177 | |||
178 | yAdj += bb || border; | ||
179 | innerBounds.push([bounds3D[1][0] + xAdj, bounds3D[1][1] - yAdj, 0]); | ||
180 | |||
181 | xAdj += br || border; | ||
182 | innerBounds.push([bounds3D[2][0] - xAdj, bounds3D[2][1] - yAdj, 0]); | ||
183 | |||
184 | yAdj = bt || border; | ||
185 | innerBounds.push([bounds3D[3][0] - xAdj, bounds3D[3][1] + yAdj, 0]); | ||
186 | console.log("innerBounds"); | ||
187 | console.dir(innerBounds); | ||
188 | |||
189 | var tmpPt = this.application.ninja.stage.viewUtils.globalToLocal([pt.x, pt.y], elt); | ||
190 | var x = tmpPt[0], | ||
191 | y = tmpPt[1]; | ||
192 | |||
193 | if(x < innerBounds[0][0]) return false; | ||
194 | if(x > innerBounds[2][0]) return false; | ||
195 | if(y < innerBounds[0][1]) return false; | ||
196 | if(y > innerBounds[1][1]) return false; | ||
197 | |||
198 | return true; | ||
199 | |||
200 | |||
201 | // var contain = MathUtils.boundaryContainsPoint(innerBounds, tmpPt, false); | ||
202 | // console.log("contain is " + contain); | ||
203 | // var tmpMat = this.application.ninja.stage.viewUtils.getLocalToGlobalMatrix( elt ); | ||
204 | //// var zoomFactor = 1; | ||
205 | //// if (this.application.ninja.stage.viewport.style && this.application.ninja.stage.viewport.style.zoom) | ||
206 | //// { | ||
207 | //// zoomFactor = Number(this.application.ninja.stage.viewport.style.zoom); | ||
208 | //// } | ||
209 | // | ||
210 | // for (var j=0; j<4; j++) | ||
211 | // { | ||
212 | // var localPt = innerBounds[j]; | ||
213 | // var tmpPt = this.application.ninja.stage.viewUtils.localToGlobal2(localPt, tmpMat); | ||
214 | // | ||
215 | //// if(zoomFactor !== 1) | ||
216 | //// { | ||
217 | //// tmpPt = vecUtils.vecScale(3, tmpPt, zoomFactor); | ||
218 | //// tmpPt[0] += this.application.ninja.stage.scrollLeft*(zoomFactor - 1); | ||
219 | //// tmpPt[1] += this.application.ninja.stage.scrollTop*(zoomFactor - 1); | ||
220 | //// } | ||
221 | // innerBounds[j] = tmpPt; | ||
222 | // } | ||
223 | // | ||
224 | // var contain = MathUtils.boundaryContainsPoint(innerBounds, [pt.x, pt.y], false); | ||
225 | // console.log("contain is " + contain); | ||
226 | |||
227 | |||
228 | |||
229 | // var bounds, | ||
230 | // innerBounds = [], | ||
231 | // plane = ElementsMediator.get3DProperty(elt, "elementPlane"), | ||
232 | // pt = webkitConvertPointFromPageToNode(drawUtils.getDrawingSurfaceElement(), new WebKitPoint(event.pageX, event.pageY)), | ||
233 | // bt = ElementsMediator.getProperty(elt, "border-top", parseFloat), | ||
234 | // br = ElementsMediator.getProperty(elt, "border-right", parseFloat), | ||
235 | // bb = ElementsMediator.getProperty(elt, "border-bottom", parseFloat), | ||
236 | // bl = ElementsMediator.getProperty(elt, "border-left", parseFloat); | ||
237 | // | ||
238 | // if(plane) | ||
239 | // { | ||
240 | // bounds = plane.getBoundaryPoints().slice(0); | ||
241 | // var b = bl || border; | ||
242 | // var dirV = vecUtils.vecSubtract(2, bounds[3], bounds[0]); | ||
243 | // dirV = vecUtils.vecNormalize(2, dirV, b); | ||
244 | // innerBounds.push(vecUtils.vecAdd(2, bounds[0], dirV)); | ||
245 | // | ||
246 | // b = bb || border; | ||
247 | // dirV = vecUtils.vecSubtract(2, bounds[1], bounds[0]); | ||
248 | // dirV = vecUtils.vecNormalize(2, dirV, b); | ||
249 | // innerBounds.push(vecUtils.vecAdd(2, bounds[0], dirV)); | ||
250 | // | ||
251 | // b = br || border; | ||
252 | // dirV = vecUtils.vecSubtract(2, bounds[2], bounds[1]); | ||
253 | // dirV = vecUtils.vecNormalize(2, dirV, b); | ||
254 | // innerBounds.push(vecUtils.vecAdd(2, bounds[1], dirV)); | ||
255 | // | ||
256 | // b = bt || border; | ||
257 | // dirV = vecUtils.vecSubtract(2, bounds[2], bounds[3]); | ||
258 | // dirV = vecUtils.vecNormalize(2, dirV, b); | ||
259 | // innerBounds.push(vecUtils.vecAdd(2, bounds[3], dirV)); | ||
260 | // | ||
261 | // console.log("outerBounds"); | ||
262 | // console.dir(bounds); | ||
263 | // | ||
264 | // console.log("innerBounds"); | ||
265 | // console.dir(innerBounds); | ||
266 | // } | ||
267 | |||
268 | // var contain = MathUtils.boundaryContainsPoint( bounds, pt, plane.isBackFacing() ); | ||
269 | // if (contain == MathUtils.OUTSIDE) | ||
270 | // { | ||
271 | // | ||
272 | // } | ||
273 | // if (contain == MathUtils.ON) | ||
274 | // { | ||
275 | // | ||
276 | // } | ||
277 | // | ||
278 | // var bt = ElementsMediator.getProperty(elt, "border-top", parseFloat), | ||
279 | // br = ElementsMediator.getProperty(elt, "border-right", parseFloat), | ||
280 | // bb = ElementsMediator.getProperty(elt, "border-bottom", parseFloat), | ||
281 | // bl = ElementsMediator.getProperty(elt, "border-left", parseFloat), | ||
282 | // left = ElementsMediator.getProperty(elt, "left", parseFloat), | ||
283 | // top = ElementsMediator.getProperty(elt, "top", parseFloat), | ||
284 | // width = ElementsMediator.getProperty(elt, "width", parseFloat), | ||
285 | // height = ElementsMediator.getProperty(elt, "height", parseFloat); | ||
286 | // | ||
287 | // left1 = elt.offsetLeft; | ||
288 | // left2 = box[0]; | ||
289 | // right1 = elt.offsetLeft + ele.offsetWidth; | ||
290 | // right2 = box[2]; | ||
291 | // top1 = ele.offsetTop; | ||
292 | // top2 = box[1]; | ||
293 | // bottom1 = ele.offsetTop + ele.offsetHeight; | ||
294 | // bottom2 = box[3]; | ||
295 | // | ||
296 | // if (bottom1 < top2) return false; | ||
297 | // if (top1 > bottom2) return false; | ||
298 | // if (right1 < left2) return false; | ||
299 | // if (left1 > right2) return false; | ||
300 | // | ||
301 | // return true; | ||
302 | |||
303 | } | ||
304 | |||
305 | |||
306 | } | ||
307 | |||
150 | } | 308 | } |
151 | 309 | ||
152 | }); \ No newline at end of file | 310 | }); \ No newline at end of file |