From 54f9f6ebfb495feed695cf12a0f245f535cd3372 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 2 Feb 2012 15:17:16 -0800 Subject: Switching to alternate dashed line function. Adding code attributions. Signed-off-by: Valerio Virgillito --- js/stage/layout.js | 53 ++++------------------------------------------------- 1 file changed, 4 insertions(+), 49 deletions(-) (limited to 'js/stage/layout.js') diff --git a/js/stage/layout.js b/js/stage/layout.js index 625c09ad..1e712550 100644 --- a/js/stage/layout.js +++ b/js/stage/layout.js @@ -282,8 +282,9 @@ exports.Layout = Montage.create(Component, { } }, - // Alternate dashed line method. - ___dashedLine: { + // Dashed line function found at http://stackoverflow.com/questions/4576724/dotted-stroke-in-canvas/ + // Portions used with permission of Gavin Kistner (phrogz) + _dashedLine: { value: function(x, y, x2, y2, dashArray) { this.ctx.lineCap = "square"; this.ctx.beginPath(); @@ -303,7 +304,7 @@ exports.Layout = Montage.create(Component, { var step = Math.sqrt(dashLength * dashLength / (1 + slope * slope)); if(xSlope){ if(dx < 0) step = -step; - x += step + x += step; y += slope * step; }else{ if(dy < 0) step = -step; @@ -321,52 +322,6 @@ exports.Layout = Montage.create(Component, { } }, - _dashedLine: { - value: function (fromX, fromY, toX, toY, pattern){ - this.ctx.beginPath(); - // Our growth rate for our line can be one of the following: - // (+,+), (+,-), (-,+), (-,-) - // Because of this, our algorithm needs to understand if the x-coord and - // y-coord should be getting smaller or larger and properly cap the values - // based on (x,y). - var lt = function (a, b) { return a <= b; }; - var gt = function (a, b) { return a >= b; }; - var capmin = function (a, b) { return Math.min(a, b); }; - var capmax = function (a, b) { return Math.max(a, b); }; - - var checkX = { thereYet: gt, cap: capmin }; - var checkY = { thereYet: gt, cap: capmin }; - - if (fromY - toY > 0) { - checkY.thereYet = lt; - checkY.cap = capmax; - } - if (fromX - toX > 0) { - checkX.thereYet = lt; - checkX.cap = capmax; - } - - this.ctx.moveTo(fromX, fromY); - var offsetX = fromX; - var offsetY = fromY; - var idx = 0, dash = true; - while (!(checkX.thereYet(offsetX, toX) && checkY.thereYet(offsetY, toY))) { - var ang = Math.atan2(toY - fromY, toX - fromX); - var len = pattern[idx]; - - offsetX = checkX.cap(toX, offsetX + (Math.cos(ang) * len)); - offsetY = checkY.cap(toY, offsetY + (Math.sin(ang) * len)); - - if (dash) this.ctx.lineTo(offsetX, offsetY); - else this.ctx.moveTo(offsetX, offsetY); - - idx = (idx + 1) % pattern.length; - dash = !dash; - } - this.ctx.stroke(); - } - }, - _elementName: { value: function(item) { return this.application.ninja.elementMediator.getNJProperty(item, "selection"); -- cgit v1.2.3 From 854a6d1be334782c8e232601e6d562a11296e55a Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Fri, 3 Feb 2012 14:06:26 -0800 Subject: Update grid and planes when elementChange event signifies the "matrix", "left", "top", "width" or "height" properties have changed. Signed-off-by: Nivesh Rajbhandari --- js/stage/layout.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'js/stage/layout.js') diff --git a/js/stage/layout.js b/js/stage/layout.js index dd5be081..c369fc30 100644 --- a/js/stage/layout.js +++ b/js/stage/layout.js @@ -74,6 +74,9 @@ exports.Layout = Montage.create(Component, { handleElementAdded: { value: function(event) { this.domTree.push(event.detail); + + this.draw(); + this.draw3DInfo(false); } }, @@ -82,6 +85,7 @@ exports.Layout = Montage.create(Component, { this.domTree.splice(this.domTree.indexOf(event.detail), 1); this.draw(); + this.draw3DInfo(false); } }, -- cgit v1.2.3 From d7ad2659d7ef8d0fffbb1cba8218061ebd516dd0 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Fri, 3 Feb 2012 15:09:54 -0800 Subject: Handle delete of multiple objects. Also, have deletion go through the mediator so elementDeleted event is fired for SnapManager, DrawUtils, etc. to clean up after deleted element(s). Signed-off-by: Nivesh Rajbhandari --- js/stage/layout.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'js/stage/layout.js') diff --git a/js/stage/layout.js b/js/stage/layout.js index c369fc30..1a491210 100644 --- a/js/stage/layout.js +++ b/js/stage/layout.js @@ -58,7 +58,7 @@ exports.Layout = Montage.create(Component, { this.eventManager.addEventListener("selectionChange", this, false); - this.eventManager.addEventListener("deleteSelection", this, true); + this.eventManager.addEventListener("deleteSelection", this, false); // this.addEventListener("change@stage.appModel.layoutView", this.handleLayoutView, false); @@ -83,21 +83,14 @@ exports.Layout = Montage.create(Component, { handleElementDeleted: { value: function(event) { this.domTree.splice(this.domTree.indexOf(event.detail), 1); - - this.draw(); - this.draw3DInfo(false); } }, - captureDeleteSelection: { + // Redraw stage only once after all deletion is completed + handleDeleteSelection: { value: function(event) { - //this.redrawDocument(); - - var len = event.detail.length; - for(var i = 0; i < len ; i++) { - this.domTree.splice(this.domTree.indexOf(event.detail[i]),1); - } - + this.draw(); + this.draw3DInfo(false); } }, -- cgit v1.2.3