aboutsummaryrefslogtreecommitdiff
path: root/js/tools/ShapeTool.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/ShapeTool.js')
-rwxr-xr-xjs/tools/ShapeTool.js44
1 files changed, 24 insertions, 20 deletions
diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js
index 6956aea8..03ddc391 100755
--- a/js/tools/ShapeTool.js
+++ b/js/tools/ShapeTool.js
@@ -55,23 +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 63 h = Math.floor(this.drawData.height);
64 var styles = document.application.njUtils.stylesFromDraw(canvas, ~~drawData.width, ~~drawData.height, drawData); 64
65 this.application.ninja.elementMediator.addElements(canvas, styles); 65 if( (w > 0) && (h > 0) ) {
66 } else { 66 if(!this._useExistingCanvas()) {
67 canvas = this._targetedElement; 67 canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument);
68 if (!canvas.getAttribute( "data-RDGE-id" )) 68
69 canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() ); 69 var styles = document.application.njUtils.stylesFromDraw(canvas, w, h, this.drawData);
70 canvas.elementModel.controller = ShapesController; 70 this.application.ninja.elementMediator.addElements(canvas, styles);
71 if(!canvas.elementModel.shapeModel) { 71 } else {
72 canvas.elementModel.shapeModel = Montage.create(ShapeModel); 72 canvas = this._targetedElement;
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);
73 } 80 }
74 this.RenderShape(drawData.width, drawData.height, drawData.planeMat, drawData.midPt, canvas);
75 } 81 }
76 } 82 }
77 83
@@ -86,10 +92,8 @@ exports.ShapeTool = Montage.create(DrawingTool, {
86 92
87 onAddElements: { 93 onAddElements: {
88 value: function(el) { 94 value: function(el) {
89 var drawData; 95 if(this.drawData) {
90 96 this.RenderShape(this.drawData.width, this.drawData.height, this.drawData.planeMat, this.drawData.midPt, el);
91 if(drawData = this.getDrawingData()) {
92 this.RenderShape(drawData.width, drawData.height, drawData.planeMat, drawData.midPt, el);
93 } 97 }
94 } 98 }
95 }, 99 },