From 9d122c5f1632b1225a543049913c36b9a030110c Mon Sep 17 00:00:00 2001 From: hwc487 Date: Mon, 6 Feb 2012 15:50:07 -0800 Subject: Enhanced the overlap test for the selection tool marquee select. --- js/tools/SelectionTool.js | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'js/tools/SelectionTool.js') diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js index 862b2e88..48548271 100644 --- a/js/tools/SelectionTool.js +++ b/js/tools/SelectionTool.js @@ -135,18 +135,16 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { var box = []; selectedItems = []; - box[0] = this.downPoint.x - this.application.ninja.stage.documentOffsetLeft + this.application.ninja.stage.scrollLeft; - box[1] = this.downPoint.y - this.application.ninja.stage.documentOffsetTop + this.application.ninja.stage.scrollTop; - box[2] = box[0] + (point.x - this.downPoint.x); - box[3] = box[1] + (point.y - this.downPoint.y); - box = this.absoluteRectangle(box[0], box[1],box[2],box[3]); - + box[0] = this.downPoint.x; + box[1] = this.downPoint.y; + box[2] = point.x; + box[3] = point.y; //selectionManagerModule.selectionManager.marqueeSelection(box); var childNodes = this.application.ninja.currentDocument.documentRoot.childNodes; childNodes = Array.prototype.slice.call(childNodes, 0); childNodes.forEach(function(item) { - if(item.nodeType == 1 && SelectionTool._simpleCollisionDetection(item, box)) { + if(item.nodeType == 1 && SelectionTool._complicatedCollisionDetection(item, box)) { selectedItems.push(item); } }); @@ -802,6 +800,34 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { } }, + // TODO : Use the new element mediator to get element offsets + _complicatedCollisionDetection: + { + value: function(elt, box) + { + var left, top, width, height; + + left = box[0]; + width = box[2] - left; + if (width < 0) + { + left = box[2]; + width = -width; + } + top = box[1]; + height = box[3] - top; + if (height < 0) + { + top = box[3]; + height = -height; + } + + var rtnVal = MathUtils.rectsOverlap( [left,top], width, height, elt ); + + return rtnVal; + } + }, + // TODO : Use the new element mediator to get element offsets _simpleCollisionDetection: { value: function(ele, box){ -- cgit v1.2.3