aboutsummaryrefslogtreecommitdiff
path: root/js/tools/SelectionTool.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/SelectionTool.js')
-rwxr-xr-xjs/tools/SelectionTool.js93
1 files changed, 48 insertions, 45 deletions
diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js
index 5f48f74d..94cc6b83 100755
--- a/js/tools/SelectionTool.js
+++ b/js/tools/SelectionTool.js
@@ -60,6 +60,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
60 else 60 else
61 { 61 {
62 this._canSnap = true; 62 this._canSnap = true;
63 this._updateTargets();
63 } 64 }
64 65
65 this.isDrawing = true; 66 this.isDrawing = true;
@@ -205,12 +206,12 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
205 { 206 {
206 this._handleMode = null; 207 this._handleMode = null;
207 this._delta = null; 208 this._delta = null;
208 this.DrawHandles();
209 } 209 }
210 210
211 this.endDraw(event); 211 this.endDraw(event);
212 this._canSnap = true; 212 this._canSnap = true;
213 this._use3DMode = false; 213 this._use3DMode = false;
214 this.DrawHandles();
214 } 215 }
215 }, 216 },
216 217
@@ -223,7 +224,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
223 HandleDoubleClick: { 224 HandleDoubleClick: {
224 value: function(event) { 225 value: function(event) {
225 if(this.application.ninja.selectedElements.length > 0) { 226 if(this.application.ninja.selectedElements.length > 0) {
226 this.application.ninja.currentSelectedContainer = this.application.ninja.selectedElements[0]._element; 227 this.application.ninja.currentSelectedContainer = this.application.ninja.selectedElements[0];
227 } else { 228 } else {
228 this.application.ninja.currentSelectedContainer = this.application.ninja.currentDocument.documentRoot; 229 this.application.ninja.currentSelectedContainer = this.application.ninja.currentDocument.documentRoot;
229 } 230 }
@@ -242,8 +243,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
242 case Keyboard.LEFT: 243 case Keyboard.LEFT:
243 var newLeft = []; 244 var newLeft = [];
244 var leftArr = this.application.ninja.selectedElements.map(function(item) { 245 var leftArr = this.application.ninja.selectedElements.map(function(item) {
245 newLeft.push( (parseInt(ElementsMediator.getProperty(item._element, "left")) - inc) + "px" ); 246 newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left")) - inc) + "px" );
246 return ElementsMediator.getProperty(item._element, "left"); 247 return ElementsMediator.getProperty(item, "left");
247 }); 248 });
248 249
249 ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr); 250 ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr);
@@ -251,8 +252,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
251 case Keyboard.UP: 252 case Keyboard.UP:
252 var newTop = []; 253 var newTop = [];
253 var topArr = this.application.ninja.selectedElements.map(function(item) { 254 var topArr = this.application.ninja.selectedElements.map(function(item) {
254 newTop.push( (parseInt(ElementsMediator.getProperty(item._element, "top")) - inc) + "px" ); 255 newTop.push( (parseInt(ElementsMediator.getProperty(item, "top")) - inc) + "px" );
255 return ElementsMediator.getProperty(item._element, "top"); 256 return ElementsMediator.getProperty(item, "top");
256 }); 257 });
257 258
258 ElementsMediator.setProperty(this.application.ninja.selectedElements, "top", newTop , "Change", "selectionTool", topArr); 259 ElementsMediator.setProperty(this.application.ninja.selectedElements, "top", newTop , "Change", "selectionTool", topArr);
@@ -260,8 +261,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
260 case Keyboard.RIGHT: 261 case Keyboard.RIGHT:
261 var newLeft = []; 262 var newLeft = [];
262 var leftArr = this.application.ninja.selectedElements.map(function(item) { 263 var leftArr = this.application.ninja.selectedElements.map(function(item) {
263 newLeft.push( (parseInt(ElementsMediator.getProperty(item._element, "left")) + inc) + "px" ); 264 newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left")) + inc) + "px" );
264 return ElementsMediator.getProperty(item._element, "left"); 265 return ElementsMediator.getProperty(item, "left");
265 }); 266 });
266 267
267 ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr); 268 ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr);
@@ -269,8 +270,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
269 case Keyboard.DOWN: 270 case Keyboard.DOWN:
270 var newTop = []; 271 var newTop = [];
271 var topArr = this.application.ninja.selectedElements.map(function(item) { 272 var topArr = this.application.ninja.selectedElements.map(function(item) {
272 newTop.push( (parseInt(ElementsMediator.getProperty(item._element, "top")) + inc) + "px" ); 273 newTop.push( (parseInt(ElementsMediator.getProperty(item, "top")) + inc) + "px" );
273 return ElementsMediator.getProperty(item._element, "top"); 274 return ElementsMediator.getProperty(item, "top");
274 }); 275 });
275 276
276 ElementsMediator.setProperty(this.application.ninja.selectedElements, "top", newTop , "Change", "selectionTool", topArr); 277 ElementsMediator.setProperty(this.application.ninja.selectedElements, "top", newTop , "Change", "selectionTool", topArr);
@@ -308,28 +309,35 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
308 previousStyles = []; 309 previousStyles = [];
309 var len = this.application.ninja.selectedElements.length; 310 var len = this.application.ninja.selectedElements.length;
310 this._targets = []; 311 this._targets = [];
311 for(var i = 0; i < len; i++) 312 for(var i = 0; i < len; i++) {
312 { 313 var elt = this.application.ninja.selectedElements[i];
313 var elt = this.application.ninja.selectedElements[i]._element;
314 314
315 var curMat = viewUtils.getMatrixFromElement(elt); 315 var curMat = viewUtils.getMatrixFromElement(elt);
316 var curMatInv = glmat4.inverse(curMat, []); 316 var curMatInv = glmat4.inverse(curMat, []);
317 317
318 this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); 318 this._targets.push({elt:elt, mat:curMat, matInv:curMatInv});
319 if(addToUndoStack) 319 if(addToUndoStack) {
320 { 320 var prevX,
321 321 prevY,
322 if(!this._use3DMode) 322 prevW,
323 { 323 prevH,
324 var previousMat = this._undoArray[i].mat.slice(0); 324 _x,
325 var prevX = this._undoArray[i]._x; 325 _y,
326 var prevY = this._undoArray[i]._y; 326 _w,
327 var prevW = this._undoArray[i]._w; 327 _h,
328 var prevH = this._undoArray[i]._h; 328 previousMat,
329 var _x = parseInt(ElementsMediator.getProperty(elt, "left")) + curMat[12] - previousMat[12]; 329 previousStyleStr,
330 var _y = parseInt(ElementsMediator.getProperty(elt, "top")) + curMat[13] - previousMat[13]; 330 newStyleStr;
331 var _w = parseInt(ElementsMediator.getProperty(elt, "width")); 331
332 var _h = parseInt(ElementsMediator.getProperty(elt, "height")); 332 if(!this._use3DMode) {
333 prevX = this._undoArray[i]._x;
334 prevY = this._undoArray[i]._y;
335 prevW = this._undoArray[i]._w;
336 prevH = this._undoArray[i]._h;
337 _x = parseInt(ElementsMediator.getProperty(elt, "left"));
338 _y = parseInt(ElementsMediator.getProperty(elt, "top"));
339 _w = parseInt(ElementsMediator.getProperty(elt, "width"));
340 _h = parseInt(ElementsMediator.getProperty(elt, "height"));
333 341
334 previousLeft.push(prevX + "px"); 342 previousLeft.push(prevX + "px");
335 previousTop.push(prevY + "px"); 343 previousTop.push(prevY + "px");
@@ -339,27 +347,22 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
339 newTop.push(_y + "px"); 347 newTop.push(_y + "px");
340 newWidth.push(_w + "px"); 348 newWidth.push(_w + "px");
341 newHeight.push(_h + "px"); 349 newHeight.push(_h + "px");
342
343 viewUtils.setMatrixForElement(elt, previousMat);
344
345 this._targets[i].mat = previousMat;
346 this._targets[i].matInv = glmat4.inverse(previousMat, []);
347 } 350 }
348 else 351 else
349 { 352 {
350 var previousMat = this._undoArray[i].mat.slice(0); 353 previousMat = this._undoArray[i].mat.slice(0);
351 var prevW = this._undoArray[i]._w; 354 prevW = this._undoArray[i]._w;
352 var prevH = this._undoArray[i]._h; 355 prevH = this._undoArray[i]._h;
353 var _w = parseInt(ElementsMediator.getProperty(elt, "width")); 356 _w = parseInt(ElementsMediator.getProperty(elt, "width"));
354 var _h = parseInt(ElementsMediator.getProperty(elt, "height")); 357 _h = parseInt(ElementsMediator.getProperty(elt, "height"));
355 previousWidth.push(prevW + "px"); 358 previousWidth.push(prevW + "px");
356 previousHeight.push(prevH + "px"); 359 previousHeight.push(prevH + "px");
357 newWidth.push(_w + "px"); 360 newWidth.push(_w + "px");
358 newHeight.push(_h + "px"); 361 newHeight.push(_h + "px");
359 362
360 var previousStyleStr = {dist:this._undoArray[i].dist, 363 previousStyleStr = {dist:this._undoArray[i].dist,
361 mat:MathUtils.scientificToDecimal(previousMat, 5)}; 364 mat:MathUtils.scientificToDecimal(previousMat, 5)};
362 var newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt), 365 newStyleStr = {dist:viewUtils.getPerspectiveDistFromElement(elt),
363 mat:MathUtils.scientificToDecimal(curMat, 5)}; 366 mat:MathUtils.scientificToDecimal(curMat, 5)};
364 previousStyles.push(previousStyleStr); 367 previousStyles.push(previousStyleStr);
365 newStyles.push(newStyleStr); 368 newStyles.push(newStyleStr);
@@ -460,11 +463,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
460 } 463 }
461 else 464 else
462 { 465 {
463 curMat = item.mat.slice(0); 466 var _x = parseInt(ElementsMediator.getProperty(elt, "left")) + transMat[12];
464 glmat4.multiply(curMat, qMat, curMat); 467 var _y = parseInt(ElementsMediator.getProperty(elt, "top")) + transMat[13];
465 var previousMat = this._undoArray[i].mat.slice(0);
466 var _x = parseInt(ElementsMediator.getProperty(elt, "left")) + curMat[12] - previousMat[12];
467 var _y = parseInt(ElementsMediator.getProperty(elt, "top")) + curMat[13] - previousMat[13];
468 468
469 newLeft.push(_x + "px"); 469 newLeft.push(_x + "px");
470 newTop.push(_y + "px"); 470 newTop.push(_y + "px");
@@ -577,6 +577,9 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
577 { 577 {
578 // form the translation vector and post translate the matrix by it. 578 // form the translation vector and post translate the matrix by it.
579 delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 ); 579 delta = vecUtils.vecSubtract( 3, data.pt1, data.pt0 );
580 delta[0] = ~~delta[0];
581 delta[1] = ~~delta[1];
582 delta[2] = 0;
580 var transMat = Matrix.Translation( delta ); 583 var transMat = Matrix.Translation( delta );
581 this._moveElements(transMat); 584 this._moveElements(transMat);
582 } 585 }
@@ -710,7 +713,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, {
710 { 713 {
711 return; 714 return;
712 } 715 }
713 if(this._target && this._handles) 716 if(this._target && this._handles && (this._targets.length === 1))
714 { 717