aboutsummaryrefslogtreecommitdiff
path: root/js/tools/SelectionTool.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/SelectionTool.js')
-rwxr-xr-xjs/tools/SelectionTool.js103
1 files changed, 52 insertions, 51 deletions
diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js
index a136113b..07ae8cf5 100755
--- a/js/tools/SelectionTool.js
+++ b/js/tools/SelectionTool.js
@@ -272,7 +272,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
272 272
273 HandleKeyPress: { 273 HandleKeyPress: {
274 value: function(event){ 274 value: function(event){
275 var inc; 275 var inc, newLeft, leftArr, newTop, topArr;
276 276
277 if (!(event.target instanceof HTMLInputElement)) { 277 if (!(event.target instanceof HTMLInputElement)) {
278 if(this.application.ninja.selectedElements.length !== 0) { 278 if(this.application.ninja.selectedElements.length !== 0) {
@@ -280,36 +280,36 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
280 280
281 switch(event.keyCode) { 281 switch(event.keyCode) {
282 case Keyboard.LEFT: 282 case Keyboard.LEFT:
283 var newLeft = []; 283 newLeft = [];
284 var leftArr = this.application.ninja.selectedElements.map(function(item) { 284 leftArr = this.application.ninja.selectedElements.map(function(item) {
285 newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left")) - inc) + "px" ); 285 newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left"), 10) - inc) + "px" );
286 return ElementsMediator.getProperty(item, "left"); 286 return ElementsMediator.getProperty(item, "left");
287 }); 287 });
288 288
289 ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr); 289 ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr);
290 break; 290 break;
291 case Keyboard.UP: 291 case Keyboard.UP:
292 var newTop = []; 292 newTop = [];
293 var topArr = this.application.ninja.selectedElements.map(function(item) { 293 topArr = this.application.ninja.selectedElements.map(function(item) {
294 newTop.push( (parseInt(ElementsMediator.getProperty(item, "top")) - inc) + "px" ); 294 newTop.push( (parseInt(ElementsMediator.getProperty(item, "top"), 10) - inc) + "px" );
295 return ElementsMediator.getProperty(item, "top"); 295 return ElementsMediator.getProperty(item, "top");
296 }); 296 });
297 297
298 ElementsMediator.setProperty(this.application.ninja.selectedElements, "top", newTop , "Change", "selectionTool", topArr); 298 ElementsMediator.setProperty(this.application.ninja.selectedElements, "top", newTop , "Change", "selectionTool", topArr);
299 break; 299 break;
300 case Keyboard.RIGHT: 300 case Keyboard.RIGHT:
301 var newLeft = []; 301 newLeft = [];
302 var leftArr = this.application.ninja.selectedElements.map(function(item) { 302 leftArr = this.application.ninja.selectedElements.map(function(item) {
303 newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left")) + inc) + "px" ); 303 newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left"), 10) + inc) + "px" );
304 return ElementsMediator.getProperty(item, "left"); 304 return ElementsMediator.getProperty(item, "left");
305 }); 305 });
306 306
307 ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr); 307 ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr);
308 break; 308 break;
309 case Keyboard.DOWN: 309 case Keyboard.DOWN:
310 var newTop = []; 310 newTop = [];
311 var topArr = this.application.ninja.selectedElements.map(function(item) { 311 topArr = this.application.ninja.selectedElements.map(function(item) {
312 newTop.push( (parseInt(ElementsMediator.getProperty(item, "top")) + inc) + "px" ); 312 newTop.push( (parseInt(ElementsMediator.getProperty(item, "top"), 10) + inc) + "px" );
313 return ElementsMediator.getProperty(item, "top"); 313 return ElementsMediator.getProperty(item, "top");
314 }); 314 });
315 315
@@ -317,7 +317,6 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
317 break; 317 break;
318 default: 318 default:
319 return false; 319 return false;
320 break;
321 } 320 }
322 321
323 322
@@ -339,17 +338,17 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
339 var modObject = [], mod3dObject = [], self = this; 338 var modObject = [], mod3dObject = [], self = this;
340 339
341 this.application.ninja.selectedElements.forEach(function(element) { 340 this.application.ninja.selectedElements.forEach(function(element) {
342 341 var prevW, prevH, w, h;
343 if(addToUndo) { 342 if(addToUndo) {
344 if(!self._use3DMode) { 343 if(!self._use3DMode) {
345 var prevX = element.elementModel.getProperty("x"); 344 var prevX = element.elementModel.getProperty("x");
346 var prevY = element.elementModel.getProperty("y"); 345 var prevY = element.elementModel.getProperty("y");
347 var prevW = element.elementModel.getProperty("w"); 346 prevW = element.elementModel.getProperty("w");
348 var prevH = element.elementModel.getProperty("h"); 347 prevH = element.elementModel.getProperty("h");
349 var x = ElementsMediator.getProperty(element, "left"); 348 var x = ElementsMediator.getProperty(element, "left");
350 var y = ElementsMediator.getProperty(element, "top"); 349 var y = ElementsMediator.getProperty(element, "top");
351 var w = ElementsMediator.getProperty(element, "width"); 350 w = ElementsMediator.getProperty(element, "width");
352 var h = ElementsMediator.getProperty(element, "height"); 351 h = ElementsMediator.getProperty(element, "height");
353 352
354 // if we have a delta, that means the transform handles were used and 353 // if we have a delta, that means the transform handles were used and
355 // we should update the width and height too. Otherwise, just update left and top. 354 // we should update the width and height too. Otherwise, just update left and top.
@@ -362,10 +361,10 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
362 } else { 361 } else {
363 // Not using the 3d mode 362 // Not using the 3d mode
364 var previousMat = element.elementModel.getProperty("mat").slice(0); 363 var previousMat = element.elementModel.getProperty("mat").slice(0);
365 var prevW = element.elementModel.getProperty("w"); 364 prevW = element.elementModel.getProperty("w");
366 var prevH = element.elementModel.getProperty("h"); 365 prevH = element.elementModel.getProperty("h");
367 var w = ElementsMediator.getProperty(element, "width"); 366 w = ElementsMediator.getProperty(element, "width");
368 var h = ElementsMediator.getProperty(element, "height"); 367 h = ElementsMediator.getProperty(element, "height");
369 368
370 var previousStyleStr = {dist:element.elementModel.getProperty("dist"), mat:MathUtils.scientificToDecimal(previousMat, 5)}; 369 var previousStyleStr = {dist:element.elementModel.getProperty("dist"), mat:MathUtils.scientificToDecimal(previousMat, 5)};
371 var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)}; 370 var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)};
@@ -421,8 +420,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
421 viewUtils.setMatrixForElement( element, curMat, true); 420 viewUtils.setMatrixForElement( element, curMat, true);
422 element.elementModel.setProperty("mat", curMat); 421 element.elementModel.setProperty("mat", curMat);
423 } else { 422 } else {
424 var x = (parseInt(ElementsMediator.getProperty(element, "left")) + transMat[12]) + "px"; 423 var x = (parseInt(ElementsMediator.getProperty(element, "left"), 10) + transMat[12]) + "px";
425 var y = (parseInt(ElementsMediator.getProperty(element, "top")) + transMat[13]) + "px"; 424 var y = (parseInt(ElementsMediator.getProperty(element, "top"), 10) + transMat[13]) + "px";
426 425
427 targets.push({element:element, properties:{left:x , top:y}}); 426 targets.push({element:element, properties:{left:x , top:y}});
428 } 427 }
@@ -452,21 +451,21 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
452 // Resize North-West 451 // Resize North-West
453 this.application.ninja.selectedElements.forEach(function(element) { 452 this.application.ninja.selectedElements.forEach(function(element) {
454 delta = ~~(data.pt1[0] - data.pt0[0]); 453 delta = ~~(data.pt1[0] - data.pt0[0]);
455 width = parseInt(element.elementModel.getProperty("w")) - delta; 454 width = parseInt(element.elementModel.getProperty("w"), 10) - delta;
456 if(width <= 0) { 455 if(width <= 0) {
457 width = 1; 456 width = 1;
458 left = parseInt(element.elementModel.getProperty("x")) + parseInt(element.elementModel.getProperty("w")) - 1; 457 left = parseInt(element.elementModel.getProperty("x"), 10) + parseInt(element.elementModel.getProperty("w"), 10) - 1;
459 } else { 458 } else {
460 left = parseInt(element.elementModel.getProperty("x")) + delta; 459 left = parseInt(element.elementModel.getProperty("x"), 10) + delta;
461 } 460 }
462 461
463 delta = ~~(data.pt1[1] - data.pt0[1]); 462 delta = ~~(data.pt1[1] - data.pt0[1]);
464 height = parseInt(element.elementModel.getProperty("h")) - delta; 463 height = parseInt(element.elementModel.getProperty("h"), 10) - delta;
465 if(height <= 0) { 464 if(height <= 0) {
466 height = 1; 465 height = 1;
467 top = parseInt(element.elementModel.getProperty("y")) + parseInt(element.elementModel.getProperty("h")) - 1; 466 top = parseInt(element.elementModel.getProperty("y"), 10) + parseInt(element.elementModel.getProperty("h"), 10) - 1;
468 } else { 467 } else {
469 top = parseInt(element.elementModel.getProperty("y")) + delta; 468 top = parseInt(element.elementModel.getProperty("y"), 10) + delta;
470 } 469 }
471 modObject.push({element:element, properties:{width: width + "px", height: height + "px", left: left + "px", top: top + "px"}}); 470 modObject.push({element:element, properties:{width: width + "px", height: height + "px", left: left + "px", top: top + "px"}});
472 }); 471 });
@@ -475,12 +474,12 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
475 // Resize West 474 // Resize West
476 this.application.ninja.selectedElements.forEach(function(element) { 475 this.application.ninja.selectedElements.forEach(function(element) {
477 delta = ~~(data.pt1[0] - data.pt0[0]); 476 delta = ~~(data.pt1[0] - data.pt0[0]);
478 width = parseInt(element.elementModel.getProperty("w")) - delta; 477 width = parseInt(element.elementModel.getProperty("w"), 10) - delta;
479 if(width <= 0) { 478 if(width <= 0) {
480 width = 1; 479 width = 1;
481 left = parseInt(element.elementModel.getProperty("x")) + parseInt(element.elementModel.getProperty("w")) - 1; 480 left = parseInt(element.elementModel.getProperty("x"), 10) + parseInt(element.elementModel.getProperty("w"), 10) - 1;
482 } else { 481 } else {
483 left = parseInt(element.elementModel.getProperty("x")) + delta; 482 left = parseInt(element.elementModel.getProperty("x"), 10) + delta;
484 } 483 }
485 modObject.push({element:element, properties:{left: left + "px", width: width + "px"}}); 484 modObject.push({element:element, properties:{left: left + "px", width: width + "px"}});
486 }); 485 });
@@ -489,15 +488,15 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
489 // Resize South-West 488 // Resize South-West
490 this.application.ninja.selectedElements.forEach(function(element) { 489 this.application.ninja.selectedElements.forEach(function(element) {
491 delta = ~~(data.pt1[0] - data.pt0[0]); 490 delta = ~~(data.pt1[0] - data.pt0[0]);
492 width = parseInt(element.elementModel.getProperty("w")) - delta; 491 width = parseInt(element.elementModel.getProperty("w"), 10) - delta;
493 if(width <= 0) { 492 if(width <= 0) {
494 width = 1; 493 width = 1;
495 left = parseInt(element.elementModel.getProperty("x")) + parseInt(element.elementModel.getProperty("w")) - 1; 494 left = parseInt(element.elementModel.getProperty("x"), 10) + parseInt(element.elementModel.getProperty("w"), 10) - 1;
496 } else { 495 } else {
497 left = parseInt(element.elementModel.getProperty("x")) + delta; 496 left = parseInt(element.elementModel.getProperty("x"), 10) + delta;
498 } 497 }
499 delta = ~~(data.pt1[1] - data.pt0[1]); 498 delta = ~~(data.pt1[1] - data.pt0[1]);
500 height = parseInt(element.elementModel.getProperty("h")) + delta; 499 height = parseInt(element.elementModel.getProperty("h"), 10) + delta;
501 if(height <= 0) { 500 if(height <= 0) {
502 height = 1; 501 height = 1;
503 } 502 }
@@ -508,7 +507,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
508 // Resize South