diff options
author | Nivesh Rajbhandari | 2012-04-16 16:06:24 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-04-16 16:06:24 -0700 |
commit | c253192a08b499ea7be46fa5438d273e51f7ec5a (patch) | |
tree | 18a1f0e3679c0eb993a9dedb537035d3861f49ac /js/tools/modifier-tool-base.js | |
parent | e19376c54eedd1f1c457ba405b2f110be376a559 (diff) | |
parent | 4b900ea5cd6bb77eb30cec8c03b9ec9fa662c1e9 (diff) | |
download | ninja-c253192a08b499ea7be46fa5438d273e51f7ec5a.tar.gz |
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'js/tools/modifier-tool-base.js')
-rwxr-xr-x | js/tools/modifier-tool-base.js | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index 80f7d758..de73c861 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js | |||
@@ -9,8 +9,8 @@ var Montage = require("montage/core/core").Montage, | |||
9 | snapManager = require("js/helper-classes/3D/snap-manager").SnapManager, | 9 | snapManager = require("js/helper-classes/3D/snap-manager").SnapManager, |
10 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, | 10 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, |
11 | vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, | 11 | vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, |
12 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, | 12 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils; |
13 | Properties3D = ("js/models/properties-3d").Properties3D; | 13 | // Properties3D = ("js/models/properties-3d").Properties3D; |
14 | 14 | ||
15 | exports.ModifierToolBase = Montage.create(DrawingTool, { | 15 | exports.ModifierToolBase = Montage.create(DrawingTool, { |
16 | 16 | ||
@@ -25,6 +25,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
25 | _snapParam: { value: null }, | 25 | _snapParam: { value: null }, |
26 | _snapIndex: { value: -1 }, | 26 | _snapIndex: { value: -1 }, |
27 | _useQuadPt: { value: false }, | 27 | _useQuadPt: { value: false }, |
28 | _shouldUseQuadPt: { value: false }, | ||
28 | 29 | ||
29 | // we set snapping capabilities depending on the tool. | 30 | // we set snapping capabilities depending on the tool. |
30 | // The following variables are set in a tool's initializeSnapping method called on mouse down. | 31 | // The following variables are set in a tool's initializeSnapping method called on mouse down. |
@@ -134,7 +135,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
134 | var hitRec = snapManager.snap(point.x, point.y, do3DSnap); | 135 | var hitRec = snapManager.snap(point.x, point.y, do3DSnap); |
135 | 136 | ||
136 | // TODO - Check that hitRec's element matches element that browser says we clicked on | 137 | // TODO - Check that hitRec's element matches element that browser says we clicked on |
137 | var elt = this.application.ninja.stage.GetElement(event); | 138 | var elt = this.application.ninja.stage.GetSelectableElement(event); |
138 | if(elt !== hitRec.getElement()) | 139 | if(elt !== hitRec.getElement()) |
139 | { | 140 | { |
140 | hitRec = snapManager.findHitRecordForElement(elt); | 141 | hitRec = snapManager.findHitRecordForElement(elt); |
@@ -175,6 +176,10 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
175 | // } | 176 | // } |
176 | } | 177 | } |
177 | 178 | ||
179 | // only do quadrant snapping if the 4 corners of the element are in the drag plane | ||
180 | var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); | ||
181 | this._shouldUseQuadPt = (sign == 0) | ||
182 | |||
178 | var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); | 183 | var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); |
179 | this._mouseDownHitRec = wpHitRec; | 184 | this._mouseDownHitRec = wpHitRec; |
180 | this._mouseUpHitRec = null; | 185 | this._mouseUpHitRec = null; |
@@ -236,6 +241,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
236 | } | 241 | } |
237 | } | 242 | } |
238 | 243 | ||
244 | //console.log( "ParameterizeSnap: " + paramPt ); | ||
239 | return paramPt; | 245 | return paramPt; |
240 | } | 246 | } |
241 | }, | 247 | }, |
@@ -284,14 +290,16 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
284 | y = x0 + ty*dy, | 290 | y = x0 + ty*dy, |
285 | z = 0.0; | 291 | z = 0.0; |
286 | var localPt = [x,y,z]; | 292 | var localPt = [x,y,z]; |
293 | |||
287 | globalPt = viewUtils.localToGlobal( localPt, elt ); | 294 | globalPt = viewUtils.localToGlobal( localPt, elt ); |
288 | 295 | ||
289 | // add in the delta | 296 | // add in the delta |
290 | var hitPt = this.GetObjectHitPoint(); | 297 | var hitPt = this.GetObjectHitPoint(); |
291 | var scrPt = viewUtils.localToGlobal( hitPt, this._clickedObject ); | 298 | var scrPt = viewUtils.localToGlobal( hitPt, this._clickedObject ); |
292 | var delta = [xEvent-scrPt[0], yEvent-scrPt[1]]; | 299 | var delta = [xEvent-scrPt[0], yEvent-scrPt[1], 0-scrPt[2]]; |
293 | globalPt[0] += delta[0]; | 300 | globalPt[0] += delta[0]; |
294 | globalPt[1] += delta[1]; | 301 | globalPt[1] += delta[1]; |
302 | globalPt[2] += delta[2]; | ||
295 | } | 303 | } |
296 | 304 | ||
297 | return globalPt; | 305 | return globalPt; |
@@ -448,6 +456,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
448 | { | 456 | { |
449 | this.isDrawing = true; | 457 | this.isDrawing = true; |
450 | this.application.ninja.stage.showSelectionBounds = false; | 458 | this.application.ninja.stage.showSelectionBounds = false; |
459 | this._updateTargets(); | ||
451 | 460 | ||
452 | if(this._canSnap) | 461 | if(this._canSnap) |
453 | { | 462 | { |
@@ -517,7 +526,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
517 | 526 | ||
518 | // do the snap | 527 | // do the snap |
519 | var quadPt; | 528 | var quadPt; |
520 | if (mouseIsDown) | 529 | if (mouseIsDown && !do3DSnap && this._shouldUseQuadPt && (this._handleMode === null) && (this._mode === 0)) |
521 | quadPt = this.GetQuadrantSnapPoint(x,y); | 530 | quadPt = this.GetQuadrantSnapPoint(x,y); |
522 | var hitRec = snapManager.snap(x, y, do3DSnap, quadPt ); | 531 | var hitRec = snapManager.snap(x, y, do3DSnap, quadPt ); |
523 | 532 | ||
@@ -552,6 +561,9 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
552 | 561 | ||
553 | // update the target | 562 | // update the target |
554 | this._mouseUpHitRec = hitRec; | 563 | this._mouseUpHitRec = hitRec; |
564 | var pt = hitRec.getScreenPoint(); | ||
565 | this.upPoint.x = pt[0]; | ||
566 | this.upPoint.y = pt[1]; | ||
555 | } | 567 | } |
556 | } | 568 | } |
557 | } | 569 | } |
@@ -579,12 +591,15 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
579 | 591 | ||
580 | this.downPoint.x = null; | 592 | this.downPoint.x = null; |
581 | this.downPoint.y = null; | 593 | this.downPoint.y = null; |
594 | this.upPoint.x = null; | ||
595 | this.upPoint.y = null; | ||
582 | // this.isDrawing = false; | 596 | // this.isDrawing = false; |
583 | 597 | ||
584 | if(this._canSnap) | 598 | if(this._canSnap) |
585 | { | 599 | { |
586 | this.cleanupSnap(); | 600 | this.cleanupSnap(); |
587 | } | 601 | } |
602 | this._mode = 0; | ||
588 | } | 603 | } |
589 | }, | 604 | }, |
590 | 605 | ||
@@ -751,6 +766,11 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
751 | snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() ); | 766 | snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() ); |
752 | this.eventManager.removeEventListener( "toolOptionsChange", this, false); | 767 | this.eventManager.removeEventListener( "toolOptionsChange", this, false); |
753 | this.eventManager.removeEventListener( "toolDoubleClick", this, false); | 768 | this.eventManager.removeEventListener( "toolDoubleClick", this, false); |
769 | |||
770 | if (this._targetedElement) { | ||
771 | this._targetedElement.classList.remove("active-element-outline"); | ||
772 | this._targetedElement = null; | ||
773 | } | ||
754 | } | 774 | } |
755 | } | 775 | } |
756 | }, | 776 | }, |
@@ -764,20 +784,22 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
764 | captureSelectionDrawn: { | 784 | captureSelectionDrawn: { |
765 | value: function(event){ | 785 | value: function(event){ |
766 | this._targets = []; | 786 | this._targets = []; |
787 | this._origin = null; | ||
788 | this._delta = null; | ||
767 | 789 | ||
768 | var len = this.application.ninja.selectedElements.length; | 790 | var len = this.application.ninja.selectedElements.length; |
769 | if(len) | 791 | if(len) |
770 | { | 792 | { |
771 | if(len === 1) | 793 | if(len === 1) |
772 | { | 794 | { |
773 | this.target = this.application.ninja.selectedElements[0]._element; | 795 | this.target = this.application.ninja.selectedElements[0]; |
774 | drawUtils.addElement(this.target); | 796 | drawUtils.addElement(this.target); |
775 | } | 797 | } |
776 | else | 798 | else |
777 | { | 799 | { |
778 | this.target = this.application.ninja.currentDocument.documentRoot; | 800 | this.target = this.application.ninja.currentDocument.documentRoot; |
779 | } | 801 | } |
780 | this._updateTargets(); | 802 | // this._updateTargets(); |
781 | } | 803 | } |
782 | else | 804 | else |
783 | { | 805 | { |
@@ -798,6 +820,8 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
798 | HandleLeftButtonDown: { | 820 | HandleLeftButtonDown: { |
799 | value: function(event) { | 821 | value: function(event) { |
800 | 822 | ||
823 | // console.log( "modifier-tool-base.HandleLeftButtonDown" ); | ||
824 | |||
801 | var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); | 825 | var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); |
802 | this.downPoint.x = point.x; | 826 | this.downPoint.x = point.x; |
803 | this.downPoint.y = point.y; | 827 | this.downPoint.y = point.y; |
@@ -866,7 +890,6 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
866 | this._updateTargets(true); | 890 | this._updateTargets(true); |
867 | } | 891 | } |
868 | 892 | ||
869 | this.endDraw(event); | ||
870 | this._hasDraw = false; | 893 | this._hasDraw = false; |
871 | } | 894 | } |
872 | if(this._handleMode !== null) | 895 | if(this._handleMode !== null) |
@@ -874,6 +897,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
874 | this._handleMode = null; | 897 | this._handleMode = null; |
875 | this._delta = null; | 898 | this._delta = null; |
876 | } | 899 | } |
900 | this.endDraw(event); | ||
877 | this.DrawHandles(); | 901 | this.DrawHandles(); |
878 | } | 902 | } |
879 | }, | 903 | }, |
@@ -998,19 +1022,6 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { | |||
998 | } | 1022 | } |