diff options
author | Valerio Virgillito | 2012-04-04 13:27:40 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-04-04 13:27:40 -0700 |
commit | 9f1806a7134ec4744a8009e6a7467f5cea04cabf (patch) | |
tree | b4038b10cb105cc9860f869e6bb372a74b05813c /js/tools/LineTool.js | |
parent | 56a042a8ed5d1cb2cb82781952f09ffd6a8338ea (diff) | |
parent | 8482e23cd9b8c4700b5130f2588e5eb24d376536 (diff) | |
download | ninja-9f1806a7134ec4744a8009e6a7467f5cea04cabf.tar.gz |
Merge branch 'refs/heads/master' into components
Diffstat (limited to 'js/tools/LineTool.js')
-rwxr-xr-x | js/tools/LineTool.js | 111 |
1 files changed, 60 insertions, 51 deletions
diff --git a/js/tools/LineTool.js b/js/tools/LineTool.js index a61f8f79..455f519e 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 | |||
7 | var Montage = require("montage/core/core").Montage, | 7 | var 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)); |
79 | } | 75 | |
80 | else | 76 | w += ~~(xAdj*2); |
81 | { | 77 | h += ~~(yAdj*2); |
82 | // else make the line's stroke fit inside the canvas by growing the canvas | 78 | } |
83 | var theta = Math.atan(slope); | 79 | |
84 | xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta)); | 80 | canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); |
85 | yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta)); | 81 | var elementModel = TagTool.makeElement(w, h, drawData.planeMat, drawData.midPt, canvas); |
86 | 82 | canvas.elementModel.isShape = true; | |
87 | w += ~~(xAdj*2); | 83 | this.application.ninja.elementMediator.addElements(canvas, elementModel.data); |
88 | h += ~~(yAdj*2); | 84 | } else { |
89 | } | 85 | canvas = this._targetedElement; |
90 | 86 | canvas.elementModel.controller = ShapesController; | |
91 | canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); | 87 | if(!canvas.elementModel.shapeModel) { |
92 | var elementModel = TagTool.makeElement(w, h, drawData.planeMat, drawData.midPt, canvas); | 88 | canvas.elementModel.shapeModel = Montage.create(ShapeModel); |
93 | 89 | } | |
94 | ElementMediator.addElement(canvas, elementModel.data, true); | ||
95 | canvas.elementModel.isShape = true; | ||
96 | } | ||
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 | } | 90 | } |
105 | } | 91 | } |
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, |