aboutsummaryrefslogtreecommitdiff
path: root/js/tools/ShapeTool.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-04-30 14:49:49 -0700
committerValerio Virgillito2012-04-30 14:49:49 -0700
commit6b1a6994d98a18b45016b97ac8d81483109a586c (patch)
treecda8a39f8813fb5c0f9b4fb1d37007e6ec971128 /js/tools/ShapeTool.js
parentc8fac64d4ad8ac18744a17a5e0f0d17204355fd6 (diff)
parent48e442977ef1630e0f664265a7142320b55d7d20 (diff)
downloadninja-6b1a6994d98a18b45016b97ac8d81483109a586c.tar.gz
Merge pull request #182 from ericmueller/Canvas-interaction
Canvas interaction
Diffstat (limited to 'js/tools/ShapeTool.js')
-rwxr-xr-xjs/tools/ShapeTool.js40
1 files changed, 29 insertions, 11 deletions
diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js
index 21a5a025..c0681200 100755
--- a/js/tools/ShapeTool.js
+++ b/js/tools/ShapeTool.js
@@ -54,9 +54,9 @@ exports.ShapeTool = Montage.create(DrawingTool, {
54 }, 54 },
55 55
56 HandleLeftButtonUp: 56 HandleLeftButtonUp:
57 { 57 {
58 value: function (event) 58 value: function (event)
59 { 59 {
60 var drawData; 60 var drawData;
61 61
62 drawData = this.getDrawingData(); 62 drawData = this.getDrawingData();
@@ -64,29 +64,34 @@ 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);
70 71
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;
77 if (!canvas.getAttribute( "data-RDGE-id" ))
78 canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() );
75 canvas.elementModel.controller = ShapesController; 79 canvas.elementModel.controller = ShapesController;
76 if(!canvas.elementModel.shapeModel) { 80 if(!canvas.elementModel.shapeModel) {
77 canvas.elementModel.shapeModel = Montage.create(ShapeModel); 81 canvas.elementModel.shapeModel = Montage.create(ShapeModel);
78 } 82 }
83 this.application.ninja.elementMediator.addElements(canvas, canvas.elementModel.data);
79 } 84 }
80 } 85 }
81 86
82 this.endDraw(event); 87 this.endDraw(event);
83 88
84 this._isDrawing = false; 89 this._isDrawing = false;
85 this._hasDraw=false; 90 this._hasDraw=false;
86 91
87 this.DrawHandles(); 92 this.DrawHandles();
88 } 93 }
89 }, 94 },
90 95
91 onAddElements: { 96 onAddElements: {
92 value: function(el) { 97 value: function(el) {
@@ -211,7 +216,20 @@ exports.ShapeTool = Montage.create(DrawingTool, {
211 _useExistingCanvas: { 216 _useExistingCanvas: {
212 value: function() 217 value: function()
213 { 218 {
214 return (this._targetedElement && !ShapesController.isElementAShape(this._targetedElement)); 219 var target;
220 if (this._targetedElement && (this._targetedElement.nodeName === "CANVAS") && !ShapesController.isElementAShape(this._targetedElement))
221 target = this._targetedElement;
222 else
223 {
224 var container = this.application.ninja.currentSelectedContainer;
225 if (container && (container.nodeName === "CANVAS"))
226 {
227 target = container;
228 this._targetedElement = target;
229 }
230 }
231
232 return target;
215 } 233 }
216 } 234 }
217 235