aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/elements/shapes-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/elements/shapes-controller.js')
-rw-r--r--js/controllers/elements/shapes-controller.js102
1 files changed, 101 insertions, 1 deletions
diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js
index 1717db94..39300eb8 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
@@ -36,6 +37,35 @@ exports.ShapesController = Montage.create(CanvasController, {
36 el.elementModel.shapeModel.GLWorld.setViewportFromCanvas(el); 37 el.elementModel.shapeModel.GLWorld.setViewportFromCanvas(el);
37 el.elementModel.shapeModel.GLGeomObj.buildBuffers(); 38 el.elementModel.shapeModel.GLGeomObj.buildBuffers();
38 break; 39 break;
40 case "useWebGl":
41 var canvas = njModule.NJUtils.makeNJElement("canvas", "Canvas", "shape", el.className, true);
42 canvas.width = el.width;
43 canvas.height = el.height;
44 this.application.ninja.elementMediator.replaceElement(el, canvas);
45 NJevent("elementDeleted", el);
46 this.application.ninja.selectionController.selectElement(canvas);
47 el = canvas;
48 this.toggleWebGlMode(el, value);
49 el.elementModel.shapeModel.GLGeomObj.buildBuffers();
50 break;
51 case "strokeMaterial":
52 var sm = Object.create(MaterialsLibrary.getMaterial(value));
53 if(sm)
54 {
55 el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(sm);
56 el.elementModel.shapeModel.strokeMaterial = sm;
57 el.elementModel.shapeModel.GLGeomObj.buildBuffers();
58 }
59 break;
60 case "fillMaterial":
61 var fm = Object.create(MaterialsLibrary.getMaterial(value));
62 if(fm)
63 {
64 el.elementModel.shapeModel.GLGeomObj.setFillMaterial(fm);
65 el.elementModel.shapeModel.fillMaterial = fm;
66 el.elementModel.shapeModel.GLGeomObj.buildBuffers();
67 }
68 break;
39 default: 69 default:
40 CanvasController.setProperty(el, p, value); 70 CanvasController.setProperty(el, p, value);
41 } 71 }
@@ -48,9 +78,25 @@ exports.ShapesController = Montage.create(CanvasController, {
48 switch(p) { 78 switch(p) {
49 case "strokeSize": 79 case "strokeSize":
50 case "innerRadius": 80 case "innerRadius":
81 case "tlRadius":
82 case "trRadius":
83 case "blRadius":
84 case "brRadius":
51 case "border": 85 case "border":
52 case "background": 86 case "background":
87 case "useWebGl":
53 return this.getShapeProperty(el, p); 88 return this.getShapeProperty(el, p);
89 case "strokeMaterial":
90 case "fillMaterial":
91 var m = this.getShapeProperty(el, p);
92 if(m)
93 {
94 return this.getShapeProperty(el, p).getName();
95 }
96 else
97 {
98 return "FlatMaterial";
99 }
54 default: 100 default:
55 return CanvasController.getProperty(el, p); 101 return CanvasController.getProperty(el, p);
56 } 102 }
@@ -249,6 +295,60 @@ exports.ShapesController = Montage.create(CanvasController, {
249 { 295 {
250 return (el.elementModel && el.elementModel.isShape); 296 return (el.elementModel && el.elementModel.isShape);
251 } 297 }
298 },
299
300 toggleWebGlMode: {
301 value: function(el, useWebGl)
302 {
303 if(useWebGl)
304 {
305 this.convertToWebGlWorld(el);
306 }
307 else
308 {
309 this.convertTo2DWorld(el);
310 }
311 }
312 },
313
314 convertToWebGlWorld: {
315 value: function(el)
316 {
317 if(el.elementModel.shapeModel.useWebGl)
318 {
319 return;
320 }
321 var world,
322 worldData = el.elementModel.shapeModel.GLWorld.export();
323 if(worldData)
324 {
325 world = new GLWorld(el, true);
326 el.elementModel.shapeModel.GLWorld = world;
327 el.elementModel.shapeModel.useWebGl = true;
328 world.import(worldData);
329 }
330
331 }
332 },
333
334 convertTo2DWorld: {
335 value: function(el)
336 {
337 if(!el.elementModel.shapeModel.useWebGl)
338 {
339 return;
340 }
341 var world,
342 worldData = el.elementModel.shapeModel.GLWorld.export();
343 if(worldData)
344 {
345 world = new GLWorld(el, false);
346 el.elementModel.shapeModel.GLWorld = world;
347 el.elementModel.shapeModel.useWebGl = false;
348 world.import(worldData);
349 }
350
351 }
252 } 352 }
253 353
254}); 354});