aboutsummaryrefslogtreecommitdiff
path: root/js/tools/LineTool.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-04-16 16:06:24 -0700
committerNivesh Rajbhandari2012-04-16 16:06:24 -0700
commitc253192a08b499ea7be46fa5438d273e51f7ec5a (patch)
tree18a1f0e3679c0eb993a9dedb537035d3861f49ac /js/tools/LineTool.js
parente19376c54eedd1f1c457ba405b2f110be376a559 (diff)
parent4b900ea5cd6bb77eb30cec8c03b9ec9fa662c1e9 (diff)
downloadninja-c253192a08b499ea7be46fa5438d273e51f7ec5a.tar.gz
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'js/tools/LineTool.js')
-rwxr-xr-xjs/tools/LineTool.js120
1 files changed, 62 insertions, 58 deletions
diff --git a/js/tools/LineTool.js b/js/tools/LineTool.js
index a61f8f79..3e9167fd 100755
--- a/js/tools/LineTool.js
+++ b/js/tools/LineTool.js
@@ -7,7 +7,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
7var Montage = require("montage/core/core").Montage, 7var Montage = require("montage/core/core").Montage,
8 ShapeTool = require("js/tools/ShapeTool").ShapeTool, 8 ShapeTool = require("js/tools/ShapeTool").ShapeTool,
9 DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase, 9 DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase,
10 ElementMediator = require("js/mediators/element-mediator").ElementMediator,
11 NJUtils = require("js/lib/NJUtils").NJUtils, 10 NJUtils = require("js/lib/NJUtils").NJUtils,
12 TagTool = require("js/tools/TagTool").TagTool, 11 TagTool = require("js/tools/TagTool").TagTool,
13 ShapesController = require("js/controllers/elements/shapes-controller").ShapesController, 12 ShapesController = require("js/controllers/elements/shapes-controller").ShapesController,
@@ -53,59 +52,43 @@ exports.LineTool = Montage.create(ShapeTool, {
53 } 52 }
54 }, 53 },
55 54
56 HandleLeftButtonUp: 55 HandleLeftButtonUp: {
57 { 56 value: function (event) {
58 value: function (event) 57 var slope = this._getSlope(), drawData = this.getDrawingData();
59 {
60 var slope = this._getSlope(),
61 drawData = this.getDrawingData();
62 58
63 if(drawData) { 59 if(drawData) {
64 var canvas, 60 var canvas, xAdj = 0, yAdj = 0, w, h;
65 xAdj = 0, 61 if(!this._useExistingCanvas()) {
66 yAdj = 0, 62 if(drawData = this.getDrawingData()) {
67 w = ~~drawData.width, 63 // set the dimensions
68 h = ~~drawData.height; 64 w = ~~drawData.width;
69 if(!this._useExistingCanvas()) 65 h = ~~drawData.height;
70 { 66 if(slope === "horizontal") {
71 // set the dimensions 67 h = Math.max(this._strokeSize, 1);
72 if(slope === "horizontal") 68 } else if(slope === "vertical") {
73 { 69 w = Math.max(this._strokeSize, 1);
74 h = Math.max(this._strokeSize, 1); 70 } else {
75 } 71 // else make the line's stroke fit inside the canvas by growing the canvas
76 else if(slope === "vertical") 72 var theta = Math.atan(slope);
77 { 73 xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta));
78 w = Math.max(this._strokeSize, 1); 74 yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta));
75
76 w += ~~(xAdj*2);
77 h += ~~(yAdj*2);
78 }
79
80 canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true);
81 var elementModel = TagTool.makeElement(w, h, drawData.planeMat, drawData.midPt, canvas, true);
82 canvas.elementModel.isShape = true;
83 this.application.ninja.elementMediator.addElements(canvas, elementModel.data);
84 } else {
85 canvas = this._targetedElement;
86 canvas.elementModel.controller = ShapesController;
87 if(!canvas.elementModel.shapeModel) {
88 canvas.elementModel.shapeModel = Montage.create(ShapeModel);
89 }
79 } 90 }
80 else
81 {
82 // else make the line's stroke fit inside the canvas by growing the canvas
83 var theta = Math.atan(slope);
84 xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta));
85 yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta));
86
87 w += ~~(xAdj*2);
88 h += ~~(yAdj*2);
89 }
90
91 canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true);
92 var elementModel = TagTool.makeElement(w, h, drawData.planeMat, drawData.midPt, canvas);
93
94 ElementMediator.addElement(canvas, elementModel.data, true);
95 canvas.elementModel.isShape = true;
96 } 91 }
97 else
98 {
99 canvas = this._targetedElement;
100 canvas.elementModel.controller = ShapesController;
101 if(!canvas.elementModel.shapeModel)
102 {
103 canvas.elementModel.shapeModel = Montage.create(ShapeModel);
104 }
105 }
106 this.RenderShape(w, h, drawData.planeMat, drawData.midPt,
107 canvas, slope, xAdj, yAdj);
108 NJevent("elementAdded", canvas);
109 } 92 }
110 93
111 this.endDraw(event); 94 this.endDraw(event);
@@ -113,11 +96,37 @@ exports.LineTool = Montage.create(ShapeTool, {
113 this._isDrawing = false; 96 this._isDrawing = false;
114 this._hasDraw=false; 97 this._hasDraw=false;
115 98
116
117 this.DrawHandles(); 99 this.DrawHandles();
118 } 100 }
119 }, 101 },
120 102
103 onAddElements: {
104 value: function(el) {
105 var drawData, xAdj = 0, yAdj = 0, w, h, slope = this._getSlope();
106
107 if(drawData = this.getDrawingData()) {
108 // set the dimensions
109 w = ~~drawData.width;
110 h = ~~drawData.height;
111 if(slope === "horizontal") {
112 h = Math.max(this._strokeSize, 1);
113 } else if(slope === "vertical") {
114 w = Math.max(this._strokeSize, 1);
115 } else {
116 // else make the line's stroke fit inside the canvas by growing the canvas
117 var theta = Math.atan(slope);
118 xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta));
119 yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta));
120
121 w += ~~(xAdj*2);
122 h += ~~(yAdj*2);
123 }
124
125 this.RenderShape(w, h, drawData.planeMat, drawData.midPt, el, slope, xAdj, yAdj);
126 }
127 }
128 },
129
121 _getSlope: { 130 _getSlope: {
122 value: function() { 131 value: function() {
123 var hitRec0 = this._mouseDownHitRec, 132 var hitRec0 = this._mouseDownHitRec,
@@ -216,6 +225,7 @@ exports.LineTool = Montage.create(ShapeTool, {
216 { 225 {
217 strokeMaterial = Object.create(MaterialsModel.getMaterial(strokeM)); 226 strokeMaterial = Object.create(MaterialsModel.getMaterial(strokeM));
218 } 227 }
228 strokeColor = ShapesController.getMaterialColor(strokeM) || strokeColor;
219 } 229 }
220 230
221 var world = this.getGLWorld(canvas, this.options.use3D); 231 var world = this.getGLWorld(canvas, this.options.use3D);
@@ -234,19 +244,13 @@ exports.LineTool = Montage.create(ShapeTool, {
234 canvas.elementModel.selection = "Line"; 244 canvas.elementModel.selection = "Line";
235 canvas.elementModel.pi = "LinePi"; 245 canvas.elementModel.pi = "LinePi";
236 canvas.elementModel.shapeModel.strokeSize = this.options.strokeSize.value + " " + this.options.strokeSize.units; 246 canvas.elementModel.shapeModel.strokeSize = this.options.strokeSize.value + " " + this.options.strokeSize.units;
237 canvas.elementModel.shapeModel.stroke = strokeColor;
238 if(strokeColor)
239 {
240 canvas.elementModel.shapeModel.border = this.application.ninja.colorController.colorToolbar.stroke;
241 }
242
243 canvas.elementModel.shapeModel.strokeMaterial = strokeMaterial;
244 247
245 canvas.elementModel.shapeModel.strokeStyleIndex = strokeStyleIndex; 248 canvas.elementModel.shapeModel.strokeStyleIndex = strokeStyleIndex;
246 canvas.elementModel.shapeModel.strokeStyle = strokeStyle; 249 canvas.elementModel.shapeModel.strokeStyle = strokeStyle;
247 250
248 canvas.elementModel.shapeModel.GLGeomObj = line; 251 canvas.elementModel.shapeModel.GLGeomObj = line;
249 canvas.elementModel.shapeModel.useWebGl = this.options.use3D; 252 canvas.elementModel.shapeModel.useWebGl = this.options.use3D;
253 canvas.elementModel.shapeModel.slope = slope;
250 } 254 }
251 else 255 else
252 { 256 {