aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools')
-rwxr-xr-xjs/tools/Rotate3DToolBase.js506
-rwxr-xr-xjs/tools/RotateObject3DTool.js5
-rwxr-xr-xjs/tools/RotateStage3DTool.js24
-rwxr-xr-xjs/tools/SelectionTool.js367
-rwxr-xr-xjs/tools/Translate3DToolBase.js276
-rwxr-xr-xjs/tools/TranslateObject3DTool.js18
-rwxr-xr-xjs/tools/modifier-tool-base.js53
7 files changed, 732 insertions, 517 deletions
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js
index 696408bf..4fa8657e 100755
--- a/js/tools/Rotate3DToolBase.js
+++ b/js/tools/Rotate3DToolBase.js
@@ -21,6 +21,153 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
21 21
22 _inLocalMode: { value: true, enumerable: true }, 22 _inLocalMode: { value: true, enumerable: true },
23 23
24 rotateStage: {
25 value: false
26 },
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
24 drawWithoutSnapping: 171 drawWithoutSnapping:
25 { 172 {
26 value: function(event) 173 value: function(event)
@@ -42,6 +189,33 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
42 } 189 }
43 }, 190 },
44 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
45 modifyElements: { 219 modifyElements: {
46 value: function(data, event) { 220 value: function(data, event) {
47 var mat, 221 var mat,
@@ -49,24 +223,42 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
49 pt0 = data.pt0, 223 pt0 = data.pt0,
50 pt1 = data.pt1; 224 pt1 = data.pt1;
51 225
226 var selectedElements = this.application.ninja.selectedElements;
227 if(this.rotateStage) {
228 selectedElements = [this.application.ninja.currentDocument.documentRoot];
229 }
230
52 if(this._handleMode !== null) 231 if(this._handleMode !== null)
53 { 232 {
54 if(this._activateOriginHandle) 233 if(this._activateOriginHandle)
55 { 234 {
56 // move the transform origin handle 235 // move the transform origin handle directly to the snap point (pt1)
57 var dx = pt1.x - pt0.x; 236 this._origin[0] = pt1.x;
58 var dy = pt1.y - pt0.y; 237 this._origin[1] = pt1.y;
59 this._origin[0] += dx; 238 this._origin[2] = pt1.z;
60 this._origin[1] += dy; 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 );
61 244
62 var len = this._targets.length; 245 var len = selectedElements.length;
63 if(len === 1) 246 if(len === 1)
64 { 247