From 648ee61ae84216d0236e0dbc211addc13b2cfa3a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:52:06 -0700 Subject: Expand tabs --- js/tools/modifier-tool-base.js | 774 ++++++++++++++++++++--------------------- 1 file changed, 387 insertions(+), 387 deletions(-) (limited to 'js/tools/modifier-tool-base.js') diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index 55baecc8..23185989 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -45,42 +45,42 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { //------------------------------------------------------------------------- // Snapping-specific properties _canSnap: { value: true }, - _snapParam: { value: null }, - _snapIndex: { value: -1 }, - _useQuadPt: { value: false }, + _snapParam: { value: null }, + _snapIndex: { value: -1 }, + _useQuadPt: { value: false }, _shouldUseQuadPt: { value: false }, - // we set snapping capabilities depending on the tool. - // The following variables are set in a tool's initializeSnapping method called on mouse down. - _snapToElements: { value: true }, - _snapToGrid: { value: true }, + // we set snapping capabilities depending on the tool. + // The following variables are set in a tool's initializeSnapping method called on mouse down. + _snapToElements: { value: true }, + _snapToGrid: { value: true }, _clickedObject : {value : null }, clickedObject: - { - get: function () { - return this._clickedObject; - }, - set: function (value) { - if(value === this.application.ninja.currentDocument.model.documentRoot) - { - this._clickedObject = this._target; - } - else - { - this._clickedObject = value; - } - - if(value) - { - this._startMat = viewUtils.getMatrixFromElement(this._clickedObject); - } - else - { - this._startMat = null; - } - } - }, + { + get: function () { + return this._clickedObject; + }, + set: function (value) { + if(value === this.application.ninja.currentDocument.model.documentRoot) + { + this._clickedObject = this._target; + } + else + { + this._clickedObject = value; + } + + if(value) + { + this._startMat = viewUtils.getMatrixFromElement(this._clickedObject); + } + else + { + this._startMat = null; + } + } + }, _getObjectBeingTracked : { @@ -109,19 +109,19 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { value: function(event) { this._mouseDownHitRec = null; - this._mouseUpHitRec = null; + this._mouseUpHitRec = null; - snapManager.clearAvoidList(); - snapManager.clearDragPlane(); + snapManager.clearAvoidList(); + snapManager.clearDragPlane(); - // the translate tool does snap align to the bounds of the object only. - // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method - snapManager.enableSnapAlign( false ); + // the translate tool does snap align to the bounds of the object only. + // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method + snapManager.enableSnapAlign( false ); - // snap to element and snap to grid are conditionally enabled based - // on the snap results of the mouse down. enable everything for the first snap - this._snapToElements = snapManager.elementSnapEnabledAppLevel(); - this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); + // snap to element and snap to grid are conditionally enabled based + // on the snap results of the mouse down. enable everything for the first snap + this._snapToElements = snapManager.elementSnapEnabledAppLevel(); + this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); this._dragPlane = null; var do3DSnap = true; @@ -132,8 +132,8 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { // { // this.doSelection(event); - snapManager.enableElementSnap ( true ); -// snapManager.enableGridSnap ( true ); + snapManager.enableElementSnap ( true ); +// snapManager.enableGridSnap ( true ); // } // } // else @@ -152,9 +152,9 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { { var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); - // do the snap before setting up the avoid list to allow - // a snap on the mouse down - var hitRec = snapManager.snap(point.x, point.y, do3DSnap); + // do the snap before setting up the avoid list to allow + // a snap on the mouse down + var hitRec = snapManager.snap(point.x, point.y, do3DSnap); // TODO - Check that hitRec's element matches element that browser says we clicked on var elt = this.application.ninja.stage.getElement(event, true); @@ -168,21 +168,21 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { snapManager.addToAvoidList(element); }); - if (hitRec) - { - // disable snap attributes - if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT) - { - this._snapToElements = false; - this._snapToGrid = false; - } - else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER) - { - snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); - } - - // parameterize the snap point on the target - this._snapParam = this.parameterizeSnap( hitRec ); + if (hitRec) + { + // disable snap attributes + if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT) + { + this._snapToElements = false; + this._snapToGrid = false; + } + else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER) + { + snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); + } + + // parameterize the snap point on the target + this._snapParam = this.parameterizeSnap( hitRec ); if(!this._dragPlane) { @@ -201,20 +201,20 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { var sign = MathUtils.fpSign( vecUtils.vecDot(3,this._dragPlane,[0,0,1]) + this._dragPlane[3] - 1.0); this._shouldUseQuadPt = (sign == 0) - var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); - this._mouseDownHitRec = wpHitRec; - this._mouseUpHitRec = null; + var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); + this._mouseDownHitRec = wpHitRec; + this._mouseUpHitRec = null; - var pt = hitRec.getScreenPoint(); - this.downPoint.x = pt[0]; - this.downPoint.y = pt[1]; + var pt = hitRec.getScreenPoint(); + this.downPoint.x = pt[0]; + this.downPoint.y = pt[1]; snapManager.drawLastHit(); snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() ); snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() ); - } + } } else { @@ -223,18 +223,18 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { } }, - /* - * The parameterization is based on the position of the - * snap point in pre-transformed element screen space - */ - parameterizeSnap: - { - value: function( hitRec ) - { - var paramPt = [0,0,0]; + /* + * The parameterization is based on the position of the + * snap point in pre-transformed element screen space + */ + parameterizeSnap: + { + value: function( hitRec ) + { + var paramPt = [0,0,0]; var elt = this._getObjectBeingTracked(hitRec); - if (elt) - { + if (elt) + { this.clickedObject = elt; var worldPt = hitRec.calculateStageWorldPoint(); @@ -246,176 +246,176 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { var scrPt = MathUtils.transformHomogeneousPoint( worldPt, invMat ); scrPt = MathUtils.applyHomogeneousCoordinate( scrPt ); - var bounds = viewUtils.getElementViewBounds3D( elt ); - var x0 = bounds[0][0], x1 = bounds[3][0], - y0 = bounds[0][1], y1 = bounds[1][1]; - var dx = x1 - x0, dy = y1 - y0; - var u = 0, v = 0; - if (MathUtils.fpSign(dx) != 0) - u = (scrPt[0] - x0) / dx; - if (MathUtils.fpSign(dy) != 0) - v = (scrPt[1] - y0) / dy; - - paramPt[0] = u; - paramPt[1] = v; - paramPt[2] = scrPt[2]; - } - } + var bounds = viewUtils.getElementViewBounds3D( elt ); + var x0 = bounds[0][0], x1 = bounds[3][0], + y0 = bounds[0][1], y1 = bounds[1][1]; + var dx = x1 - x0, dy = y1 - y0; + var u = 0, v = 0; + if (MathUtils.fpSign(dx) != 0) + u = (scrPt[0] - x0) / dx; + if (MathUtils.fpSign(dy) != 0) + v = (scrPt[1] - y0) / dy; + + paramPt[0] = u; + paramPt[1] = v; + paramPt[2] = scrPt[2]; + } + } //console.log( "ParameterizeSnap: " + paramPt ); - return paramPt; - } - }, + return paramPt; + } + }, GetObjectHitPoint : - { - value: function() - { - var scrPt; - var elt = this._clickedObject; - if (elt) - { - var bounds = viewUtils.getElementViewBounds3D( elt ); - var x0 = bounds[0][0], x1 = bounds[3][0], - y0 = bounds[0][1], y1 = bounds[1][1]; - var dx = x1 - x0, dy = y1 - y0; - - var x = x0 + this._snapParam[0]*dx, - y = x0 + this._snapParam[1]*dy, - z = this._snapParam[2]; - scrPt = [x,y,z]; - } - - return scrPt; - } - }, - - GetQuadrantSnapPoint: - { - value: function(xEvent, yEvent) - { - var globalPt; - var elt = this._clickedObject; - if (elt && this._snapParam) - { - var tx = this._snapParam[0] <= 0.5 ? 0.0 : 1.0, - ty = this._snapParam[1] <= 0.5 ? 0.0 : 1.0; - - var bounds = viewUtils.getElementViewBounds3D( elt ); - var x0 = bounds[0][0], x1 = bounds[3][0], - y0 = bounds[0][1], y1 = bounds[1][1]; - var dx = x1 - x0, dy = y1 - y0; - - var x = x0 + tx*dx, - y = x0 + ty*dy, - z = 0.0; - var localPt = [x,y,z]; - - globalPt = viewUtils.localToGlobal( localPt, elt ); + { + value: function() + { + var scrPt; + var elt = this._clickedObject; + if (elt) + { + var bounds = viewUtils.getElementViewBounds3D( elt ); + var x0 = bounds[0][0], x1 = bounds[3][0], + y0 = bounds[0][1], y1 = bounds[1][1]; + var dx = x1 - x0, dy = y1 - y0; + + var x = x0 + this._snapParam[0]*dx, + y = x0 + this._snapParam[1]*dy, + z = this._snapParam[2]; + scrPt = [x,y,z]; + } + + return scrPt; + } + }, + + GetQuadrantSnapPoint: + { + value: function(xEvent, yEvent) + { + var globalPt; + var elt = this._clickedObject; + if (elt && this._snapParam) + { + var tx = this._snapParam[0] <= 0.5 ? 0.0 : 1.0, + ty = this._snapParam[1] <= 0.5 ? 0.0 : 1.0; + + var bounds = viewUtils.getElementViewBounds3D( elt ); + var x0 = bounds[0][0], x1 = bounds[3][0], + y0 = bounds[0][1], y1 = bounds[1][1]; + var dx = x1 - x0, dy = y1 - y0; + + var x = x0 + tx*dx, + y = x0 + ty*dy, + z = 0.0; + var localPt = [x,y,z]; + + globalPt = viewUtils.localToGlobal( localPt, elt ); - // add in the delta - var hitPt = this.GetObjectHitPoint(); - var scrPt = viewUtils.localToGlobal( hitPt, this._clickedObject ); - var delta = [xEvent-scrPt[0], yEvent-scrPt[1], 0-scrPt[2]]; - globalPt[0] += delta[0]; - globalPt[1] += delta[1]; + // add in the delta + var hitPt = this.GetObjectHitPoint(); + var scrPt = viewUtils.localToGlobal( hitPt, this._clickedObject ); + var delta = [xEvent-scrPt[0], yEvent-scrPt[1], 0-scrPt[2]]; + globalPt[0] += delta[0]; + globalPt[1] += delta[1]; globalPt[2] += delta[2]; - } - - return globalPt; - } - }, - - GetQuadrantPoint: - { - value: function(useViewPoint) - { - var elt = this._clickedObject; - var tx = this._snapParam[0] <= 0.5 ? 0.0 : 1.0, - ty = this._snapParam[1] <= 0.5 ? 0.0 : 1.0; - - var bounds = viewUtils.getElementViewBounds3D( elt ); - var x0 = bounds[0][0], x1 = bounds[3][0], - y0 = bounds[0][1], y1 = bounds[1][1]; - var dx = x1 - x0, dy = y1 - y0; - - var x = x0 + tx*dx, - y = x0 + ty*dy, - z = 0.0; - var scrPt = [x,y,z]; - - viewUtils.pushViewportObj( elt ); - var viewPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); - viewUtils.popViewportObj(); + } + + return globalPt; + } + }, + + GetQuadrantPoint: + { + value: function(useViewPoint) + { + var elt = this._clickedObject; + var tx = this._snapParam[0] <= 0.5 ? 0.0 : 1.0, + ty = this._snapParam[1] <= 0.5 ? 0.0 : 1.0; + + var bounds = viewUtils.getElementViewBounds3D( elt ); + var x0 = bounds[0][0], x1 = bounds[3][0], + y0 = bounds[0][1], y1 = bounds[1][1]; + var dx = x1 - x0, dy = y1 - y0; + + var x = x0 + tx*dx, + y = x0 + ty*dy, + z = 0.0; + var scrPt = [x,y,z]; + + viewUtils.pushViewportObj( elt ); + var viewPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); + viewUtils.popViewportObj(); if(useViewPoint) - { - return viewPt; - } + { + return viewPt; + } else { return MathUtils.transformPoint( viewPt, this._startMat ); } - } - }, - - GetSourcePointFromBoundary : - { - value: function( index, useViewPoint ) - { - var elt = this._clickedObject; - var bounds = viewUtils.getElementViewBounds3D( elt ); - - var x = bounds[index][0], - y = bounds[index][1], - z = 0; - var scrPt = [x,y,z]; - - viewUtils.pushViewportObj( elt ); - var viewPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); - viewUtils.popViewportObj(); + } + }, + + GetSourcePointFromBoundary : + { + value: function( index, useViewPoint ) + { + var elt = this._clickedObject; + var bounds = viewUtils.getElementViewBounds3D( elt ); + + var x = bounds[index][0], + y = bounds[index][1], + z = 0; + var scrPt = [x,y,z]; + + viewUtils.pushViewportObj( elt ); + var viewPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); + viewUtils.popViewportObj(); - if(useViewPoint) - { - return viewPt; - } + if(useViewPoint) + { + return viewPt; + } else { return MathUtils.transformPoint( viewPt, this._startMat ); } - } - }, - - GetSourcePointFromParameterizedTarget : - { - value: function(useViewPoint) - { - var elt = this._clickedObject; - var bounds = viewUtils.getElementViewBounds3D( elt ); - var x0 = bounds[0][0], x1 = bounds[3][0], - y0 = bounds[0][1], y1 = bounds[1][1]; - var dx = x1 - x0, dy = y1 - y0; - - var x = x0 + this._snapParam[0]*dx, - y = x0 + this._snapParam[1]*dy, - z = this._snapParam[2]; - var scrPt = [x,y,z]; - - viewUtils.pushViewportObj( elt ); - var viewPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); - viewUtils.popViewportObj(); + } + }, + + GetSourcePointFromParameterizedTarget : + { + value: function(useViewPoint) + { + var elt = this._clickedObject; + var bounds = viewUtils.getElementViewBounds3D( elt ); + var x0 = bounds[0][0], x1 = bounds[3][0], + y0 = bounds[0][1], y1 = bounds[1][1]; + var dx = x1 - x0, dy = y1 - y0; + + var x = x0 + this._snapParam[0]*dx, + y = x0 + this._snapParam[1]*dy, + z = this._snapParam[2]; + var scrPt = [x,y,z]; + + viewUtils.pushViewportObj( elt ); + var viewPt = viewUtils.screenToView( scrPt[0], scrPt[1], scrPt[2] ); + viewUtils.popViewportObj(); - if(useViewPoint) - { - return viewPt; - } + if(useViewPoint) + { + return viewPt; + } else { return MathUtils.transformPoint( viewPt, this._startMat ); } - } - }, + } + }, getMousePoints: { value: function() @@ -448,7 +448,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { pt1 = MathUtils.transformPoint( pt1, this._startMat ); } - //console.log( "getMousePoints, useViewPoint: " + useViewPoint + ", " + pt0 + " => " + pt1 ); + //console.log( "getMousePoints, useViewPoint: " + useViewPoint + ", " + pt0 + " => " + pt1 ); return {pt0:pt0, pt1:pt1}; } else @@ -523,65 +523,65 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); var x = point.x, y = point.y; - this._useQuadPt = false; - - /////////////////////////////////////////////////////////// - // do a 3D snap if the mouse button is not down - this._snapIndex = -1; - this._useQuadPt = false; - var mouseIsDown = (this._mouseDownHitRec !== null); - var do3DSnap = (!mouseIsDown || event.shiftKey); - - // set the snapping capabilities - if (mouseIsDown) - { - snapManager.enableElementSnap ( this._snapToElements ); - snapManager.enableGridSnap ( this._snapToGrid ); - } -// else -// { -// this._showFeedbackOnMouseMove(event); -// } - - snapManager.enableElementSnap ( snapManager.elementSnapEnabledAppLevel() ); - snapManager.enableGridSnap ( snapManager.gridSnapEnabledAppLevel() ); - //snapManager.enableSnapAlign ( snapManager.snapAlignEnabledAppLevel() ); - snapManager.enableSnapAlign ( false ); // only snap to element bounds (below) - - // do the snap - var quadPt; - if (mouseIsDown && !do3DSnap && this._shouldUseQuadPt && (this._handleMode === null) && (this._mode === 0)) - quadPt = this.GetQuadrantSnapPoint(x,y); - var hitRec = snapManager.snap(x, y, do3DSnap, quadPt ); - - snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); - if ( snapManager.snapAlignEnabled() && this._clickedObject && + this._useQuadPt = false; + + /////////////////////////////////////////////////////////// + // do a 3D snap if the mouse button is not down + this._snapIndex = -1; + this._useQuadPt = false; + var mouseIsDown = (this._mouseDownHitRec !== null); + var do3DSnap = (!mouseIsDown || event.shiftKey); + + // set the snapping capabilities + if (mouseIsDown) + { + snapManager.enableElementSnap ( this._snapToElements ); + snapManager.enableGridSnap ( this._snapToGrid ); + } +// else +// { +// this._showFeedbackOnMouseMove(event); +// } + + snapManager.enableElementSnap ( snapManager.elementSnapEnabledAppLevel() ); + snapManager.enableGridSnap ( snapManager.gridSnapEnabledAppLevel() ); + //snapManager.enableSnapAlign ( snapManager.snapAlignEnabledAppLevel() ); + snapManager.enableSnapAlign ( false ); // only snap to element bounds (below) + + // do the snap + var quadPt; + if (mouseIsDown && !do3DSnap && this._shouldUseQuadPt && (this._handleMode === null) && (this._mode === 0)) + quadPt = this.GetQuadrantSnapPoint(x,y); + var hitRec = snapManager.snap(x, y, do3DSnap, quadPt ); + + snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); + if ( snapManager.snapAlignEnabled() && this._clickedObject && (this._clickedObject !== this.application.ninja.currentDocument.model.documentRoot) ) - { - var alignBounds = !hitRec || (hitRec.getType() == hitRec.SNAP_TYPE_STAGE) || hitRec.isSomeGridTypeSnap(); - if (alignBounds) - { - // calculate the delta to offset the points of the element by - var scrPt = this.GetObjectHitPoint(); - scrPt = viewUtils.localToGlobal( scrPt, this._clickedObject ); - var delta = [x-scrPt[0], y-scrPt[1]]; - - var alignArray = new Array(); - snapManager.snapAlignToElementBounds( this._clickedObject, delta, alignArray ); - if (alignArray.length > 0) - hitRec = alignArray[0]; - } - } - - if (hitRec) - { - if (mouseIsDown && this._clickedObject) - { - // make the hit record working plane relative - this._snapIndex = hitRec.getSnapBoundaryIndex(); - this._useQuadPt = hitRec.getUseQuadPoint(); - var wp = this._dragPlane ? this._dragPlane : workingPlane; - hitRec = hitRec.convertToWorkingPlane( wp ); + { + var alignBounds = !hitRec || (hitRec.getType() == hitRec.SNAP_TYPE_STAGE) || hitRec.isSomeGridTypeSnap(); + if (alignBounds) + { + // calculate the delta to offset the points of the element by + var scrPt = this.GetObjectHitPoint(); + scrPt = viewUtils.localToGlobal( scrPt, this._clickedObject ); + var delta = [x-scrPt[0], y-scrPt[1]]; + + var alignArray = new Array(); + snapManager.snapAlignToElementBounds( this._clickedObject, delta, alignArray ); + if (alignArray.length > 0) + hitRec = alignArray[0]; + } + } + + if (hitRec) + { + if (mouseIsDown && this._clickedObject) + { + // make the hit record working plane relative + this._snapIndex = hitRec.getSnapBoundaryIndex(); + this._useQuadPt = hitRec.getUseQuadPoint(); + var wp = this._dragPlane ? this._dragPlane : workingPlane; + hitRec = hitRec.convertToWorkingPlane( wp ); // update the target this._mouseUpHitRec = hitRec; @@ -589,8 +589,8 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { this.upPoint.x = pt[0]; this.upPoint.y = pt[1]; this.upPoint.z = pt[2]; - } - } + } + } } }, @@ -634,15 +634,15 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { this.mouseUpHitRec = null; this._dragPlane = null; - this._useQuadPt = false; + this._useQuadPt = false; - snapManager.clearAvoidList(); - snapManager.clearDragPlane(); + snapManager.clearAvoidList(); + snapManager.clearDragPlane(); - // restore the snap settings - snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); - snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() ); - snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() ); + // restore the snap settings + snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); + snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() ); + snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() ); } }, //------------------------------------------------------------------------- @@ -680,21 +680,21 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { _target: { value: null }, target: { - get: function () { - return this._target; - }, - set: function (value) { - this._target = value; - if (value === null) + get: function () { + return this._target; + }, + set: function (value) { + this._target = value; + if (value === null) { - return; - } + return; + } if (this._target.elementModel && this._target.elementModel.props3D) { - // do nothing - } - else + // do nothing + } + else { console.warn("no props3D model"); // if(!this._target.elementModel) @@ -709,10 +709,10 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { // controller: { value: ControllerFactory.getController(controller)}, // props3D: { value: p3d} // }); -// this._target.props3D = Object.create(Properties3D, {}); -// this._target.props3D.Init(this._target); - } - } +// this._target.props3D = Object.create(Properties3D, {}); +// this._target.props3D.Init(this._target); + } + } }, _startMat: { value: Matrix.I(4) }, @@ -781,42 +781,42 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { }, captureSelectionChange: { - value: function(event){ - this.eventManager.addEventListener("selectionDrawn", this, true); - } - }, + value: function(event){ + this.eventManager.addEventListener("selectionDrawn", this, true); + } + }, - captureSelectionDrawn: { - value: function(event){ + captureSelectionDrawn: { + value: function(event){ this._origin = null; this._delta = null; - var len = this.application.ninja.selectedElements.length; - if(len) - { - if(len === 1) - { - this.target = this.application.ninja.selectedElements[0]; - drawUtils.addElement(this.target); - } - else - { - this.target = this.application.ninja.currentDocument.model.documentRoot; - } -// this._updateTargets(); - } - else - { - this.target = null; - } - this.DrawHandles(); - - if(event) - { + var len = this.application.ninja.selectedElements.length; + if(len) + { + if(len === 1) + { + this.target = this.application.ninja.selectedElements[0]; + drawUtils.addElement(this.target); + } + else + { + this.target = this.application.ninja.currentDocument.model.documentRoot; + } +// this._updateTargets(); + } + else + { + this.target = null; + } + this.DrawHandles(); + + if(event) + { this.eventManager.removeEventListener("selectionDrawn", this, true); - } - } - }, + } + } + }, //------------------------------------------------------------------------- //------------------------------------------------------------------------- @@ -865,7 +865,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { } } - if (!this._isDrawing || (this.application.ninja.selectedElements.length == 1)) + if (!this._isDrawing || (this.application.ninja.selectedElements.length == 1)) this.DrawHandles(this._delta); if(this._canSnap) @@ -908,19 +908,19 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { } this.endDraw(event); - this.application.ninja.stage.draw(); - if (this.application.ninja.selectedElements.length > 1) - { - //this._origin = null; - this._updateHandlesOrigin(); - } + this.application.ninja.stage.draw(); + if (this.application.ninja.selectedElements.length > 1) + { + //this._origin = null; + this._updateHandlesOrigin(); + } this.DrawHandles(); } }, - _updateHandlesOrigin: { - value: function () { } - }, + _updateHandlesOrigin: { + value: function () { } + }, handleToolDoubleClick: { value: function(event) { @@ -952,46 +952,46 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { }, /** - * This function is for specifying custom feedback routine - * upon mouse over. - * For example, the drawing tools will add a glow when mousing - * over existing canvas elements to signal to the user that - * the drawing operation will act on the targeted canvas. - */ - _showFeedbackOnMouseMove : { - value: function (event) { - if(this._target && this._handles) - { - var len = this._handles.length; - var i = 0, - toolHandle, - c, + * This function is for specifying custom feedback routine + * upon mouse over. + * For example, the drawing tools will add a glow when mousing + * over existing canvas elements to signal to the user that + * the drawing operation will act on the targeted canvas. + */ + _showFeedbackOnMouseMove : { + value: function (event) { + if(this._target && this._handles) + { + var len = this._handles.length; + var i = 0, + toolHandle, + c, point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); - for (i=0; i