diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/stage/tool-handle.js | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz |
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/stage/tool-handle.js')
-rw-r--r-- | js/stage/tool-handle.js | 724 |
1 files changed, 724 insertions, 0 deletions
diff --git a/js/stage/tool-handle.js b/js/stage/tool-handle.js new file mode 100644 index 00000000..03513de7 --- /dev/null +++ b/js/stage/tool-handle.js | |||
@@ -0,0 +1,724 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var Montage = require("montage/core/core").Montage, | ||
8 | Component = require("montage/ui/component").Component, | ||
9 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, | ||
10 | vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, | ||
11 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils; | ||
12 | |||
13 | var ToolHandle = exports.ToolHandle = Montage.create(Component, { | ||
14 | _x: { | ||
15 | value: 0, | ||
16 | writable: true | ||
17 | }, | ||
18 | |||
19 | _y: { | ||
20 | value: 0, | ||
21 | writable: true | ||
22 | }, | ||
23 | |||
24 | _width: { | ||
25 | value: 4, | ||
26 | writable: true | ||
27 | }, | ||
28 | |||
29 | _height: { | ||
30 | value: 4, | ||
31 | writable: true | ||
32 | }, | ||
33 | |||
34 | VERTEX_HIT_RAD: { | ||
35 | value: 4, | ||
36 | writable: true | ||
37 | }, | ||
38 | |||
39 | _cursor: { | ||
40 | value: "default", | ||
41 | writable: true | ||
42 | }, | ||
43 | |||
44 | _strokeStyle: { | ||
45 | value: 'rgba(255,255,255,0.6)' | ||
46 | }, | ||
47 | |||
48 | _fillStyle: { | ||
49 | value: 'rgba(0,0,0,1)' | ||
50 | }, | ||
51 | |||
52 | init: { | ||
53 | value: function (cursorStyle) { | ||
54 | this._cursor = cursorStyle; | ||
55 | } | ||
56 | }, | ||
57 | |||
58 | draw: { | ||
59 | value: function(x, y) { | ||
60 | var context = this.application.ninja.stage.drawingContext; | ||
61 | context.save(); | ||
62 | |||
63 | context.fillStyle = this._fillStyle; | ||
64 | this._x = x - this._width/2; | ||
65 | this._y = y - this._height/2; | ||
66 | |||
67 | context.fillRect(this._x, this._y, this._width, this._height); | ||
68 | |||
69 | context.strokeStyle = this._strokeStyle; | ||
70 | this._x = x - this._width/2 - 1; | ||
71 | this._y = y - this._height/2 - 1; | ||
72 | |||
73 | context.strokeRect(this._x, this._y, this._width + 2, this._height + 2); | ||
74 | |||
75 | context.restore(); | ||
76 | |||
77 | } | ||
78 | }, | ||
79 | |||
80 | collidesWithPoint: { | ||
81 | value:function (x, y) { | ||
82 | if(x < (this._x - this.VERTEX_HIT_RAD)) return false; | ||
83 | if(x > (this._x + this._width + this.VERTEX_HIT_RAD)) return false; | ||
84 | if(y < this._y - this.VERTEX_HIT_RAD) return false; | ||
85 | if(y > (this._y + this._height + this.VERTEX_HIT_RAD)) return false; | ||
86 | |||
87 | return true; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | }); | ||
92 | |||
93 | |||
94 | exports.RotateHandle = Montage.create(ToolHandle, { | ||
95 | _originL: { | ||
96 | value: null, | ||
97 | writable: true | ||
98 | }, | ||
99 | |||
100 | _origin: { | ||
101 | value: null, | ||
102 | writable: true | ||
103 | }, | ||
104 | |||
105 | |||
106 | _dirVec: { | ||
107 | value: null, | ||
108 | writable: true | ||
109 | }, | ||
110 | |||
111 | _dirVecL: { | ||
112 | value: null, | ||
113 | writable: true | ||
114 | }, | ||
115 | |||
116 | _radius: { | ||
117 | value: 50, | ||
118 | writable: true | ||
119 | }, | ||
120 | |||
121 | _transformCenterRadius: { | ||
122 | value: 5, | ||
123 | writable: true | ||
124 | }, | ||
125 | |||
126 | _cursor: { | ||
127 | value: "default", | ||
128 | writable: true | ||
129 | }, | ||
130 | |||
131 | _strokeStyle: { | ||
132 | value: 'rgba(255,0,255,1)' | ||
133 | }, | ||
134 | |||
135 | _axis: { | ||
136 | value: null, | ||
137 | writable: true | ||
138 | }, | ||
139 | |||
140 | _lineWidth: { | ||
141 | value: 2 | ||
142 | }, | ||
143 | |||
144 | _fillStyle: { | ||
145 | value: 'rgba(255,0,255,1)' | ||
146 | }, | ||
147 | |||
148 | _nTriangles: { | ||
149 | value: 30, | ||
150 | writable: true | ||
151 | }, | ||
152 | |||
153 | _rotMat: { | ||
154 | value: null, | ||
155 | writable: true | ||
156 | }, | ||
157 | |||
158 | _rotMatInv: { | ||
159 | value: null, | ||
160 | writable: true | ||
161 | }, | ||
162 | |||
163 | _planeEq: { | ||
164 | value: null, | ||
165 | writable: true | ||
166 | }, | ||
167 | |||
168 | _matW: { | ||
169 | value: null, | ||
170 | writable: true | ||
171 | }, | ||
172 | |||
173 | _matL: { | ||
174 | value: null, | ||
175 | writable: true | ||
176 | }, | ||
177 | |||
178 | _vec: { | ||
179 | value: null, | ||
180 | writable: true | ||
181 | }, | ||
182 | |||
183 | _vec2: { | ||
184 | value: null, | ||
185 | writable: true | ||
186 | }, | ||
187 | |||
188 | _vec3: { | ||
189 | value: null, | ||
190 | writable: true | ||
191 | }, | ||
192 | |||
193 | _dragPlane: { | ||
194 | value: null, | ||
195 | writable: true | ||
196 | }, | ||
197 | |||
198 | init: { | ||
199 | value: function (cursorStyle, color, axis) { | ||
200 | this._cursor = cursorStyle; | ||
201 | this._strokeStyle = color; | ||
202 | this._fillStyle = color; | ||
203 | this._axis = axis; | ||
204 | switch(this._axis) | ||
205 | { | ||
206 | case "x": | ||
207 | this._vec = Vector.create([1, 0, 0]); | ||
208 | this._vec2 = Vector.create([0, 1, 0]); | ||
209 | this._vec3 = Vector.create([0, 0, 1]); | ||
210 | break; | ||
211 | case "y": | ||
212 | this._vec = Vector.create([0, 1, 0]); | ||
213 | this._vec2 = Vector.create([1, 0, 0]); | ||
214 | this._vec3 = Vector.create([0, 0, 1]); | ||
215 | break; | ||
216 | case "z": | ||
217 | this._vec = Vector.create([0, 0, 1]); | ||
218 | this._vec2 = Vector.create([1, 0, 0]); | ||
219 | this._vec3 = Vector.create([0, 1, 0]); | ||
220 | break; | ||
221 | } | ||
222 | |||
223 | // get a matrix to rotate a point around the circle | ||
224 | var angle = 2.0*Math.PI/Number(this._nTriangles); | ||
225 | this._rotMat = Matrix.RotationZ( angle ); | ||
226 | this._rotMatInv = glmat4.inverse(this._rotMat, []); | ||
227 | } | ||
228 | }, | ||
229 | |||
230 | draw: { | ||
231 | value: function(base, item, inLocalMode) { | ||
232 | var context = this.application.ninja.stage.drawingContext; | ||
233 | context.save(); | ||
234 | |||
235 | context.strokeStyle = this._strokeStyle; | ||
236 | context.fillStyle = this._fillStyle; | ||
237 | context.lineWidth = this._lineWidth; | ||
238 | |||
239 | var pointOnElt = base.slice(0); | ||
240 | // this._origin = viewUtils.localToGlobal(pointOnElt, item); | ||
241 | this._origin = pointOnElt; | ||
242 | |||
243 | |||
244 | var viewMat = viewUtils.getMatrixFromElement(this.application.ninja.currentDocument.documentRoot); | ||
245 | |||
246 | var transMat = viewMat.slice(0); | ||
247 | if(inLocalMode) | ||
248 | { | ||
249 | var objMat = viewUtils.getMatrixFromElement(item); | ||
250 | glmat4.multiply(viewMat, objMat, transMat); | ||
251 | } | ||
252 | |||
253 | this._planeEq = MathUtils.transformVector(this._vec, transMat); | ||
254 | this._planeEq2 = MathUtils.transformVector(this._vec2, transMat); | ||
255 | this._plane |