diff options
Diffstat (limited to 'js/controllers/elements/element-controller.js')
-rwxr-xr-x | js/controllers/elements/element-controller.js | 136 |
1 files changed, 101 insertions, 35 deletions
diff --git a/js/controllers/elements/element-controller.js b/js/controllers/elements/element-controller.js index da8afbaa..3d71c52d 100755 --- a/js/controllers/elements/element-controller.js +++ b/js/controllers/elements/element-controller.js | |||
@@ -5,12 +5,16 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var Montage = require("montage/core/core").Montage, | 7 | var Montage = require("montage/core/core").Montage, |
8 | Component = require("montage/ui/component").Component; | 8 | Component = require("montage/ui/component").Component, |
9 | njModule = require("js/lib/NJUtils"); | ||
9 | 10 | ||
10 | exports.ElementController = Montage.create(Component, { | 11 | exports.ElementController = Montage.create(Component, { |
11 | 12 | ||
12 | addElement: { | 13 | addElement: { |
13 | value: function(el, styles) { | 14 | value: function(el, styles) { |
15 | |||
16 | if (el.getAttribute) el.setAttribute('data-ninja-node', 'true'); | ||
17 | |||
14 | // Updated to use new methods in TimelinePanel. JR. | 18 | // Updated to use new methods in TimelinePanel. JR. |
15 | var insertionIndex = this.application.ninja.timeline.getInsertionIndex(); | 19 | var insertionIndex = this.application.ninja.timeline.getInsertionIndex(); |
16 | if (insertionIndex === false) { | 20 | if (insertionIndex === false) { |
@@ -53,7 +57,7 @@ exports.ElementController = Montage.create(Component, { | |||
53 | // Remove the element from the DOM and clear the GLWord. | 57 | // Remove the element from the DOM and clear the GLWord. |
54 | removeElement: { | 58 | removeElement: { |
55 | value: function(el) { | 59 | value: function(el) { |
56 | if(el.elementModel && el.elementModel.shapeModel && el.elementModel.shapeModel.GLWorld) { | 60 | if(el.elementModel.shapeModel && el.elementModel.shapeModel.GLWorld) { |
57 | el.elementModel.shapeModel.GLWorld.clearTree(); | 61 | el.elementModel.shapeModel.GLWorld.clearTree(); |
58 | } | 62 | } |
59 | el.parentNode.removeChild(el); | 63 | el.parentNode.removeChild(el); |
@@ -179,32 +183,12 @@ exports.ElementController = Montage.create(Component, { | |||
179 | el.elementModel.stroke = null; | 183 | el.elementModel.stroke = null; |
180 | return; | 184 | return; |
181 | case 'gradient': | 185 | case 'gradient': |
182 | this.setProperty(el, "border-image", color.color.css); | 186 | this.setGradientBorder(el, color.color.gradientMode, color.color.css); |
183 | this.setProperty(el, "border-color", "none"); | ||
184 | if(color.borderInfo) { | ||
185 | if(color.borderInfo.borderWidth) { | ||
186 | this.setProperty(el, "border-width", color.borderInfo.borderWidth + color.borderInfo.borderUnits); | ||
187 | } | ||
188 | if(color.borderInfo.borderStyle) { | ||
189 | this.setProperty(el, "border-style", color.borderInfo.borderStyle); | ||
190 | } | ||
191 | } | ||
192 | break; | 187 | break; |
193 | default: | 188 | default: |
194 | if(borderSide){ | 189 | this.setProperty(el, "border-image", "none"); |
195 | this.setProperty(el,"border-"+borderSide+"-color",color.color.css); | 190 | this.setProperty(el, "border-image-slice", ""); |
196 | }else{ | 191 | this.setProperty(el, "border-color", color.color.css); |
197 | this.setProperty(el, "border-image", "none"); | ||
198 | this.setProperty(el, "border-color", color.color.css); | ||
199 | } | ||
200 | if(color.borderInfo) { | ||
201 | if(color.borderInfo.borderWidth) { | ||
202 | this.setProperty(el, "border-width", color.borderInfo.borderWidth + color.borderInfo.borderUnits); | ||
203 | } | ||
204 | if(color.borderInfo.borderStyle) { | ||
205 | this.setProperty(el, "border-style", color.borderInfo.borderStyle); | ||
206 | } | ||
207 | } | ||
208 | } | 192 | } |
209 | } | 193 | } |
210 | el.elementModel.stroke = color; | 194 | el.elementModel.stroke = color; |
@@ -212,26 +196,108 @@ exports.ElementController = Montage.create(Component, { | |||
212 | } | 196 | } |
213 | }, | 197 | }, |
214 | 198 | ||
199 | setGradientBorder: { | ||
200 | value: function(el, gradientMode, css) { | ||
201 | if(gradientMode === "radial") { | ||
202 | this.setProperty(el, "border-image", css.replace("ellipse", "circle")); | ||
203 | } else { | ||
204 | this.setProperty(el, "border-image", css); | ||
205 | } | ||
206 | this.setProperty(el, "border-color", "none"); | ||
207 | // gradient slice = borderWidth/totalWidth | ||
208 | var b = parseInt(this.getProperty(el, "border-left-width", true)), | ||
209 | w = parseInt(this.getProperty(el, "width", true)), | ||
210 | h = parseInt(this.getProperty(el, "height", true)); | ||
211 | if(h > w) { | ||
212 | w = h; | ||
213 | } | ||
214 | this.setProperty(el, "border-image-slice", Math.floor(b/(w+b+b) * 100) + "%"); | ||
215 | } | ||
216 | }, | ||
217 | |||
215 | getStroke: { | 218 | getStroke: { |
216 | value: function(el) { | 219 | value: function(el, stroke) { |
217 | // TODO - Need to figure out which border side user wants | 220 | var strokeInfo = {}, |
218 | return this.application.ninja.stylesController.getElementStyle(el, "border"); | 221 | color, |
222 | borderWidth, | ||
223 | border; | ||
224 | if(stroke.colorInfo) { | ||
225 | strokeInfo.colorInfo = {}; | ||
226 | color = this.getColor(el, false); | ||
227 | if(color && color.color) { | ||
228 | strokeInfo.colorInfo.mode = color.mode; | ||
229 | strokeInfo.colorInfo.color = color.color; | ||
230 | } else { | ||
231 | strokeInfo.colorInfo.mode = "nocolor"; | ||
232 | strokeInfo.colorInfo.color = null; | ||
233 | } | ||
234 | } | ||
235 | if(stroke.borderInfo) { | ||
236 | // TODO - Need to figure out which border side user wants | ||
237 | strokeInfo.borderInfo = {}; | ||
238 | if(stroke.borderInfo.borderWidth) { | ||
239 | borderWidth = this.getProperty(el, "border-width"); | ||
240 | if(borderWidth) { | ||
241 | border = njModule.NJUtils.getValueAndUnits(borderWidth); | ||
242 | strokeInfo.borderInfo.borderWidth = border[0]; | ||
243 | strokeInfo.borderInfo.borderUnits = border[1]; | ||
244 | } | ||
245 | } | ||
246 | if(stroke.borderInfo.borderStyle) { | ||
247 | strokeInfo.borderInfo.borderStyle = this.getProperty(el, "border-style"); | ||
248 | } | ||
249 | } | ||
250 | return strokeInfo; | ||
219 | } | 251 | } |
220 | }, | 252 | }, |
221 | 253 | ||
222 | setStroke: { | 254 | setStroke: { |
223 | value: function(el, stroke) { | 255 | value: function(el, stroke) { |
224 | this.application.ninja.stylesController.setElementStyle(el, "border-width", stroke.borderWidth + stroke.borderUnits); | 256 | if(stroke.borderInfo) { |
225 | this.application.ninja.stylesController.setElementStyle(el, "border-style", stroke.borderStyle); | 257 | if(stroke.borderInfo.borderWidth) { |
226 | this.setColor(el, stroke.color, false); | 258 | this.application.ninja.stylesController.setElementStyle(el, "border-width", stroke.borderInfo.borderWidth + stroke.borderInfo.borderUnits); |
259 | } | ||
260 | if(stroke.borderInfo.borderStyle) { | ||
261 | this.application.ninja.stylesController.setElementStyle(el, "border-style", stroke.borderInfo.borderStyle); | ||
262 | } | ||
263 | } | ||
264 | if(stroke.colorInfo) { | ||
265 | this.setColor(el, stroke.colorInfo, false); | ||
266 | } | ||
227 | } | 267 | } |
228 | }, | 268 | }, |
229 | 269 | ||
270 | getFill: { | ||
271 | value: function(el, fill) { | ||
272 | var fillInfo = {}, | ||
273 | color; | ||
274 | if(fill.colorInfo) { | ||
275 | fillInfo.colorInfo = {}; | ||
276 | color = this.getColor(el, true); | ||
277 | if(color && color.color) { | ||
278 | fillInfo.colorInfo.mode = color.mode; | ||
279 | fillInfo.colorInfo.color = color.color; | ||
280 | } else { | ||
281 | fillInfo.colorInfo.mode = "nocolor"; | ||
282 | fillInfo.colorInfo.color = null; | ||
283 | } | ||
284 | } | ||
285 | return fillInfo; | ||
286 | } | ||
287 | }, | ||
288 | |||
289 | setFill: { | ||
290 | value: function(el, fill) { | ||
291 | if(fill.colorInfo) { | ||
292 | this.setColor(el, fill.colorInfo, true); | ||
293 | } | ||
294 | } | ||
295 | }, | ||
230 | //-------------------------------------------------------------------------------------------------------- | 296 | //-------------------------------------------------------------------------------------------------------- |
231 | // Routines to get/set 3D properties | 297 | // Routines to get/set 3D properties |
232 | get3DProperty: { | 298 | get3DProperty: { |
233 | value: function(el, prop) { | 299 | value: function(el, prop) { |
234 | if(el.elementModel && el.elementModel.props3D) { | 300 | if(el.elementModel.props3D) { |
235 | return el.elementModel.props3D[prop]; | 301 | return el.elementModel.props3D[prop]; |
236 | } | 302 | } |
237 | } | 303 | } |
@@ -239,7 +305,7 @@ exports.ElementController = Montage.create(Component, { | |||
239 | 305 | ||
240 | getMatrix: { | 306 | getMatrix: { |
241 | value: function(el) { | 307 | value: function(el) { |
242 | if(el.elementModel && el.elementModel.props3D && el.elementModel.props3D.matrix3d) { | 308 | if(el.elementModel.props3D && el.elementModel.props3D.matrix3d) { |
243 | return el.elementModel.props3D.matrix3d.slice(0); | 309 | return el.elementModel.props3D.matrix3d.slice(0); |
244 | } else { | 310 | } else { |
245 | var mat; | 311 | var mat; |
@@ -259,7 +325,7 @@ exports.ElementController = Montage.create(Component, { | |||
259 | 325 | ||
260 | getPerspectiveDist: { | 326 | getPerspectiveDist: { |
261 | value: function(el) { | 327 | value: function(el) { |
262 | if(el.elementModel && el.elementModel.props3D && el.elementModel.props3D.perspectiveDist) { | 328 | if(el.elementModel.props3D && el.elementModel.props3D.perspectiveDist) { |
263 | return el.elementModel.props3D.perspectiveDist; |