diff options
author | hwc487 | 2012-04-27 13:52:40 -0700 |
---|---|---|
committer | hwc487 | 2012-04-27 13:52:40 -0700 |
commit | e73fba18b095f0c270f5d954e5993c155b488c73 (patch) | |
tree | da18c6c0117fec3652b823bddc198add47632fc8 | |
parent | 4b83774cdbfbf30add9a8fa2f11b1c4ff35179fa (diff) | |
download | ninja-e73fba18b095f0c270f5d954e5993c155b488c73.tar.gz |
Creating shapes in a container
-rwxr-xr-x | js/helper-classes/3D/snap-manager.js | 3 | ||||
-rwxr-xr-x | js/tools/SelectionTool.js | 2 | ||||
-rwxr-xr-x | js/tools/ShapeTool.js | 2 | ||||
-rwxr-xr-x | js/tools/drawing-tool-base.js | 13 |
4 files changed, 17 insertions, 3 deletions
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, { | |||
1011 | } | 1011 | } |
1012 | // hit test the current object | 1012 | // hit test the current object |
1013 | var hit; | 1013 | var hit; |
1014 | if (depth > 0) // don't snap to the root | 1014 | var snapToStage = ((depth === 0) && (elt === this.application.ninja.currentSelectedContainer) && (elt.nodeName === 'CANVAS')); |
1015 | if ((depth > 0) || snapToStage) // don't snap to the root unles we are working inside a canvas | ||
1015 | { | 1016 | { |
1016 | // if the element is in the 2D cache snapping is done there | 1017 | // if the element is in the 2D cache snapping is done there |
1017 | if (elt.elementModel && !elt.elementModel.isIn2DSnapCache) | 1018 | 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, { | |||
222 | value: function(event) { | 222 | value: function(event) { |
223 | if(this.application.ninja.selectedElements.length > 0) { | 223 | if(this.application.ninja.selectedElements.length > 0) { |
224 | this.application.ninja.currentSelectedContainer = this.application.ninja.selectedElements[0]; | 224 | this.application.ninja.currentSelectedContainer = this.application.ninja.selectedElements[0]; |
225 | console.log( "setting container to selected element" ); | ||
225 | } else { | 226 | } else { |
226 | this.application.ninja.currentSelectedContainer = this.application.ninja.currentDocument.documentRoot; | 227 | this.application.ninja.currentSelectedContainer = this.application.ninja.currentDocument.documentRoot; |
228 | console.log( "setting container to stage" ); | ||
227 | } | 229 | } |
228 | } | 230 | } |
229 | }, | 231 | }, |
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, { | |||
64 | if(drawData) { | 64 | if(drawData) { |
65 | var canvas; | 65 | var canvas; |
66 | if(!this._useExistingCanvas()) { | 66 | if(!this._useExistingCanvas()) { |
67 | console.log( "creating a new canvas" ); | ||
67 | canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); | 68 | canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); |
68 | var elementModel = TagTool.makeElement(~~drawData.width, ~~drawData.height, | 69 | var elementModel = TagTool.makeElement(~~drawData.width, ~~drawData.height, |
69 | drawData.planeMat, drawData.midPt, canvas, true); | 70 | drawData.planeMat, drawData.midPt, canvas, true); |
@@ -71,6 +72,7 @@ exports.ShapeTool = Montage.create(DrawingTool, { | |||
71 | canvas.elementModel.isShape = true; | 72 | canvas.elementModel.isShape = true; |
72 | this.application.ninja.elementMediator.addElements(canvas, elementModel.data); | 73 | this.application.ninja.elementMediator.addElements(canvas, elementModel.data); |
73 | } else { | 74 | } else { |
75 | console.log( "inserting shape into container" ); | ||
74 | canvas = this._targetedElement; | 76 | canvas = this._targetedElement; |
75 | if (!canvas.getAttribute( "data-RDGE-id" )) | 77 | if (!canvas.getAttribute( "data-RDGE-id" )) |
76 | canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() ); | 78 | 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, { | |||
41 | 41 | ||
42 | // do the snap | 42 | // do the snap |
43 | var hitRec = snapManager.snap(x, y, true); | 43 | var hitRec = snapManager.snap(x, y, true); |
44 | var dragPlane; | ||
44 | if (hitRec) { | 45 | if (hitRec) { |
45 | // set up the working plane and convert the hit record to be working plane relative | 46 | // set up the working plane and convert the hit record to be working plane relative |
46 | var dragPlane = snapManager.setupDragPlanes( hitRec ); | 47 | if (hitRec.getElement() === snapManager.application.ninja.currentSelectedContainer) |
47 | var wpHitRec = hitRec.convertToWorkingPlane( dragPlane ); | 48 | { |
49 | dragPlane = viewUtils.getUnprojectedElementPlane( hitRec.getElement() ); | ||
50 | snapManager.setupDragPlaneFromPlane( dragPlane ); | ||
51 | } | ||
52 | else | ||
53 | { | ||
54 | dragPlane = snapManager.setupDragPlanes( hitRec ); | ||
55 | } | ||
48 | 56 | ||
57 | var wpHitRec = hitRec.convertToWorkingPlane( dragPlane ); | ||
49 | var pt = hitRec.getScreenPoint(); | 58 | var pt = hitRec.getScreenPoint(); |
50 | 59 | ||
51 | return( [wpHitRec, pt[0], pt[1]] ); | 60 | return( [wpHitRec, pt[0], pt[1]] ); |