From 355656cac2fa1a025ad97791ea095a54cebdff71 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 1 May 2012 20:13:58 -0700 Subject: Support drawing in side and top view. Also, adding back support for drawing shapes inside canvas when double-clicked into canvas or when moused over canvas. Signed-off-by: Nivesh Rajbhandari --- js/tools/ShapeTool.js | 3 +++ js/tools/drawing-tool-base.js | 63 ++++++++++++++++++++++++------------------- js/tools/drawing-tool.js | 3 ++- 3 files changed, 41 insertions(+), 28 deletions(-) (limited to 'js/tools') diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js index 8f45891d..d2337000 100755 --- a/js/tools/ShapeTool.js +++ b/js/tools/ShapeTool.js @@ -106,6 +106,9 @@ exports.ShapeTool = Montage.create(DrawingTool, { if(wasSelected) { this.AddCustomFeedback(); this.application.ninja.elementMediator.addDelegate = this; + if(this.application.ninja.currentSelectedContainer.nodeName === "CANVAS") { + this._targetedElement = this.application.ninja.currentSelectedContainer; + } } else { this.RemoveCustomFeedback(); this.application.ninja.elementMediator.addDelegate = null; diff --git a/js/tools/drawing-tool-base.js b/js/tools/drawing-tool-base.js index 0b51aa28..7d97f105 100755 --- a/js/tools/drawing-tool-base.js +++ b/js/tools/drawing-tool-base.js @@ -24,6 +24,9 @@ exports.DrawingToolBase = Montage.create(Montage, { value: null }, + dragPlane: { + value: null + }, /** * Used on the initial MouseDown for Drawing Tools * @@ -33,28 +36,30 @@ exports.DrawingToolBase = Montage.create(Montage, { * 2 - Y value converted to screen point */ getInitialSnapPoint: { - value: function(x,y) { + value: function(x, y, shapeCanvas) { + snapManager.clearDragPlane(); + // update the snap settings snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() ); snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() ); // do the snap - var hitRec = snapManager.snap(x, y, true); - var dragPlane; + this.dragPlane = null; + var hitRec = snapManager.snap(x, y, true); if (hitRec) { - // set up the working plane and convert the hit record to be working plane relative - if (hitRec.getElement() === snapManager.application.ninja.currentSelectedContainer) + if (shapeCanvas) { - dragPlane = viewUtils.getUnprojectedElementPlane( hitRec.getElement() ); - snapManager.setupDragPlaneFromPlane( dragPlane ); + this.dragPlane = viewUtils.getUnprojectedElementPlane( shapeCanvas ); + snapManager.setupDragPlaneFromPlane( this.dragPlane ); } else { - dragPlane = snapManager.setupDragPlanes( hitRec ); + this.dragPlane = snapManager.setupDragPlanes( hitRec, true ); } +// console.log( "drag plane: " + this.dragPlane ); - var wpHitRec = hitRec.convertToWorkingPlane( dragPlane ); + var wpHitRec = hitRec.convertToWorkingPlane( this.dragPlane ); var pt = hitRec.getScreenPoint(); return( [wpHitRec, pt[0], pt[1]] ); @@ -72,28 +77,32 @@ exports.DrawingToolBase = Montage.create(Montage, { snapManager.enableElementSnap( snapManager.elementSnapEnabledAppLevel() ); snapManager.enableGridSnap( snapManager.gridSnapEnabledAppLevel() ); - - // do the first snap var hitRec = snapManager.snap(x, y, snap3d ); if (hitRec) { - if ((hitRec.getType() !== hitRec.SNAP_TYPE_STAGE) && !hitRec.isSomeGridTypeSnap()) { - hitRec = hitRec.convertToWorkingPlane( snapManager.getDragPlane() ); - } - - if(downHitRec !== null) { - // if we are working off-plane, do a snap to the projected locations of the geometry - var thePlane = workingPlane; - if (snapManager.hasDragPlane()) - { - thePlane = snapManager.getDragPlane(); - } - - // Return the up HitRec - return hitRec; - } else { - return null; +// if ((hitRec.getType() !== hitRec.SNAP_TYPE_STAGE) && !hitRec.isSomeGridTypeSnap()) { +// hitRec = hitRec.convertToWorkingPlane( snapManager.getDragPlane() ); +// } +// +// if(downHitRec !== null) { +// // if we are working off-plane, do a snap to the projected locations of the geometry +// var thePlane = workingPlane; +// if (snapManager.hasDragPlane()) +// { +// thePlane = snapManager.getDragPlane(); +// } +// +// // Return the up HitRec +// return hitRec; +// } else { +// return null; +// } + if(downHitRec) { + hitRec = hitRec.convertToWorkingPlane(this.dragPlane); + } else if ((hitRec.getType() !== hitRec.SNAP_TYPE_STAGE) && !hitRec.isSomeGridTypeSnap()) { + hitRec = hitRec.convertToWorkingPlane( snapManager.getDragPlane() ); } } + return hitRec; } }, diff --git a/js/tools/drawing-tool.js b/js/tools/drawing-tool.js index dc5f7996..d906fdf9 100755 --- a/js/tools/drawing-tool.js +++ b/js/tools/drawing-tool.js @@ -72,10 +72,11 @@ exports.DrawingTool = Montage.create(ToolBase, { var snapData, point; this._isDrawing = true; + this.mouseDownHitRec = null; this.mouseUpHitRec = null; point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); - snapData = DrawingToolBase.getInitialSnapPoint(point.x, point.y); //event.layerX, event.layerY); + snapData = DrawingToolBase.getInitialSnapPoint(point.x, point.y, this._targetedElement); //event.layerX, event.layerY); this.mouseDownHitRec = snapData[0]; this.downPoint.x = snapData[1]; this.downPoint.y = snapData[2]; -- cgit v1.2.3