aboutsummaryrefslogtreecommitdiff
path: root/js/tools/modifier-tool-base.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/modifier-tool-base.js')
-rwxr-xr-xjs/tools/modifier-tool-base.js796
1 files changed, 398 insertions, 398 deletions
<
diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js
index 55baecc8..2363745b 100755
--- a/js/tools/modifier-tool-base.js
+++ b/js/tools/modifier-tool-base.js
@@ -45,43 +45,43 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
45 //------------------------------------------------------------------------- 45 //-------------------------------------------------------------------------
46 // Snapping-specific properties 46 // Snapping-specific properties
47 _canSnap: { value: true }, 47 _canSnap: { value: true },
48 _snapParam: { value: null }, 48 _snapParam: { value: null },
49 _snapIndex: { value: -1 }, 49 _snapIndex: { value: -1 },
50 _useQuadPt: { value: false }, 50 _useQuadPt: { value: false },
51 _shouldUseQuadPt: { value: false }, 51 _shouldUseQuadPt: { value: false },
52 52
53 // we set snapping capabilities depending on the tool. 53 // we set snapping capabilities depending on the tool.
54 // The following variables are set in a tool's initializeSnapping method called on mouse down. 54 // The following variables are set in a tool's initializeSnapping method called on mouse down.
55 _snapToElements: { value: true }, 55 _snapToElements: { value: true },
56 _snapToGrid: { value: true }, 56 _snapToGrid: { value: true },
57 57
58 _clickedObject : {value : null }, 58 _clickedObject : {value : null },
59 clickedObject: 59 clickedObject:
60 { 60 {
61 get: function () { 61 get: function () {
62 return this._clickedObject; 62 return this._clickedObject;
63 }, 63 },
64 set: function (value) { 64 set: function (value) {
65 if(value === this.application.ninja.currentDocument.model.documentRoot) 65 if(value === this.application.ninja.currentDocument.model.documentRoot)
66 { 66 {
67 this._clickedObject = this._target; 67 this._clickedObject = this._target;
68 } 68 }
69 else 69 else
70 { 70 {
71 this._clickedObject = value; 71 this._clickedObject = value;
72 } 72 }
73 73
74 if(value) 74 if(value)
75 { 75 {
76 this._startMat = viewUtils.getMatrixFromElement(this._clickedObject); 76 this._startMat = viewUtils.getMatrixFromElement(this._clickedObject);
77 } 77 }
78 else 78 else
79 { 79 {
80 this._startMat = null; 80 this._startMat = null;
81 } 81 }
82 } 82 }
83 }, 83 },
84 84
85 _getObjectBeingTracked : 85 _getObjectBeingTracked :
86 { 86 {
87 value: function(hitRec) 87 value: function(hitRec)
@@ -103,25 +103,25 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
103 // override in subclasses 103 // override in subclasses
104 } 104 }
105 }, 105 },
106 106
107 initializeSnapping: 107 initializeSnapping:
108 { 108 {
109 value: function(event) 109 value: function(event)
110 { 110 {
111 this._mouseDownHitRec = null; 111 this._mouseDownHitRec = null;
112 this._mouseUpHitRec = null; 112 this._mouseUpHitRec = null;
113 113
114 snapManager.clearAvoidList(); 114 snapManager.clearAvoidList();
115 snapManager.clearDragPlane(); 115 snapManager.clearDragPlane();
116 116
117 // the translate tool does snap align to the bounds of the object only. 117 // the translate tool does snap align to the bounds of the object only.
118 // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method 118 // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method
119 snapManager.enableSnapAlign( false ); 119 snapManager.enableSnapAlign( false );
120 120
121 // snap to element and snap to grid are conditionally enabled based 121 // snap to element and snap to grid are conditionally enabled based
122 // on the snap results of the mouse down. enable everything for the first snap 122 // on the snap results of the mouse down. enable everything for the first snap
123 this._snapToElements = snapManager.elementSnapEnabledAppLevel(); 123 this._snapToElements = snapManager.elementSnapEnabledAppLevel();
124 this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); 124 this._snapToGrid = snapManager.gridSnapEnabledAppLevel();
125 125
126 this._dragPlane = null; 126 this._dragPlane = null;
127 var do3DSnap = true; 127 var do3DSnap = true;
@@ -132,8 +132,8 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
132// { 132// {
133// this.doSelection(event); 133// this.doSelection(event);
134 134
135 snapManager.enableElementSnap ( true ); 135 snapManager.enableElementSnap ( true );
136// snapManager.enableGridSnap ( true ); 136// snapManager.enableGridSnap ( true );
137// } 137// }
138// } 138// }
139// else 139// else
@@ -152,9 +152,9 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
152 { 152 {
153 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, 153 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas,
154 new WebKitPoint(event.pageX, event.pageY)); 154 new WebKitPoint(event.pageX, event.pageY));
155 // do the snap before setting up the avoid list to allow 155 // do the snap before setting up the avoid list to allow
156 // a snap on the mouse down 156 // a snap on the mouse down
157 var hitRec = snapManager.snap(point.x, point.y, do3DSnap); 157 var hitRec = snapManager.snap(point.x, point.y, do3DSnap);
158 158
159 // TODO - Check that hitRec's element matches element that browser says we clicked on 159 // TODO - Check that hitRec's element matches element that browser says we clicked on
160 var elt = this.application.ninja.stage.getElement(event, true); 160 var elt = this.application.ninja.stage.getElement(event, true);
@@ -168,21 +168,21 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
168 snapManager.addToAvoidList(element); 168 snapManager.addToAvoidList(element);
169 }); 169 });
170 170
171 if (hitRec) 171 if (hitRec)
172 { 172 {
173 // disable snap attributes 173 // disable snap attributes
174 if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT) 174 if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT)
175 { 175 {
176 this._snapToElements = false; 176 this._snapToElements = false;
177 this._snapToGrid = false; 177 this._snapToGrid = false;
178 } 178 }
179 else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER) 179 else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER)
180 { 180 {
181 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); 181 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() );
182 } 182 }
183 183
184 // parameterize the snap point on the target 184 // parameterize the snap point on the target
185 this._snapParam = this.parameterizeSnap( hitRec ); 185 this._snapParam = this.parameterizeSnap( hitRec );
186 186
187 if(!this._dragPlane) 187 if(!this._dragPlane)
188 { 188 {
@@ -201,20 +201,20 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
201 var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); 201 var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0);
202 this._shouldUseQuadPt = (sign == 0) 202 this._shouldUseQuadPt = (sign == 0)
203 203
204 var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); 204 var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane );
205 this._mouseDownHitRec = wpHitRec; 205 this._mouseDownHitRec = wpHitRec;
206 this._mouseUpHitRec = null; 206 this._mouseUpHitRec = null;
207 207
208 var pt = hitRec.getScreenPoint(); 208 var pt = hitRec.getScreenPoint();
209 this.downPoint.x = pt[0]; 209 this.downPoint.x = pt[0];
210 this.downPoint.y = pt[1]; 210 this.downPoint.y = pt[1];
211 211
212 snapManager.drawLastHit(); 212 snapManager.drawLastHit();
213 213
214 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); 214 snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() );
215 snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() ); 215 snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() );
216 snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() ); 216 snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() );
217 } 217 }
218 } 218 }
219 else 219 else
220 { 220 {
@@ -222,19 +222,19 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
222 } 222 }
223 } 223 }
224 }, 224 },
225 225
226 /* 226 /*
227 * The parameterization is based on the position of the 227 * The parameterization is based on the position of the
228 * snap point in pre-transformed element screen space 228 * snap point in pre-transformed element screen space
229 */ 229 */
230 parameterizeSnap: 230 parameterizeSnap:
231 { 231 {
232 value: function( hitRec ) 232 value: function( hitRec )
233 { 233 {
234 var paramPt = [0,0,0]; 234 var paramPt = [0,0,0];
235 var elt = this._getObjectBeingTracked(hitRec); 235 var elt = this._getObjectBeingTracked(hitRec);
236 if (elt) 236 if (elt)
237 { 237 {
238 this.clickedObject = elt;