diff options
Diffstat (limited to 'js/tools/SelectionTool.js')
-rwxr-xr-x | js/tools/SelectionTool.js | 114 |
1 files changed, 79 insertions, 35 deletions
diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js index 4bafa12a..ed92b893 100755 --- a/js/tools/SelectionTool.js +++ b/js/tools/SelectionTool.js | |||
@@ -49,6 +49,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { | |||
49 | 49 | ||
50 | startDraw: { | 50 | startDraw: { |
51 | value: function(event) { | 51 | value: function(event) { |
52 | this.drawData = null; | ||
53 | |||
52 | if(!this.application.ninja.selectedElements.length) | 54 | if(!this.application.ninja.selectedElements.length) |
53 | { | 55 | { |
54 | this._isSelecting = true; | 56 | this._isSelecting = true; |
@@ -399,7 +401,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { | |||
399 | //Routines to modify the selected objects | 401 | //Routines to modify the selected objects |
400 | modifyElements : { | 402 | modifyElements : { |
401 | value : function(data, event) { | 403 | value : function(data, event) { |
402 | var delta, deltaH = [], deltaW = [], modObject = []; | 404 | var delta, modObject = [], left, top, width, height; |
403 | 405 | ||
404 | if(this._handleMode !== null) { | 406 | if(this._handleMode !== null) { |
405 | // 0 7 6 | 407 | // 0 7 6 |
@@ -411,92 +413,134 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { | |||
411 | // Resize North-West | 413 | // Resize North-West |
412 | this.application.ninja.selectedElements.forEach(function(element) { | 414 | this.application.ninja.selectedElements.forEach(function(element) { |
413 | delta = ~~(data.pt1[0] - data.pt0[0]); | 415 | delta = ~~(data.pt1[0] - data.pt0[0]); |
414 | var width = parseInt(element.elementModel.getProperty("w")) - delta + "px"; | 416 | width = parseInt(element.elementModel.getProperty("w")) - delta; |
415 | var left = parseInt(element.elementModel.getProperty("x")) + delta + "px"; | 417 | if(width <= 0) { |
418 | width = 1; | ||
419 | left = parseInt(element.elementModel.getProperty("x")) + parseInt(element.elementModel.getProperty("w")) - 1; | ||
420 | } else { | ||
421 | left = parseInt(element.elementModel.getProperty("x")) + delta; | ||
422 | } | ||
423 | |||
416 | delta = ~~(data.pt1[1] - data.pt0[1]); | 424 | delta = ~~(data.pt1[1] - data.pt0[1]); |
417 | var height = parseInt(element.elementModel.getProperty("h")) - delta + "px"; | 425 | height = parseInt(element.elementModel.getProperty("h")) - delta; |
418 | var top = parseInt(element.elementModel.getProperty("y")) + delta + "px"; | 426 | if(height <= 0) { |
419 | modObject.push({element:element, properties:{width: width, height: height, left: left, top: top}}); | 427 | height = 1; |
428 | top = parseInt(element.elementModel.getProperty("y")) + parseInt(element.elementModel.getProperty("h")) - 1; | ||
429 | } else { | ||
430 | top = parseInt(element.elementModel.getProperty("y")) + delta; | ||
431 | } | ||
432 | modObject.push({element:element, properties:{width: width + "px", height: height + "px", left: left + "px", top: top + "px"}}); | ||
420 | }); | 433 | }); |
421 | ElementsMediator.setProperties(modObject, "Changing", "SelectionTool" ); | ||
422 | break; | 434 | break; |
423 | case 1: | 435 | case 1: |
424 | // Resize West | 436 | // Resize West |
425 | this.application.ninja.selectedElements.forEach(function(element) { | 437 | this.application.ninja.selectedElements.forEach(function(element) { |
426 | delta = ~~(data.pt1[0] - data.pt0[0]); | 438 | delta = ~~(data.pt1[0] - data.pt0[0]); |
427 | var width = parseInt(element.elementModel.getProperty("w")) - delta + "px"; | 439 | width = parseInt(element.elementModel.getProperty("w")) - delta; |
428 | var left = parseInt(element.elementModel.getProperty("x")) + delta + "px"; | 440 | if(width <= 0) { |
429 | modObject.push({element:element, properties:{left: left, width: width}}); | 441 | width = 1; |
442 | left = parseInt(element.elementModel.getProperty("x")) + parseInt(element.elementModel.getProperty("w")) - 1; | ||
443 | } else { | ||
444 | left = parseInt(element.elementModel.getProperty("x")) + delta; | ||
445 | } | ||
446 | modObject.push({element:element, properties:{left: left + "px", width: width + "px"}}); | ||
430 | }); | 447 | }); |
431 | ElementsMediator.setProperties(modObject, "Changing", "SelectionTool"); | ||
432 | break; | 448 | break; |
433 | case 2: | 449 | case 2: |
434 | // Resize South-West | 450 | // Resize South-West |
435 | this.application.ninja.selectedElements.forEach(function(element) { | 451 | this.application.ninja.selectedElements.forEach(function(element) { |
436 | delta = ~~(data.pt1[0] - data.pt0[0]); | 452 | delta = ~~(data.pt1[0] - data.pt0[0]); |
437 | var width = parseInt(element.elementModel.getProperty("w")) - delta + "px"; | 453 | width = parseInt(element.elementModel.getProperty("w")) - delta; |
438 | var left = parseInt(element.elementModel.getProperty("x")) + delta + "px"; | 454 | if(width <= 0) { |
455 | width = 1; | ||
456 | left = parseInt(element.elementModel.getProperty("x")) + parseInt(element.elementModel.getProperty("w")) - 1; | ||
457 | } else { | ||
458 | left = parseInt(element.elementModel.getProperty("x")) + delta; | ||
459 | } | ||
439 | delta = ~~(data.pt1[1] - data.pt0[1]); | 460 | delta = ~~(data.pt1[1] - data.pt0[1]); |
440 | var height = parseInt(element.elementModel.getProperty("h")) + delta + "px"; | 461 | height = parseInt(element.elementModel.getProperty("h")) + delta; |
441 | modObject.push({element:element, properties:{width: width, height: height, left: left}}); | 462 | if(height <= 0) { |
463 | height = 1; | ||
464 | } | ||
465 | modObject.push({element:element, properties:{width: width + "px", height: height + "px", left: left + "px"}}); | ||
442 | }); | 466 | }); |
443 | ElementsMediator.setProperties(modObject, "Changing", "SelectionTool" ); | ||
444 | break; | 467 | break; |
445 | case 3: | 468 | case 3: |
446 | // Resize South | 469 | // Resize South |
447 | this.application.ninja.selectedElements.forEach(function(element) { | 470 | this.application.ninja.selectedElements.forEach(function(element) { |
448 | delta = ~~(data.pt1[1] - data.pt0[1]); | 471 | delta = ~~(data.pt1[1] - data.pt0[1]); |
449 | deltaH.push(parseInt(element.elementModel.getProperty("h")) + delta + "px"); | 472 | height = parseInt(element.elementModel.getProperty("h")) + delta; |
450 | // modObject.push({element:element, properties:{width: width, height: height}}); | 473 | if(height <= 0) { |
474 | height = 1; | ||
475 | } | ||
476 | modObject.push({element:element, properties:{height: height + "px"}}); | ||
451 | }); | 477 | }); |
452 | ElementsMediator.setProperty(this.application.ninja.selectedElements, "height", deltaH, "Changing", "SelectionTool" ); | ||
453 | break; | 478 | break; |
454 | case 4: | 479 | case 4: |
455 | // Resize South-East | 480 | // Resize South-East |
456 | this.application.ninja.selectedElements.forEach(function(element) { | 481 | this.application.ninja.selectedElements.forEach(function(element) { |
457 | delta = ~~(data.pt1[0] - data.pt0[0]); | 482 | delta = ~~(data.pt1[0] - data.pt0[0]); |
458 | var width = parseInt(element.elementModel.getProperty("w")) + delta + "px"; | 483 | width = parseInt(element.elementModel.getProperty("w")) + delta; |
484 | if(width <= 0) { | ||
485 | width = 1; | ||
486 | } | ||
459 | delta = ~~(data.pt1[1] - data.pt0[1]); | 487 | delta = ~~(data.pt1[1] - data.pt0[1]); |
460 | var height = parseInt(element.elementModel.getProperty("h")) + delta + "px"; | 488 | height = parseInt(element.elementModel.getProperty("h")) + delta; |
461 | modObject.push({element:element, properties:{width: width, height: height}}); | 489 | if(height <= 0) { |
490 | height = 1; | ||
491 | } | ||
492 | modObject.push({element:element, properties:{width: width + "px", height: height + "px"}}); | ||
462 | }); | 493 | }); |
463 | ElementsMediator.setProperties(modObject, "Changing", "SelectionTool" ); | ||
464 | break; | 494 | break; |
465 | case 5: | 495 | case 5: |
466 | // Resize East | 496 | // Resize East |
467 | this.application.ninja.selectedElements.forEach(function(element) { | 497 | this.application.ninja.selectedElements.forEach(function(element) { |
468 | delta = ~~(data.pt1[0] - data.pt0[0]); | 498 | delta = ~~(data.pt1[0] - data.pt0[0]); |
469 | deltaW.push(parseInt(element.elementModel.getProperty("w")) + delta + "px"); | 499 | width = parseInt(element.elementModel.getProperty("w")) + delta; |
470 | // modObject.push({element:element, properties:{width: width, height: height}}); | 500 | if(width <= 0) { |
501 | width = 1; | ||
502 | } | ||
503 | modObject.push({element:element, properties:{width: width + "px"}}); | ||
471 | }); | 504 | }); |
472 | ElementsMediator.setProperty(this.application.ninja.selectedElements, "width", deltaW, "Changing", "SelectionTool" ); | ||
473 | break; | 505 | break; |
474 | case 6: | 506 | case 6: |
475 | // Resize North-East | 507 | // Resize North-East |
476 | this.application.ninja.selectedElements.forEach(function(element) { | 508 | this.application.ninja.selectedElements.forEach(function(element) { |
477 | delta = ~~(data.pt1[0] - data.pt0[0]); | 509 | delta = ~~(data.pt1[0] - data.pt0[0]); |
478 | var width = parseInt(element.elementModel.getProperty("w")) + delta + "px"; | 510 | width = parseInt(element.elementModel.getProperty("w")) + delta; |
511 | if(width <= 0) { | ||
512 | width = 1; | ||
513 | } | ||
479 | delta = ~~(data.pt1[1] - data.pt0[1]); | 514 | delta = ~~(data.pt1[1] - data.pt0[1]); |
480 | var height = parseInt(element.elementModel.getProperty("h")) - delta + "px"; | 515 | height = parseInt(element.elementModel.getProperty("h")) - delta; |
481 | var top = parseInt(element.elementModel.getProperty("y")) + delta + "px"; | 516 | if(height <= 0) { |
482 | modObject.push({element:element, properties:{width: width, height: height, top: top}}); | 517 | height = 1; |
518 | top = parseInt(element.elementModel.getProperty("y")) + parseInt(element.elementModel.getProperty("h")) - 1; | ||
519 | } else { | ||
520 | top = parseInt(element.elementModel.getProperty("y")) + delta; | ||
521 | } | ||
522 | modObject.push({element:element, properties:{width: width + "px", height: height + "px", top: top + "px"}}); | ||
483 | }); | 523 | }); |
484 | ElementsMediator.setProperties(modObject, "Changing", "SelectionTool" ); | ||
485 | break; | 524 | break; |
486 | case 7: | 525 | case 7: |
487 | // Resize North | 526 | // Resize North |
488 | this.application.ninja.selectedElements.forEach(function(element) { | 527 | this.application.ninja.selectedElements.forEach(function(element) { |
489 | delta = ~~(data.pt1[1] - data.pt0[1]); | 528 | delta = ~~(data.pt1[1] - data.pt0[1]); |
490 | var height = parseInt(element.elementModel.getProperty("h")) - delta + "px"; | 529 | height = parseInt(element.elementModel.getProperty("h")) - delta; |
491 | var top = parseInt(element.elementModel.getProperty("y")) + delta + "px"; | 530 | if(height <= 0) { |
492 | modObject.push({element:element, properties:{height: height, top: top}}); | 531 | height = 1; |
532 | top = parseInt(element.elementModel.getProperty("y")) + parseInt(element.elementModel.getProperty("h")) - 1; | ||
533 | } else { | ||
534 | top = parseInt(element.elementModel.getProperty("y")) + delta; | ||
535 | } | ||
536 | modObject.push({element:element, properties:{height: height + "px", top: top + "px"}}); | ||
493 | }); | 537 | }); |
494 | ElementsMediator.setProperties(modObject, "Changing", "SelectionTool" ); | ||
495 | break; | 538 | break; |
496 | default: | 539 | default: |
497 | break; | 540 | break; |
498 | } | 541 | } |
499 | 542 | ||
543 | ElementsMediator.setProperties(modObject, "Changing", "SelectionTool" ); | ||
500 | this._delta = delta; | 544 | this._delta = delta; |
501 | } | 545 | } |
502 | else | 546 | else |