aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorValerio Virgillito2012-06-05 16:20:20 -0700
committerValerio Virgillito2012-06-05 16:20:20 -0700
commit18e212dca48066d1ddaca96875a3f40adcc859b6 (patch)
treedf4ddb09c1625101b3018c418f4681ba572300c7 /js
parentb23a684a6aba38946867463bbbf4184ba2a2ff4a (diff)
parent3bf45fbac80bb3eac7ed6493cfe136899760b497 (diff)
downloadninja-18e212dca48066d1ddaca96875a3f40adcc859b6.tar.gz
Merge pull request #273 from mqg734/TransformTool
Free Transform tool's handle should stop when it reaches the other end.
Diffstat (limited to 'js')
-rwxr-xr-xjs/tools/SelectionTool.js112
1 files changed, 77 insertions, 35 deletions
diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js
index 4bafa12a..7b72a857 100755
--- a/js/tools/SelectionTool.js
+++ b/js/tools/SelectionTool.js
@@ -399,7 +399,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
399 //Routines to modify the selected objects 399 //Routines to modify the selected objects
400 modifyElements : { 400 modifyElements : {
401 value : function(data, event) { 401 value : function(data, event) {
402 var delta, deltaH = [], deltaW = [], modObject = []; 402 var delta, modObject = [], left, top, width, height;
403 403
404 if(this._handleMode !== null) { 404 if(this._handleMode !== null) {
405 // 0 7 6 405 // 0 7 6
@@ -411,92 +411,134 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
411 // Resize North-West 411 // Resize North-West
412 this.application.ninja.selectedElements.forEach(function(element) { 412 this.application.ninja.selectedElements.forEach(function(element) {
413 delta = ~~(data.pt1[0] - data.pt0[0]); 413 delta = ~~(data.pt1[0] - data.pt0[0]);
414 var width = parseInt(element.elementModel.getProperty("w")) - delta + "px"; 414 width = parseInt(element.elementModel.getProperty("w")) - delta;
415 var left = parseInt(element.elementModel.getProperty("x")) + delta + "px"; 415 if(width <= 0) {
416 width = 1;
417 left = parseInt(element.elementModel.getProperty("x")) + parseInt(element.elementModel.getProperty("w")) - 1;
418 } else {
419 left = parseInt(element.elementModel.getProperty("x")) + delta;
420 }
421
416 delta = ~~(data.pt1[1] - data.pt0[1]); 422 delta = ~~(data.pt1[1] - data.pt0[1]);
417 var height = parseInt(element.elementModel.getProperty("h")) - delta + "px"; 423 height = parseInt(element.elementModel.getProperty("h")) - delta;
418 var top = parseInt(element.elementModel.getProperty("y")) + delta + "px"; 424 if(height <= 0) {
419 modObject.push({element:element, properties:{width: width, height: height, left: left, top: top}}); 425 height = 1;
426 top = parseInt(element.elementModel.getProperty("y")) + parseInt(element.elementModel.getProperty("h")) - 1;
427 } else {
428 top = parseInt(element.elementModel.getProperty("y")) + delta;
429 }
430 modObject.push({element:element, properties:{width: width + "px", height: height + "px", left: left + "px", top: top + "px"}});
420 }); 431 });
421 ElementsMediator.setProperties(modObject, "Changing", "SelectionTool" );
422 break; 432 break;
423 case 1: 433 case 1:
424 // Resize West 434 // Resize West
425 this.application.ninja.selectedElements.forEach(function(element) { 435 this.application.ninja.selectedElements.forEach(function(element) {
426 delta = ~~(data.pt1[0] - data.pt0[0]); 436 delta = ~~(data.pt1[0] - data.pt0[0]);
427 var width = parseInt(element.elementModel.getProperty("w")) - delta + "px"; 437 width = parseInt(element.elementModel.getProperty("w")) - delta;
428 var left = parseInt(element.elementModel.getProperty("x")) + delta + "px"; 438 if(width <= 0) {
429 modObject.push({element:element, properties:{left: left, width: width}}); 439 width = 1;
440 left = parseInt(element.elementModel.getProperty("x")) + parseInt(element.elementModel.getProperty("w")) - 1;
441 } else {
442 left = parseInt(element.elementModel.getProperty("x")) + delta;
443 }
444 modObject.push({element:element, properties:{left: left + "px", width: width + "px"}});
430 }); 445 });
431 ElementsMediator.setProperties(modObject, "Changing", "SelectionTool");
432 break; 446 break;
433 case 2: 447 case 2:
434 // Resize South-West 448 // Resize South-West
435 this.application.ninja.selectedElements.forEach(function(element) { 449 this.application.ninja.selectedElements.forEach(function(element) {
436 delta = ~~(data.pt1[0] - data.pt0[0]); 450 delta = ~~(data.pt1[0] - data.pt0[0]);
437 var width = parseInt(element.elementModel.getProperty("w")) - delta + "px"; 451 width = parseInt(element.elementModel.getProperty("w")) - delta;
438 var left = parseInt(element.elementModel.getProperty("x")) + delta + "px"; 452 if(width <= 0) {
453 width = 1;
454 left = parseInt(element.elementModel.getProperty("x")) + parseInt(element.elementModel.getProperty("w")) - 1;
455 } else {
456 left = parseInt(element.elementModel.getProperty("x")) + delta;
457 }
439 delta = ~~(data.pt1[1] - data.pt0[1]); 458 delta = ~~(data.pt1[1] - data.pt0[1]);
440 var height = parseInt(element.elementModel.getProperty("h")) + delta + "px"; 459 height = parseInt(element.elementModel.getProperty("h")) + delta;
441 modObject.push({element:element, properties:{width: width, height: height, left: left}}); 460 if(height <= 0) {
461 height = 1;
462 }
463 modObject.push({element:element, properties:{width: width + "px", height: height + "px", left: left + "px"}});
442 }); 464 });
443 ElementsMediator.setProperties(modObject, "Changing", "SelectionTool" );
444 break; 465 break;
445 case 3: 466 case 3:
446 // Resize South 467 // Resize South
447 this.application.ninja.selectedElements.forEach(function(element) { 468 this.application.ninja.selectedElements.forEach(function(element) {
448 delta = ~~(data.pt1[1] - data.pt0[1]); 469 delta = ~~(data.pt1[1] - data.pt0[1]);
449 deltaH.push(parseInt(element.elementModel.getProperty("h")) + delta + "px"); 470 height = parseInt(element.elementModel.getProperty("h")) + delta;
450 // modObject.push({element:element, properties:{width: width, height: height}}); 471 if(height <= 0) {
472 height = 1;
473 }
474 modObject.push({element:element, properties:{height: height + "px"}});
451 }); 475 });
452 ElementsMediator.setProperty(this.application.ninja.selectedElements, "height", deltaH, "Changing", "SelectionTool" );
453 break; 476 break;
454 case 4: 477 case 4:
455 // Resize South-East 478 // Resize South-East
456 this.application.ninja.selectedElements.forEach(function(element) { 479 this.application.ninja.selectedElements.forEach(function(element) {
457 delta = ~~(data.pt1[0] - data.pt0[0]); 480 delta = ~~(data.pt1[0] - data.pt0[0]);
458 var width = parseInt(element.elementModel.getProperty("w")) + delta + "px"; 481 width = parseInt(element.elementModel.getProperty("w")) + delta;
482 if(width <= 0) {
483 width = 1;
484 }
459 delta = ~~(data.pt1[1] - data.pt0[1]); 485 delta = ~~(data.pt1[1] - data.pt0[1]);
460 var height = parseInt(element.elementModel.getProperty("h")) + delta + "px"; 486 height = parseInt(element.elementModel.getProperty("h")) + delta;
461 modObject.push({element:element, properties:{width: width, height: height}}); 487 if(height <= 0) {
488 height = 1;
489 }
490 modObject.push({element:element, properties:{width: width + "px", height: height + "px"}});
462 }); 491 });
463 ElementsMediator.setProperties(modObject, "Changing", "SelectionTool" );
464 break; 492 break;
465 case 5: 493 case 5:
466 // Resize East 494 // Resize East
467 this.application.ninja.selectedElements.forEach(function(element) { 495 this.application.ninja.selectedElements.forEach(function(element) {
468 delta = ~~(data.pt1[0] - data.pt0[0]); 496 delta = ~~(data.pt1[0] - data.pt0[0]);
469 deltaW.push(parseInt(element.elementModel.getProperty("w")) + delta + "px"); 497 width = parseInt(element.elementModel.getProperty("w")) + delta;
470 // modObject.push({element:element, properties:{width: width, height: height}}); 498 if(width <= 0) {
499 width = 1;
500 }
501 modObject.push({element:element, properties:{width: width + "px"}});
471 }); 502 });
472 ElementsMediator.setProperty(this.application.ninja.selectedElements, "width", deltaW, "Changing", "SelectionTool" );
473 break; 503 break;
474 case 6: 504 case 6:
475 // Resize North-East 505 // Resize North-East
476 this.application.ninja.selectedElements.forEach(function(element) { 506 this.application.ninja.selectedElements.forEach(function(element) {
477 delta = ~~(data.pt1[0] - data.pt0[0]); 507 delta = ~~(data.pt1[0] - data.pt0[0]);
478 var width = parseInt(element.elementModel.getProperty("w")) + delta + "px"; 508 width = parseInt(element.elementModel.getProperty("w")) + delta;
509 if(width <= 0) {
510 width = 1;
511 }
479 delta = ~~(data.pt1[1] - data.pt0[1]); 512 delta = ~~(data.pt1[1] - data.pt0[1]);
480 var height = parseInt(element.elementModel.getProperty("h")) - delta + "px"; 513 height = parseInt(element.elementModel.getProperty("h")) - delta;
481 var top = parseInt(element.elementModel.getProperty("y")) + delta + "px"; 514 if(height <= 0) {
482 modObject.push({element:element, properties:{width: width, height: height, top: top}}); 515 height = 1;
516 top = parseInt(element.elementModel.getProperty("y")) + parseInt(element.elementModel.getProperty("h")) - 1;
517 } else {
518 top = parseInt(element.elementModel.getProperty("y")) + delta;
519 }
520 modObject.push({element:element, properties:{width: width + "px", height: height + "px", top: top + "px"}});
483 }); 521 });
484 ElementsMediator.setProperties(modObject, "Changing", "SelectionTool" );
485 break; 522 break;
486 case 7: 523 case 7:
487 // Resize North 524 // Resize North
488 this.application.ninja.selectedElements.forEach(function(element) { 525 this.application.ninja.selectedElements.forEach(function(element) {
489 delta = ~~(data.pt1[1] - data.pt0[1]); 526 delta = ~~(data.pt1[1] - data.pt0[1]);
490 var height = parseInt(element.elementModel.getProperty("h")) - delta + "px"; 527 height = parseInt(element.elementModel.getProperty("h")) - delta;
491 var top = parseInt(element.elementModel.getProperty("y")) + delta + "px"; 528 if(height <= 0) {
492 modObject.push({element:element, properties:{height: height, top: top}}); 529 height = 1;
530 top = parseInt(element.elementModel.getProperty("y")) + parseInt(element.elementModel.getProperty("h")) - 1;
531 } else {
532 top = parseInt(element.elementModel.getProperty("y")) + delta;
533 }
534 modObject.push({element:element, properties:{height: height + "px", top: top + "px"}});
493 }); 535 });
494 ElementsMediator.setProperties(modObject, "Changing", "SelectionTool" );
495 break; 536 break;
496 default: 537 default:
497 break; 538 break;
498 } 539 }
499 540
541 ElementsMediator.setProperties(modObject, "Changing", "SelectionTool" );
500 this._delta = delta; 542 this._delta = delta;
501 } 543 }
502 else 544 else