aboutsummaryrefslogtreecommitdiff
path: root/js/tools/ShapeTool.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/ShapeTool.js')
-rwxr-xr-xjs/tools/ShapeTool.js51
1 files changed, 27 insertions, 24 deletions
diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js
index 367ab78d..8d381711 100755
--- a/js/tools/ShapeTool.js
+++ b/js/tools/ShapeTool.js
@@ -55,24 +55,29 @@ exports.ShapeTool = Montage.create(DrawingTool, {
55 55
56 HandleLeftButtonUp: { 56 HandleLeftButtonUp: {
57 value: function (event) { 57 value: function (event) {
58 var canvas, drawData = this.getDrawingData(); 58 var canvas, w, h;
59 59 this.drawData = this.getDrawingData();
60 if(drawData) { 60
61 if(!this._useExistingCanvas()) { 61 if(this.drawData) {
62 canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument); 62 w = Math.floor(this.drawData.width);
63 document.application.njUtils.createModelWithShape(canvas); 63 h = Math.floor(this.drawData.height);
64 64
65 var styles = document.application.njUtils.stylesFromDraw(canvas, ~~drawData.width, ~~drawData.height, drawData); 65 if( (w > 0) && (h > 0) ) {
66 this.application.ninja.elementMediator.addElements(canvas, styles); 66 if(!this._useExistingCanvas()) {
67 } else { 67 canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument);
68 canvas = this._targetedElement; 68
69 if (!canvas.getAttribute( "data-RDGE-id" )) 69 var styles = document.application.njUtils.stylesFromDraw(canvas, w, h, this.drawData);
70 canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() ); 70 this.application.ninja.elementMediator.addElements(canvas, styles);
71 canvas.elementModel.controller = ShapesController; 71 } else {
72 if(!canvas.elementModel.shapeModel) { 72 canvas = this._targetedElement;
73 canvas.elementModel.shapeModel = Montage.create(ShapeModel); 73 if (!canvas.getAttribute( "data-RDGE-id" ))
74 canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() );
75 canvas.elementModel.controller = ShapesController;
76 if(!canvas.elementModel.shapeModel) {
77 canvas.elementModel.shapeModel = Montage.create(ShapeModel);
78 }
79 this.RenderShape(w, h, this.drawData.planeMat, this.drawData.midPt, canvas);
74 } 80 }
75 this.RenderShape(drawData.width, drawData.height, drawData.planeMat, drawData.midPt, canvas);
76 } 81 }
77 } 82 }
78 83
@@ -87,10 +92,8 @@ exports.ShapeTool = Montage.create(DrawingTool, {
87 92
88 onAddElements: { 93 onAddElements: {
89 value: function(el) { 94 value: function(el) {
90 var drawData; 95 if(this.drawData) {
91 96 this.RenderShape(this.drawData.width, this.drawData.height, this.drawData.planeMat, this.drawData.midPt, el);
92 if(drawData = this.getDrawingData()) {
93 this.RenderShape(drawData.width, drawData.height, drawData.planeMat, drawData.midPt, el);
94 } 97 }
95 } 98 }
96 }, 99 },
@@ -100,8 +103,8 @@ exports.ShapeTool = Montage.create(DrawingTool, {
100 if(wasSelected) { 103 if(wasSelected) {
101 this.AddCustomFeedback(); 104 this.AddCustomFeedback();
102 this.application.ninja.elementMediator.addDelegate = this; 105 this.application.ninja.elementMediator.addDelegate = this;
103 if(this.application.ninja.currentSelectedContainer.nodeName === "CANVAS") { 106 if(this.application.ninja.currentDocument.model.domContainer.nodeName === "CANVAS") {
104 this._targetedElement = this.application.ninja.currentSelectedContainer; 107 this._targetedElement = this.application.ninja.currentDocument.model.domContainer;
105 } 108 }
106 } else { 109 } else {
107 this.RemoveCustomFeedback(); 110 this.RemoveCustomFeedback();
@@ -196,7 +199,7 @@ exports.ShapeTool = Montage.create(DrawingTool, {
196 target = this._targetedElement; 199 target = this._targetedElement;
197 else 200 else
198 { 201 {
199 var container = this.application.ninja.currentSelectedContainer; 202 var container = this.application.ninja.currentDocument.model.domContainer;
200 if (container && (container.nodeName === "CANVAS")) 203 if (container && (container.nodeName === "CANVAS"))
201 { 204 {
202 target = container; 205 target = container;