diff options
Diffstat (limited to 'js/tools/SelectionTool.js')
-rwxr-xr-x | js/tools/SelectionTool.js | 385 |
1 files changed, 156 insertions, 229 deletions
diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js index f9411f48..7033ee3d 100755 --- a/js/tools/SelectionTool.js +++ b/js/tools/SelectionTool.js | |||
@@ -33,19 +33,16 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { | |||
33 | 33 | ||
34 | _areElementsOnSamePlane : { | 34 | _areElementsOnSamePlane : { |
35 | value: function () { | 35 | value: function () { |
36 | if(this._targets && this._targets.length) | 36 | if(this.application.ninja.selectedElements.length) { |
37 | { | 37 | var len = this.application.ninja.selectedElements.length; |
38 | var len = this._targets.length; | ||
39 | var plane = this.application.ninja.stage.stageDeps.snapManager.getDragPlane(); | 38 | var plane = this.application.ninja.stage.stageDeps.snapManager.getDragPlane(); |
40 | for(var i = 0; i < len; i++) | 39 | for(var i = 0; i < len; i++) { |
41 | { | 40 | if(!this.application.ninja.stage.stageDeps.snapManager.elementIsOnPlane(this.application.ninja.selectedElements[i], plane)) { |
42 | var elt = this._targets[i].elt; | ||
43 | if(!this.application.ninja.stage.stageDeps.snapManager.elementIsOnPlane(elt, plane)) | ||
44 | { | ||
45 | return false; | 41 | return false; |
46 | } | 42 | } |
47 | } | 43 | } |
48 | } | 44 | } |
45 | |||
49 | return true; | 46 | return true; |
50 | } | 47 | } |
51 | }, | 48 | }, |
@@ -60,6 +57,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { | |||
60 | else | 57 | else |
61 | { | 58 | { |
62 | this._canSnap = true; | 59 | this._canSnap = true; |
60 | this._updateTargets(); | ||
63 | } | 61 | } |
64 | 62 | ||
65 | this.isDrawing = true; | 63 | this.isDrawing = true; |
@@ -223,7 +221,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { | |||
223 | HandleDoubleClick: { | 221 | HandleDoubleClick: { |
224 | value: function(event) { | 222 | value: function(event) { |
225 | if(this.application.ninja.selectedElements.length > 0) { | 223 | if(this.application.ninja.selectedElements.length > 0) { |
226 | this.application.ninja.currentSelectedContainer = this.application.ninja.selectedElements[0]._element; | 224 | this.application.ninja.currentSelectedContainer = this.application.ninja.selectedElements[0]; |
227 | } else { | 225 | } else { |
228 | this.application.ninja.currentSelectedContainer = this.application.ninja.currentDocument.documentRoot; | 226 | this.application.ninja.currentSelectedContainer = this.application.ninja.currentDocument.documentRoot; |
229 | } | 227 | } |
@@ -242,8 +240,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { | |||
242 | case Keyboard.LEFT: | 240 | case Keyboard.LEFT: |
243 | var newLeft = []; | 241 | var newLeft = []; |
244 | var leftArr = this.application.ninja.selectedElements.map(function(item) { | 242 | var leftArr = this.application.ninja.selectedElements.map(function(item) { |
245 | newLeft.push( (parseInt(ElementsMediator.getProperty(item._element, "left")) - inc) + "px" ); | 243 | newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left")) - inc) + "px" ); |
246 | return ElementsMediator.getProperty(item._element, "left"); | 244 | return ElementsMediator.getProperty(item, "left"); |
247 | }); | 245 | }); |
248 | 246 | ||
249 | ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr); | 247 | ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr); |
@@ -251,8 +249,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { | |||
251 | case Keyboard.UP: | 249 | case Keyboard.UP: |
252 | var newTop = []; | 250 | var newTop = []; |
253 | var topArr = this.application.ninja.selectedElements.map(function(item) { | 251 | var topArr = this.application.ninja.selectedElements.map(function(item) { |
254 | newTop.push( (parseInt(ElementsMediator.getProperty(item._element, "top")) - inc) + "px" ); | 252 | newTop.push( (parseInt(ElementsMediator.getProperty(item, "top")) - inc) + "px" ); |
255 | return ElementsMediator.getProperty(item._element, "top"); | 253 | return ElementsMediator.getProperty(item, "top"); |
256 | }); | 254 | }); |
257 | 255 | ||
258 | ElementsMediator.setProperty(this.application.ninja.selectedElements, "top", newTop , "Change", "selectionTool", topArr); | 256 | ElementsMediator.setProperty(this.application.ninja.selectedElements, "top", newTop , "Change", "selectionTool", topArr); |
@@ -260,8 +258,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { | |||
260 | case Keyboard.RIGHT: | 258 | case Keyboard.RIGHT: |
261 | var newLeft = []; | 259 | var newLeft = []; |
262 | var leftArr = this.application.ninja.selectedElements.map(function(item) { | 260 | var leftArr = this.application.ninja.selectedElements.map(function(item) { |
263 | newLeft.push( (parseInt(ElementsMediator.getProperty(item._element, "left")) + inc) + "px" ); | 261 | newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left")) + inc) + "px" ); |
264 | return ElementsMediator.getProperty(item._element, "left"); | 262 | return ElementsMediator.getProperty(item, "left"); |
265 | }); | 263 | }); |
266 | 264 | ||
267 | ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr); | 265 | ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr); |
@@ -269,8 +267,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { | |||
269 | case Keyboard.DOWN: | 267 | case Keyboard.DOWN: |
270 | var newTop = []; | 268 | var newTop = []; |
271 | var topArr = this.application.ninja.selectedElements.map(function(item) { | 269 | var topArr = this.application.ninja.selectedElements.map(function(item) { |
272 | newTop.push( (parseInt(ElementsMediator.getProperty(item._element, "top")) + inc) + "px" ); | 270 | newTop.push( (parseInt(ElementsMediator.getProperty(item, "top")) + inc) + "px" ); |
273 | return ElementsMediator.getProperty(item._element, "top"); | 271 | return ElementsMediator.getProperty(item, "top"); |
274 | }); | 272 | }); |
275 | 273 | ||
276 | ElementsMediator.setProperty(this.application.ninja.selectedElements, "top", newTop , "Change", "selectionTool", topArr); | 274 | ElementsMediator.setProperty(this.application.ninja.selectedElements, "top", newTop , "Change", "selectionTool", topArr); |
@@ -295,190 +293,103 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { | |||
295 | }, | 293 | }, |
296 | 294 | ||
297 | _updateTargets: { | 295 | _updateTargets: { |
298 | value: function(addToUndoStack) { | 296 | value: function(addToUndo) { |
299 | var newLeft = [], | 297 | var modObject = [], mod3dObject = [], self = this; |
300 | newTop = [], | 298 | |
301 | newWidth = [], | 299 | this.application.ninja.selectedElements.forEach(function(element) { |
302 | newHeight = [], | 300 | |
303 | newStyles = [], | 301 | if(addToUndo) { |
304 | previousLeft = [], | 302 | if(!self._use3DMode) { |
305 | previousTop = [], | 303 | var prevX = element.elementModel.getProperty("x"); |
306 | previousWidth = [], | 304 | var prevY = element.elementModel.getProperty("y"); |
307 | previousHeight = [], | 305 | var prevW = element.elementModel.getProperty("w"); |
308 | previousStyles = []; | 306 | var prevH = element.elementModel.getProperty("h"); |
309 | var len = this.application.ninja.selectedElements.length; | 307 | var x = ElementsMediator.getProperty(element, "left"); |
310 | this._targets = []; | 308 | var y = ElementsMediator.getProperty(element, "top"); |
311 | for(var i = 0; i < len; i++) | 309 | var w = ElementsMediator.getProperty(element, "width"); |
312 | { | 310 | var h = ElementsMediator.getProperty(element, "height"); |
313 | var elt = this.application.ninja.selectedElements[i]._element; | 311 | |
312 | // if we have a delta, that means the transform handles were used and | ||
313 | // we should update the width and height too. Otherwise, just update left and top. | ||
314 | if(this.delta) { | ||
315 | modObject.push({element:element, properties:{left: x, top:y, width: w, height: h}, previousProperties: {left: prevX, top:prevY, width: prevW, height: prevH}}); | ||
316 | } else { | ||
317 | modObject.push({element:element, properties:{left: x, top:y}, previousProperties: {left: prevX, top:prevY}}); | ||
318 | } | ||
314 | 319 | ||
315 | var curMat = viewUtils.getMatrixFromElement(elt); | 320 | } else { |
316 | var curMatInv = glmat4.inverse(curMat, []); | 321 | // Not using the 3d mode |
322 | var previousMat = element.elementModel.getProperty("mat").slice(0); | ||
323 | var prevW = element.elementModel.getProperty("w"); | ||
324 | var prevH = element.elementModel.getProperty("h"); | ||
325 | var w = ElementsMediator.getProperty(element, "width"); | ||
326 | var h = ElementsMediator.getProperty(element, "height"); | ||
317 | 327 | ||
318 | this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); | 328 | var previousStyleStr = {dist:element.elementModel.getProperty("dist"), mat:MathUtils.scientificToDecimal(previousMat, 5)}; |
319 | if(addToUndoStack) | 329 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)}; |
320 | { | ||
321 | 330 | ||
322 | if(!this._use3DMode) | 331 | modObject.push({element:element, properties:{width: w, height:h}, previousProperties: {width: prevW, height:prevH}}); |
323 | { | 332 | mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr}); |
324 | var previousMat = this._undoArray[i].mat.slice(0); | ||
325 | var prevX = this._undoArray[i]._x; | ||
326 | var prevY = this._undoArray[i]._y; | ||
327 | var prevW = this._undoArray[i]._w; | ||
328 | var prevH = this._undoArray[i]._h; | ||
329 | var _x = parseInt(ElementsMediator.getProperty(elt, "left")) + curMat[12] - previousMat[12]; | ||
330 | var _y = parseInt(ElementsMediator.getProperty(elt, "top")) + curMat[13] - previousMat[13]; | ||
331 | var _w = parseInt(ElementsMediator.getProperty(elt, "width")); | ||
332 | var _h = parseInt(ElementsMediator.getProperty(elt, "height")); | ||
333 | |||
334 | previousLeft.push(prevX + "px"); | ||
335 | previousTop.push(prevY + "px"); | ||
336 | previousWidth.push(prevW + "px"); | ||
337 | previousHeight.push(prevH + "px"); | ||
338 | newLeft.push(_x + "px"); | ||
339 | newTop.push(_y + "px"); | ||
340 | newWidth.push(_w + "px"); | ||
341 | newHeight.push(_h + "px"); | ||
342 | |||
343 | viewUtils.setMatrixForElement(elt, previousMat); | ||
344 | |||
345 | this._targets[i].mat = previousMat; | ||
346 | this._targets[i].matInv = glmat4.inverse(previousMat, []); | ||
347 | } | ||
348 | else | ||
349 | { | ||
350 | var previousMat = this._undoArray[i].mat.slice(0); | ||
351 | var prevW = this._undoArray[i]._w; | ||
352 | var prevH = this._undoArray[i]._h; | ||
353 | var _w = parseInt(ElementsMediator.getProperty(elt, "width")); | ||
354 | var _h = parseInt(ElementsMediator.getProperty(elt, "height")); | ||
355 | previousWidth.push(prevW + "px"); | ||
356 | previousHeight.push(prevH + "px"); | ||
357 | newWidth.push(_w + "px"); | ||
358 | newHeight.push(_h + "px"); | ||
359 | |||
360 | var previousStyleStr = {dist:this._undoArray[i].dist, | ||
361 | mat:MathUtils.scientificToDecimal(previousMat, 5)}; | ||
362 | var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), | ||
363 | mat:MathUtils.scientificToDecimal(curMat, 5)}; | ||
364 | previousStyles.push(previousStyleStr); | ||
365 | newStyles.push(newStyleStr); | ||
366 | |||
367 | this._targets[i].mat = curMat; | ||
368 | this._targets[i].matInv = curMatInv; | ||
369 | } | ||
370 | } | ||
371 | } | ||
372 | if(addToUndoStack) | ||
373 | { | ||
374 | if(!this._use3DMode) | ||
375 | { | ||
376 | // if we have a delta, that means the transform handles were used and | ||
377 | // we should update the width and height too. Otherwise, just update left and top. | ||
378 | if(this._delta) | ||
379 | { | ||
380 | ElementsMediator.setProperties(this.application.ninja.selectedElements, | ||
381 | { "left": newLeft, "top": newTop, "width": newWidth, "height": newHeight }, | ||
382 | "Change", | ||
383 | "selectionTool", | ||
384 |