aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/elements
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/elements')
-rw-r--r--js/controllers/elements/shapes-controller.js69
1 files changed, 68 insertions, 1 deletions
diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js
index 5efbccd0..3f1ccc3d 100644
--- a/js/controllers/elements/shapes-controller.js
+++ b/js/controllers/elements/shapes-controller.js
@@ -5,7 +5,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
5</copyright> */ 5</copyright> */
6 6
7var Montage = require("montage/core/core").Montage, 7var Montage = require("montage/core/core").Montage,
8 CanvasController = require("js/controllers/elements/canvas-controller").CanvasController; 8 CanvasController = require("js/controllers/elements/canvas-controller").CanvasController,
9 njModule = require("js/lib/NJUtils");
9 10
10exports.ShapesController = Montage.create(CanvasController, { 11exports.ShapesController = Montage.create(CanvasController, {
11 12
@@ -56,6 +57,17 @@ exports.ShapesController = Montage.create(CanvasController, {
56 el.elementModel.shapeModel.GLWorld.setViewportFromCanvas(el); 57 el.elementModel.shapeModel.GLWorld.setViewportFromCanvas(el);
57 el.elementModel.shapeModel.GLGeomObj.buildBuffers(); 58 el.elementModel.shapeModel.GLGeomObj.buildBuffers();
58 break; 59 break;
60 case "useWebGl":
61 var canvas = njModule.NJUtils.makeNJElement("canvas", "Canvas", "shape", el.className, true);
62 canvas.width = el.width;
63 canvas.height = el.height;
64 this.application.ninja.elementMediator.replaceElement(el, canvas);
65 NJevent("elementDeleted", el);
66 this.application.ninja.selectionController.selectElement(canvas);
67 el = canvas;
68 this.toggleWebGlMode(el, value);
69 el.elementModel.shapeModel.GLGeomObj.buildBuffers();
70 break;
59 default: 71 default:
60 CanvasController.setProperty(el, p, value); 72 CanvasController.setProperty(el, p, value);
61 } 73 }
@@ -76,6 +88,7 @@ exports.ShapesController = Montage.create(CanvasController, {
76 case "fillMaterial": 88 case "fillMaterial":
77 case "border": 89 case "border":
78 case "background": 90 case "background":
91 case "useWebGl":
79 return this.getShapeProperty(el, p); 92 return this.getShapeProperty(el, p);
80 default: 93 default:
81 return CanvasController.getProperty(el, p); 94 return CanvasController.getProperty(el, p);
@@ -275,6 +288,60 @@ exports.ShapesController = Montage.create(CanvasController, {
275 { 288 {
276 return (el.elementModel && el.elementModel.isShape); 289 return (el.elementModel && el.elementModel.isShape);
277 } 290 }
291 },
292
293 toggleWebGlMode: {
294 value: function(el, useWebGl)
295 {
296 if(useWebGl)
297 {
298 this.convertToWebGlWorld(el);
299 }
300 else
301 {
302 this.convertTo2DWorld(el);
303 }
304 }
305 },
306
307 convertToWebGlWorld: {
308 value: function(el)
309 {
310 if(el.elementModel.shapeModel.useWebGl)
311 {
312 return;
313 }
314 var world,
315 worldData = el.elementModel.shapeModel.GLWorld.export();
316 if(worldData)
317 {
318 world = new GLWorld(el, true);
319 el.elementModel.shapeModel.GLWorld = world;
320 el.elementModel.shapeModel.useWebGl = true;
321 world.import(worldData);
322 }
323
324 }
325 },
326
327 convertTo2DWorld: {
328 value: function(el)
329 {
330 if(!el.elementModel.shapeModel.useWebGl)
331 {
332 return;
333 }
334 var world,
335 worldData = el.elementModel.shapeModel.GLWorld.export();
336 if(worldData)
337 {
338 world = new GLWorld(el, false);
339 el.elementModel.shapeModel.GLWorld = world;
340 el.elementModel.shapeModel.useWebGl = false;
341 world.import(worldData);
342 }
343
344 }
278 } 345 }
279 346
280}); 347});