aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
authorPushkar Joshi2012-04-19 14:12:45 -0700
committerPushkar Joshi2012-04-19 14:12:45 -0700
commit9f32d7e5454db3189209fc68a286a7fdb0c31fe8 (patch)
treea51c2bf67839a25158c30752b44fdea0eac28b9d /js/tools
parentdc1e8dde18c40cf740bd2fe09165784e0d415fab (diff)
parent6d33345a9e609e36539d2efa25569f5eeb04a2af (diff)
downloadninja-9f32d7e5454db3189209fc68a286a7fdb0c31fe8.tar.gz
Merge branch 'master' into pentool
Conflicts: js/helper-classes/3D/view-utils.js
Diffstat (limited to 'js/tools')
-rwxr-xr-xjs/tools/Rotate3DToolBase.js386
-rwxr-xr-xjs/tools/RotateObject3DTool.js4
-rwxr-xr-xjs/tools/RotateStage3DTool.js7
-rwxr-xr-xjs/tools/Translate3DToolBase.js134
-rwxr-xr-xjs/tools/TranslateObject3DTool.js1
-rwxr-xr-xjs/tools/modifier-tool-base.js17
6 files changed, 475 insertions, 74 deletions
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js
index 2e121b0b..4fa8657e 100755
--- a/js/tools/Rotate3DToolBase.js
+++ b/js/tools/Rotate3DToolBase.js
@@ -25,6 +25,149 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
25 value: false 25 value: false
26 }, 26 },
27 27
28 initializeSnapping : {
29 value : function(event)
30 {
31// console.log( "initializeSnapping" );
32
33 var selectedElements = this.application.ninja.selectedElements;
34 if(this.rotateStage) {
35 selectedElements = [this.application.ninja.currentDocument.documentRoot];
36 }
37
38 this._mouseDownHitRec = null;
39 this._mouseUpHitRec = null;
40
41 snapManager.clearAvoidList();
42 snapManager.clearDragPlane();
43
44 // the translate tool does snap align to the bounds of the object only.
45 // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method
46 snapManager.enableSnapAlign( false );
47
48 // snap to element and snap to grid are conditionally enabled based
49 // on the snap results of the mouse down. enable everything for the first snap
50 this._snapToElements = snapManager.elementSnapEnabledAppLevel();
51 this._snapToGrid = snapManager.gridSnapEnabledAppLevel();
52
53 this._dragPlane = null;
54 this._clickedOnStage = false;
55 var do3DSnap = true;
56
57 if(this._handleMode === null)
58 {
59 snapManager.enableElementSnap ( true );
60 snapManager.enableGridSnap ( true );
61 }
62// else
63// {
64// this._delta = null;
65 // special case for z-translation
66// if(this._handleMode === 0)
67// {
68// this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target);
69// snapManager.setupDragPlaneFromPlane(this._dragPlane);
70// do3DSnap = false;
71
72// snapManager.enableElementSnap ( false );
73// snapManager.enableGridSnap ( false );
74// }
75// }
76
77 if (selectedElements.length)
78 {
79 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas,
80 new WebKitPoint(event.pageX, event.pageY));
81
82 // do the snap before setting up the avoid list to allow
83 // a snap on the mouse down
84 var hitRec = snapManager.snap(point.x, point.y, do3DSnap);
85
86// if(this._handleMode === 2)
87// {
88// // translate z doesn't snap to element so hitRec's element will always be different
89// // from what the browser says we clicked on. So, skip this check.
90// }
91// else
92// {
93// // Check that hitRec's element matches element that browser says we clicked on
94// // TODO - This is still not working when using a handle that is on top of an
95// // element that is not currently selected
96// var elt = this.application.ninja.stage.GetSelectableElement(event);
97// if(elt && (elt !== hitRec.getElement()))
98// {
99// hitRec = snapManager.findHitRecordForElement(elt);
100// }
101// if(elt === this.application.ninja.currentSelectedContainer)
102// {
103// this._clickedOnStage = true;
104// }
105// }
106
107 // we don't want to snap to selected objects during the drag
108// var len = this._targets.length;
109// for(var i=0; i<len; i++)
110// {
111// snapManager.addToAvoidList( this._targets[i].elt );
112// }
113 if (hitRec)
114 {
115 // disable snap attributes
116 if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT)
117 {
118 this._snapToElements = false;
119 this._snapToGrid = false;
120 }
121 else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER)
122 {
123 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() );
124 }
125
126 if(this._handleMode === 0)
127 this.clickedObject = this._target;
128
129 // parameterize the snap point on the target
130 this._snapParam = this.parameterizeSnap( hitRec );
131
132 if(!this._dragPlane)
133 {
134 if (selectedElements.length === 1)
135 {
136 this._dragPlane = viewUtils.getUnprojectedElementPlane(this._clickedObject);
137 snapManager.setupDragPlaneFromPlane(this._dragPlane);
138 }
139 else
140 {
141 this._dragPlane = snapManager.setupDragPlanes( hitRec, true );
142 }
143
144 }
145
146 // no quadrant snapping for the rotate tool
147 this._shouldUseQuadPt = false;
148
149 var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane );
150 this._mouseDownHitRec = wpHitRec;
151 this._mouseUpHitRec = null;
152
153 var pt = hitRec.getScreenPoint();
154 this.downPoint.x = pt[0];
155 this.downPoint.y = pt[1];
156 this.downPoint.z = pt[2];
157
158 // TODO - need to figure out snapManager dependency by drawUtils.
159 // For now, bypassing by calling snapManager.drawLastHit();
160// drawUtils.refreshDisplay();
161// snapManager.drawLastHit();
162 }
163 }
164 else
165 {
166 this.target = null;
167 }
168 }
169 },
170
28 drawWithoutSnapping: 171 drawWithoutSnapping:
29 { 172 {
30 value: function(event) 173 value: function(event)
@@ -46,25 +189,76 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
46 } 189 }
47 }, 190 },
48 191
192 HandleMouseMove: {
193 value: function(event) {
194 if(this._escape) {
195 this._escape = false;
196 this.isDrawing = true;
197 }
198
199 if(this.isDrawing) {
200 this._hasDraw = true; // Flag for position of element
201 this.doDraw(event);
202 } else {
203 this._showFeedbackOnMouseMove(event);
204 if(this._canSnap)
205 {
206 this.doSnap(event);
207 }
208 }
209
210 this.DrawHandles(this._delta);
211
212 if(this._canSnap)
213 {
214 snapManager.drawLastHit();
215 }
216 }
217 },
218
49 modifyElements: { 219 modifyElements: {
50 value: function(data, event) { 220 value: function(data, event) {
51 var mat, angle, pt0 = data.pt0, pt1 = data.pt1; 221 var mat,
52 222 angle,
53 if(this._handleMode !== null) { 223 pt0 = data.pt0,
54 if(this._activateOriginHandle) { 224 pt1 = data.pt1;
55 // move the transform origin handle 225
56 var dx = pt1.x - pt0.x; 226 var selectedElements = this.application.ninja.selectedElements;
57 var dy = pt1.y - pt0.y; 227 if(this.rotateStage) {
58 this._origin[0] += dx; 228 selectedElements = [this.application.ninja.currentDocument.documentRoot];
59 this._origin[1] += dy; 229 }
60 230
61 if( this.rotateStage || (this.application.ninja.selectedElements.length === 1)) { 231 if(this._handleMode !== null)
62 this._startOriginArray[0][0] += dx; 232 {
63 this._startOriginArray[0][1] += dy; 233 if(this._activateOriginHandle)
234 {
235 // move the transform origin handle directly to the snap point (pt1)
236 this._origin[0] = pt1.x;
237 this._origin[1] = pt1.y;
238 this._origin[2] = pt1.z;
239
240 var sw2gMat = viewUtils.getStageWorldToGlobalMatrix();
241 var g2swMat = glmat4.inverse( sw2gMat, [] );
242 var swOrigin = MathUtils.transformAndDivideHomogeneousPoint( this._origin, g2swMat );
243 //console.log( "modifyElements, _origin: " + this._origin + ", in stageWorld: " + swOrigin );
244
245 var len = selectedElements.length;
246