aboutsummaryrefslogtreecommitdiff
path: root/js/tools/SelectionTool.js
diff options
context:
space:
mode:
authorJonathan Duran2012-04-18 08:08:14 -0700
committerJonathan Duran2012-04-18 08:08:14 -0700
commit9f05148454783fd761c9cad35a169c6cb164c1a4 (patch)
tree02b9cac67ce4215443beab9f47fa4cf216e77840 /js/tools/SelectionTool.js
parenta2af3c8bd2349a24dd7de920381b04847a863a46 (diff)
parent616a8532099fec2a15855eac97cd85cb60c4451c (diff)
downloadninja-9f05148454783fd761c9cad35a169c6cb164c1a4.tar.gz
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
Diffstat (limited to 'js/tools/SelectionTool.js')
-rwxr-xr-xjs/tools/SelectionTool.js367
1 files changed, 146 insertions, 221 deletions
diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js
index eb5341de..abf45365 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 },
@@ -298,189 +295,103 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
298 }, 295 },
299 296
300 _updateTargets: { 297 _updateTargets: {
301 value: function(addToUndoStack) { 298 value: function(addToUndo) {
302 var newLeft = [], 299 var modObject = [], mod3dObject = [], self = this;
303 newTop = [], 300
304 newWidth = [], 301 this.application.ninja.selectedElements.forEach(function(element) {
305 newHeight = [], 302
306 newStyles = [], 303 if(addToUndo) {
307 previousLeft = [], 304 if(!self._use3DMode) {
308 previousTop = [], 305 var prevX = element.elementModel.getProperty("x");
309 previousWidth = [], 306 var prevY = element.elementModel.getProperty("y");
310 previousHeight = [], 307 var prevW = element.elementModel.getProperty("w");
311 previousStyles = []; 308 var prevH = element.elementModel.getProperty("h");
312 var len = this.application.ninja.selectedElements.length; 309 var x = ElementsMediator.getProperty(element, "left");
313 this._targets = []; 310 var y = ElementsMediator.getProperty(element, "top");
314 for(var i = 0; i < len; i++) { 311 var w = ElementsMediator.getProperty(element, "width");
315 var elt = this.application.ninja.selectedElements[i]; 312 var h = ElementsMediator.getProperty(element, "height");
316 313
317 var curMat = viewUtils.getMatrixFromElement(elt); 314 // if we have a delta, that means the transform handles were used and
318 var curMatInv = glmat4.inverse(curMat, []); 315 // we should update the width and height too. Otherwise, just update left and top.
319 316 if(this.delta) {
320 this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); 317 modObject.push({element:element, properties:{left: x, top:y, width: w, height: h}, previousProperties: {left: prevX, top:prevY, width: prevW, height: prevH}});
321 if(addToUndoStack) { 318 } else {
322 var prevX, 319 modObject.push({element:element, properties:{left: x, top:y}, previousProperties: {left: prevX, top:prevY}});
323 prevY, 320 }
324 prevW, 321
325 prevH, 322 } else {
326 _x, 323 // Not using the 3d mode
327 _y, 324 var previousMat = element.elementModel.getProperty("mat").slice(0);
328 _w, 325 var prevW = element.elementModel.getProperty("w");
329 _h, 326 var prevH = element.elementModel.getProperty("h");
330 previousMat, 327 var w = ElementsMediator.getProperty(element, "width");
331 previousStyleStr, 328 var h = ElementsMediator.getProperty(element, "height");
332 newStyleStr; 329
333 330 var previousStyleStr = {dist:element.elementModel.getProperty("dist"), mat:MathUtils.scientificToDecimal(previousMat, 5)};
334 if(!this._use3DMode) { 331 var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)};
335 prevX = this._undoArray[i]._x; 332
336 prevY = this._undoArray[i]._y; 333 modObject.push({element:element, properties:{width: w, height:h}, previousProperties: {width: prevW, height:prevH}});
337 prevW = this._undoArray[i]._w; 334 mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr});
338 prevH = this._undoArray[i]._h;
339 _x = parseInt(ElementsMediator.getProperty(elt, "left"));
340 _y = parseInt(ElementsMediator.getProperty(elt, "top"));
341 _w = parseInt(ElementsMediator.getProperty(elt, "width"));
342 _h = parseInt(ElementsMediator.getProperty(elt, "height"));
343
344 previousLeft.push(prevX + "px");
345 previousTop.push(prevY + "px");
346 previousWidth.push(prevW + "px");
347 previousHeight.push(prevH + "px");
348 newLeft.push(_x + "px");
349 newTop.push(_y + "px");
350 newWidth.push(_w + "px");
351 newHeight.push(_h + "px");
352 }
353 else
354 {
355 previousMat = this._undoArray[i].mat.slice(0);
356 prevW = this._undoArray[i]._w;
357 prevH = this._undoArray[i]._h;
358 _w = parseInt(ElementsMediator.getProperty(elt, "width"));
359 _h = parseInt(ElementsMediator.getProperty(elt, "height"));
360 previousWidth.push(prevW + "px");
361 previousHeight.push(prevH + "px");
362 newWidth.push(_w + "px");
363 newHeight.push(_h + "px");
364
365 previousStyleStr = {dist:this._undoArray[i].dist,
366 mat:MathUtils.scientificToDecimal(previousMat, 5)};
367 newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt),
368 mat:MathUtils.scientificToDecimal(curMat, 5)};
369 previousStyles.push(previousStyleStr);
370 newStyles.push(newStyleStr);
371
372 this._targets[i].mat = curMat;
373 this._targets[i].matInv = curMatInv;
374 }
375 }
376 }
377 if(addToUndoStack)
378 {
379 if(!this._use3DMode)
380 {
381 // if we have a delta, that means the transform handles were used and
382 // we should update the width and height too. Otherwise, just update left and top.
383 if(this._delta)
384 {
385 ElementsMediator.setProperties(this.application.ninja.selectedElements,
386 { "left": newLeft, "top": newTop, "width": newWidth, "height": newHeight },
387 "Change",
388 "selectionTool",
389 { "left" : previousLeft, "top" : previousTop, "width": previousWidth, "height": previousHeight}
390 );
391 }
392 else
393 {
394 ElementsMediator.setProperties(this.application.ninja.selectedElements,
395 { "left": newLeft, "top": newTop },
396 "Change",
397 "selectionTool",
398 { "left" : previousLeft, "top" : previousTop }
399 );
400 } 335 }
401 } 336 }
402 else 337 });
403 { 338
339 // Move them
340 if(addToUndo) {
341 if(!this._use3DMode) {
342 ElementsMediator.setProperties(modObject, "Change", "SelectionTool" );
343 } else {
404 // TODO - We don't support transform handles in 3d space for now 344 // TODO - We don't support transform handles in 3d space for now
405 ElementsMediator.setProperties(this.application.ninja.selectedElements, 345 ElementsMediator.setProperties(modObject, "Change", "SelectionTool" );
406 { "width": newWidth, "height": newHeight }, 346 ElementsMediator.set3DProperties(mod3dObject, "Change", "translateTool");
407 "Change", 347
408 "selectionTool",
409 { "width": previousWidth, "height": previousHeight}
410 );
411 ElementsMediator.set3DProperties(this.application.ninja.selectedElements,
412 newStyles,
413 "Change",
414 "translateTool",
415 previousStyles
416 );
417 } 348 }
418 } 349 }
419 // Save previous value for undo/redo 350
420 this._undoArray = []; 351 this.application.ninja.selectedElements.forEach(function(element) {
421 for(i = 0, len = this._targets.length; i < len; i++) 352 element.elementModel.setProperty("x", ElementsMediator.getProperty(element, "left"));
422 { 353 element.elementModel.setProperty("y", ElementsMediator.getProperty(element, "top"));
423 var item = this._targets[i]; 354 element.elementModel.setProperty("w", ElementsMediator.getProperty(element, "width"));
424 _x = parseInt(ElementsMediator.getProperty(item.elt, "left")); 355 element.elementModel.setProperty("h", ElementsMediator.getProperty(element, "height"));
425 _y = parseInt(ElementsMediator.getProperty(item.elt, "top")); 356 element.elementModel.setProperty("mat", viewUtils.getMatrixFromElement(element));
426 _w = parseInt(ElementsMediator.getProperty(item.elt, "width")); 357 element.elementModel.setProperty("matInv", glmat4.inverse(element.elementModel.getProperty("mat"), []));
427 _h = parseInt(ElementsMediator.getProperty(item.elt, "height")); 358 element.elementModel.setProperty("dist", viewUtils.getPerspectiveDistFromElement(element));
428 var _mat = viewUtils.getMatrixFromElement(item.elt); 359 });
429 var _dist = viewUtils.getPerspectiveDistFromElement(item.elt);
430 this._undoArray.push({_x:_x, _y:_y, _w:_w, _h:_h, mat:_mat, dist:_dist});
431 }
432 360
433 } 361 }
434 }, 362 },
435 363
436 _moveElements: { 364 _moveElements: {
437 value: function (transMat) { 365 value: function (transMat) {
438 var len = this._targets.length, 366 var elt, curMat, targets = [];
439 i,
440 item,
441 elt,
442 curMat,
443 newLeft = [],
444