aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
authorValerio Virgillito2012-04-17 11:08:29 -0700
committerValerio Virgillito2012-04-17 11:08:29 -0700
commit2292a35f545a161c0d19b26a8640b9421afce792 (patch)
treec9a64c50dd4c42cdbd221e35548418fe883c2d13 /js/tools
parent4b900ea5cd6bb77eb30cec8c03b9ec9fa662c1e9 (diff)
parent7ed5215332123d16f819a7a26c651af520a68669 (diff)
downloadninja-2292a35f545a161c0d19b26a8640b9421afce792.tar.gz
Merge pull request #163 from mencio/undo-manager
Undo manager - Fixing a couple undo bugs and architecture work to support undo/redo
Diffstat (limited to 'js/tools')
-rwxr-xr-xjs/tools/Rotate3DToolBase.js196
-rwxr-xr-xjs/tools/RotateObject3DTool.js1
-rwxr-xr-xjs/tools/RotateStage3DTool.js17
-rwxr-xr-xjs/tools/SelectionTool.js367
-rwxr-xr-xjs/tools/Translate3DToolBase.js158
-rwxr-xr-xjs/tools/TranslateObject3DTool.js17
-rwxr-xr-xjs/tools/modifier-tool-base.js38
7 files changed, 304 insertions, 490 deletions
diff --git a/js/tools/Rotate3DToolBase.js b/js/tools/Rotate3DToolBase.js
index 696408bf..2e121b0b 100755
--- a/js/tools/Rotate3DToolBase.js
+++ b/js/tools/Rotate3DToolBase.js
@@ -21,6 +21,10 @@ 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
24 drawWithoutSnapping: 28 drawWithoutSnapping:
25 { 29 {
26 value: function(event) 30 value: function(event)
@@ -44,27 +48,21 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
44 48
45 modifyElements: { 49 modifyElements: {
46 value: function(data, event) { 50 value: function(data, event) {
47 var mat, 51 var mat, angle, pt0 = data.pt0, pt1 = data.pt1;
48 angle,
49 pt0 = data.pt0,
50 pt1 = data.pt1;
51 52
52 if(this._handleMode !== null) 53 if(this._handleMode !== null) {
53 { 54 if(this._activateOriginHandle) {
54 if(this._activateOriginHandle)
55 {
56 // move the transform origin handle 55 // move the transform origin handle
57 var dx = pt1.x - pt0.x; 56 var dx = pt1.x - pt0.x;
58 var dy = pt1.y - pt0.y; 57 var dy = pt1.y - pt0.y;
59 this._origin[0] += dx; 58 this._origin[0] += dx;
60 this._origin[1] += dy; 59 this._origin[1] += dy;
61 60
62 var len = this._targets.length; 61 if( this.rotateStage || (this.application.ninja.selectedElements.length === 1)) {
63 if(len === 1)
64 {
65 this._startOriginArray[0][0] += dx; 62 this._startOriginArray[0][0] += dx;
66 this._startOriginArray[0][1] += dy; 63 this._startOriginArray[0][1] += dy;
67 } 64 }
65
68 this.downPoint.x = pt1.x; 66 this.downPoint.x = pt1.x;
69 this.downPoint.y = pt1.y; 67 this.downPoint.y = pt1.y;
70 this.DrawHandles(); 68 this.DrawHandles();
@@ -133,7 +131,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
133 } 131 }
134 } 132 }
135 133
136 if(this._inLocalMode && (this._targets.length === 1) ) 134 if(this._inLocalMode && (this.application.ninja.selectedElements.length === 1 || this.rotateStage) )
137 { 135 {
138 this._rotateLocally(mat); 136 this._rotateLocally(mat);
139 } 137 }
@@ -149,12 +147,15 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
149 147
150 _rotateLocally: { 148 _rotateLocally: {
151 value: function (rotMat) { 149 value: function (rotMat) {
152 var len = this._targets.length; 150 var selectedElements = this.application.ninja.selectedElements;
153 for(var i = 0; i < len; i++) 151
154 { 152 if(this.rotateStage) {
155 var item = this._targets[i]; 153 selectedElements = [this.application.ninja.currentDocument.documentRoot];
156 var elt = item.elt; 154 }
157 var curMat = item.mat; 155 var len = selectedElements.length;
156 for(var i = 0; i < len; i++) {
157 var elt = selectedElements[i].elementModel.getProperty("elt");
158 var curMat = selectedElements[i].elementModel.getProperty("mat");
158 159
159 // pre-translate by the transformation center 160 // pre-translate by the transformation center
160 var tMat = Matrix.I(4); 161 var tMat = Matrix.I(4);
@@ -178,19 +179,17 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
178 glmat4.multiply(mat, tMat, mat); 179 glmat4.multiply(mat, tMat, mat);
179 180
180 // while moving, set inline style to improve performance 181 // while moving, set inline style to improve performance
181 viewUtils.setMatrixForElement( elt, mat, true ); 182 viewUtils.setMatrixForElement(selectedElements[i], mat, true );
182 } 183 }
183 } 184 }
184 }, 185 },
185 186
186 _rotateGlobally: { 187 _rotateGlobally: {
187 value: function (rotMat) { 188 value: function (rotMat) {
188 var len = this._targets.length; 189 var len = this.application.ninja.selectedElements.length;
189 for(var i = 0; i < len; i++) 190 for(var i = 0; i < len; i++) {
190 { 191 var elt = this.application.ninja.selectedElements[i].elementModel.getProperty("elt");
191 var item = this._targets[i]; 192 var curMat = this.application.ninja.selectedElements[i].elementModel.getProperty("mat");
192 var elt = item.elt;
193 var curMat = item.mat;
194 193
195 // pre-translate by the transformation center 194 // pre-translate by the transformation center
196 var tMat = Matrix.I(4); 195 var tMat = Matrix.I(4);
@@ -213,7 +212,7 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
213 212
214 glmat4.multiply(mat, curMat, mat); 213 glmat4.multiply(mat, curMat, mat);
215 214
216 viewUtils.setMatrixForElement( elt, mat, true ); 215 viewUtils.setMatrixForElement(this.application.ninja.selectedElements[i], mat, true );
217 } 216 }
218 } 217 }
219 }, 218 },
@@ -254,7 +253,6 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
254 captureSelectionDrawn: { 253 captureSelectionDrawn: {
255 value: function(event){ 254 value: function(event){
256 this._origin = null; 255 this._origin = null;
257 this._targets = [];
258 this._startOriginArray = null; 256 this._startOriginArray = null;
259 257
260 var len = this.application.ninja.selectedElements.length; 258 var len = this.application.ninja.selectedElements.length;
@@ -304,103 +302,79 @@ exports.Rotate3DToolBase = Montage.create(ModifierToolBase, {
304 }, 302 },
305 303
306 _updateTargets: { 304 _updateTargets: {
307 value: function(addToUndoStack) { 305 value: function(addToUndo) {
308 var newStyles = [], 306 var mod3dObject = [], self = this;
309 previousStyles = [],
310 len = this.application.ninja.selectedElements.length;
311 this._targets = [];
312 for(var i = 0; i < len; i++)
313 {
314 var elt = this.application.ninja.selectedElements[i];
315// this._initProps3D(elt);
316
317 307
318 var curMat = viewUtils.getMatrixFromElement(elt); 308 this.application.ninja.selectedElements.forEach(function(element) {
319 var curMatInv = glmat4.inverse(curMat, []); 309 viewUtils.pushViewportObj(element);
320
321 viewUtils.pushViewportObj( elt );
322 var eltCtr = viewUtils.getCenterOfProjection(); 310 var eltCtr = viewUtils.getCenterOfProjection();
323 viewUtils.popViewportObj(); 311 viewUtils.popViewportObj();
312 eltCtr = viewUtils.localToGlobal(eltCtr, element);
324 313
325 eltCtr = viewUtils.localToGlobal(eltCtr, elt); 314 element.elementModel.setProperty("ctr", eltCtr);
326
327 this._targets.push({elt:elt, mat:curMat, matInv:curMatInv, ctr:eltCtr});
328 if(addToUndoStack)
329 {
330 var previousStyleStr = {dist:this._undoArray[i].dist, mat:MathUtils.scientificToDecimal(this._undoArray[i].mat.slice(0), 5)};
331 315
332 var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), mat:MathUtils.scientificToDecimal(curMat, 5)}; 316 if(addToUndo) {
317 var previousMat = element.elementModel.getProperty("mat").slice(0);
318 var previousStyleStr = {dist:element.elementModel.getProperty("dist"), mat:MathUtils.scientificToDecimal(previousMat, 5)};
319 var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(element), mat:MathUtils.scientificToDecimal(viewUtils.getMatrixFromElement(element), 5)};
333 320
334 previousStyles.push(previousStyleStr); 321 mod3dObject.push({element:element, properties:newStyleStr, previousProperties: previousStyleStr});
335 newStyles.push(newStyleStr);
336 } 322 }
323
324 });
325
326 if(addToUndo) {
327 ElementsMediator.set3DProperties(mod3dObject, "Change", "rotateTool");
337 } 328 }
338 if(addToUndoStack) 329
339 { 330 this.application.ninja.selectedElements.forEach(function(element) {
340 ElementsMediator.set3DProperties(this.application.ninja.selectedElements, 331 element.elementModel.setProperty("mat", viewUtils.getMatrixFromElement(element));
341 newStyles, 332 element.elementModel.setProperty("matInv", glmat4.inverse(element.elementModel.getProperty("mat"), []));
342 "Change", 333 element.elementModel.setProperty("dist", viewUtils.getPerspectiveDistFromElement(element));
343 "rotateTool", 334 });
344 previousStyles
345 );
346 }
347 // Save previous value for undo/redo
348 this._undoArray = [];
349 for(i = 0, len = this._targets.length; i < len; i++)
350 {
351 var elt = this._targets[i].elt;
352 var _mat = viewUtils.getMatrixFromElement(elt);
353 var _dist = viewUtils.getPerspectiveDistFromElement(elt);
354 this._undoArray.push({mat:_mat, dist:_dist});
355 }
356 } 335 }
357 }, 336 },
358 337
359 _setTransformOrigin: { 338 _setTransformOrigin: {
360 value: function(shouldUpdateCenter) { 339 value: