aboutsummaryrefslogtreecommitdiff
path: root/js/stage
diff options
context:
space:
mode:
authorPushkar Joshi2012-02-07 07:21:27 -0800
committerPushkar Joshi2012-02-07 07:21:27 -0800
commit4bbe42e6d01fd0f81d13357a75b40eae9925dda3 (patch)
tree57f49ebfa5d3fcef28753b34015209edda6e620a /js/stage
parente7aa17a9b472640355e95c54841399f6203050d4 (diff)
parent8950b342d1eda8bfa195372e1c17363a409651cd (diff)
downloadninja-4bbe42e6d01fd0f81d13357a75b40eae9925dda3.tar.gz
Merge branch 'master' into pentool
Diffstat (limited to 'js/stage')
-rw-r--r--js/stage/layout.js72
1 files changed, 12 insertions, 60 deletions
diff --git a/js/stage/layout.js b/js/stage/layout.js
index 89fa44f3..1a491210 100644
--- a/js/stage/layout.js
+++ b/js/stage/layout.js
@@ -58,7 +58,7 @@ exports.Layout = Montage.create(Component, {
58 58
59 this.eventManager.addEventListener("selectionChange", this, false); 59 this.eventManager.addEventListener("selectionChange", this, false);
60 60
61 this.eventManager.addEventListener("deleteSelection", this, true); 61 this.eventManager.addEventListener("deleteSelection", this, false);
62 62
63// this.addEventListener("change@stage.appModel.layoutView", this.handleLayoutView, false); 63// this.addEventListener("change@stage.appModel.layoutView", this.handleLayoutView, false);
64 64
@@ -74,26 +74,23 @@ exports.Layout = Montage.create(Component, {
74 handleElementAdded: { 74 handleElementAdded: {
75 value: function(event) { 75 value: function(event) {
76 this.domTree.push(event.detail); 76 this.domTree.push(event.detail);
77
78 this.draw();
79 this.draw3DInfo(false);
77 } 80 }
78 }, 81 },
79 82
80 handleElementDeleted: { 83 handleElementDeleted: {
81 value: function(event) { 84 value: function(event) {
82 this.domTree.splice(this.domTree.indexOf(event.detail), 1); 85 this.domTree.splice(this.domTree.indexOf(event.detail), 1);
83
84 this.draw();
85 } 86 }
86 }, 87 },
87 88
88 captureDeleteSelection: { 89 // Redraw stage only once after all deletion is completed
90 handleDeleteSelection: {
89 value: function(event) { 91 value: function(event) {
90 //this.redrawDocument(); 92 this.draw();
91 93 this.draw3DInfo(false);
92 var len = event.detail.length;
93 for(var i = 0; i < len ; i++) {
94 this.domTree.splice(this.domTree.indexOf(event.detail[i]),1);
95 }
96
97 } 94 }
98 }, 95 },
99 96
@@ -290,8 +287,9 @@ exports.Layout = Montage.create(Component, {
290 } 287 }
291 }, 288 },
292 289
293 // Alternate dashed line method. 290 // Dashed line function found at http://stackoverflow.com/questions/4576724/dotted-stroke-in-canvas/
294 ___dashedLine: { 291 // Portions used with permission of Gavin Kistner (phrogz)
292 _dashedLine: {
295 value: function(x, y, x2, y2, dashArray) { 293 value: function(x, y, x2, y2, dashArray) {
296 this.ctx.lineCap = "square"; 294 this.ctx.lineCap = "square";
297 this.ctx.beginPath(); 295 this.ctx.beginPath();
@@ -311,7 +309,7 @@ exports.Layout = Montage.create(Component, {
311 var step = Math.sqrt(dashLength * dashLength / (1 + slope * slope)); 309 var step = Math.sqrt(dashLength * dashLength / (1 + slope * slope));
312 if(xSlope){ 310 if(xSlope){
313 if(dx < 0) step = -step; 311 if(dx < 0) step = -step;
314 x += step 312 x += step;
315 y += slope * step; 313 y += slope * step;
316 }else{ 314 }else{
317 if(dy < 0) step = -step; 315 if(dy < 0) step = -step;
@@ -329,52 +327,6 @@ exports.Layout = Montage.create(Component, {
329 } 327 }
330 }, 328 },
331 329
332 _dashedLine: {
333 value: function (fromX, fromY, toX, toY, pattern){
334 this.ctx.beginPath();
335 // Our growth rate for our line can be one of the following:
336 // (+,+), (+,-), (-,+), (-,-)
337 // Because of this, our algorithm needs to understand if the x-coord and
338 // y-coord should be getting smaller or larger and properly cap the values
339 // based on (x,y).
340 var lt = function (a, b) { return a <= b; };
341 var gt = function (a, b) { return a >= b; };
342 var capmin = function (a, b) { return Math.min(a, b); };
343 var capmax = function (a, b) { return Math.max(a, b); };
344
345 var checkX = { thereYet: gt, cap: capmin };
346 var checkY = { thereYet: gt, cap: capmin };
347
348 if (fromY - toY > 0) {
349 checkY.thereYet = lt;
350 checkY.cap = capmax;
351 }
352 if (fromX - toX > 0) {
353 checkX.thereYet = lt;
354 checkX.cap = capmax;
355 }
356
357 this.ctx.moveTo(fromX, fromY);
358 var offsetX = fromX;
359 var offsetY = fromY;
360 var idx = 0, dash = true;
361 while (!(checkX.thereYet(offsetX, toX) && checkY.thereYet(offsetY, toY))) {
362 var ang = Math.atan2(toY - fromY, toX - fromX);
363 var len = pattern[idx];
364
365 offsetX = checkX.cap(toX, offsetX + (Math.cos(ang) * len));
366 offsetY = checkY.cap(toY, offsetY + (Math.sin(ang) * len));
367
368 if (dash) this.ctx.lineTo(offsetX, offsetY);
369 else this.ctx.moveTo(offsetX, offsetY);
370
371 idx = (idx + 1) % pattern.length;
372 dash = !dash;
373 }
374 this.ctx.stroke();
375 }
376 },
377
378 _elementName: { 330 _elementName: {
379 value: function(item) { 331 value: function(item) {
380 return this.application.ninja.elementMediator.getNJProperty(item, "selection"); 332 return this.application.ninja.elementMediator.getNJProperty(item, "selection");