From e73fba18b095f0c270f5d954e5993c155b488c73 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 27 Apr 2012 13:52:40 -0700 Subject: Creating shapes in a container --- js/helper-classes/3D/snap-manager.js | 3 ++- js/tools/SelectionTool.js | 2 ++ js/tools/ShapeTool.js | 2 ++ js/tools/drawing-tool-base.js | 13 +++++++++++-- 4 files changed, 17 insertions(+), 3 deletions(-) (limited to 'js') diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index dcfd5ddc..7fc492a5 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -1011,7 +1011,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { } // hit test the current object var hit; - if (depth > 0) // don't snap to the root + var snapToStage = ((depth === 0) && (elt === this.application.ninja.currentSelectedContainer) && (elt.nodeName === 'CANVAS')); + if ((depth > 0) || snapToStage) // don't snap to the root unles we are working inside a canvas { // if the element is in the 2D cache snapping is done there if (elt.elementModel && !elt.elementModel.isIn2DSnapCache) diff --git a/js/tools/SelectionTool.js b/js/tools/SelectionTool.js index 7033ee3d..9c9aee93 100755 --- a/js/tools/SelectionTool.js +++ b/js/tools/SelectionTool.js @@ -222,8 +222,10 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { value: function(event) { if(this.application.ninja.selectedElements.length > 0) { this.application.ninja.currentSelectedContainer = this.application.ninja.selectedElements[0]; + console.log( "setting container to selected element" ); } else { this.application.ninja.currentSelectedContainer = this.application.ninja.currentDocument.documentRoot; + console.log( "setting container to stage" ); } } }, diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js index 74e692b6..90b403a4 100755 --- a/js/tools/ShapeTool.js +++ b/js/tools/ShapeTool.js @@ -64,6 +64,7 @@ exports.ShapeTool = Montage.create(DrawingTool, { if(drawData) { var canvas; if(!this._useExistingCanvas()) { + console.log( "creating a new canvas" ); canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); var elementModel = TagTool.makeElement(~~drawData.width, ~~drawData.height, drawData.planeMat, drawData.midPt, canvas, true); @@ -71,6 +72,7 @@ exports.ShapeTool = Montage.create(DrawingTool, { canvas.elementModel.isShape = true; this.application.ninja.elementMediator.addElements(canvas, elementModel.data); } else { + console.log( "inserting shape into container" ); canvas = this._targetedElement; if (!canvas.getAttribute( "data-RDGE-id" )) canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() ); diff --git a/js/tools/drawing-tool-base.js b/js/tools/drawing-tool-base.js index 2283dfab..0b51aa28 100755 --- a/js/tools/drawing-tool-base.js +++ b/js/tools/drawing-tool-base.js @@ -41,11 +41,20 @@ exports.DrawingToolBase = Montage.create(Montage, { // do the snap var hitRec = snapManager.snap(x, y, true); + var dragPlane; if (hitRec) { // set up the working plane and convert the hit record to be working plane relative - var dragPlane = snapManager.setupDragPlanes( hitRec ); - var wpHitRec = hitRec.convertToWorkingPlane( dragPlane ); + if (hitRec.getElement() === snapManager.application.ninja.currentSelectedContainer) + { + dragPlane = viewUtils.getUnprojectedElementPlane( hitRec.getElement() ); + snapManager.setupDragPlaneFromPlane( dragPlane ); + } + else + { + dragPlane = snapManager.setupDragPlanes( hitRec ); + } + var wpHitRec = hitRec.convertToWorkingPlane( dragPlane ); var pt = hitRec.getScreenPoint(); return( [wpHitRec, pt[0], pt[1]] ); -- cgit v1.2.3