aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/elements
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/elements')
-rwxr-xr-xjs/controllers/elements/component-controller.js13
-rwxr-xr-xjs/controllers/elements/shapes-controller.js45
2 files changed, 48 insertions, 10 deletions
diff --git a/js/controllers/elements/component-controller.js b/js/controllers/elements/component-controller.js
index fbe9a995..d902e4a1 100755
--- a/js/controllers/elements/component-controller.js
+++ b/js/controllers/elements/component-controller.js
@@ -11,6 +11,8 @@ exports.ComponentController = Montage.create(ElementController, {
11 11
12 getProperty: { 12 getProperty: {
13 value: function(el, prop) { 13 value: function(el, prop) {
14 var component = el.controller || this.application.ninja.currentDocument.getComponentFromElement(el);
15
14 switch(prop) { 16 switch(prop) {
15 case "id": 17 case "id":
16 case "class": 18 case "class":
@@ -20,18 +22,20 @@ exports.ComponentController = Montage.create(ElementController, {
20 case "width": 22 case "width":
21 case "height": 23 case "height":
22 if(el.nodeName === "IMG" && (prop === "width" || prop === "height")) { 24 if(el.nodeName === "IMG" && (prop === "width" || prop === "height")) {
23 return this.application.ninja.currentDocument.getComponentFromElement(el)[prop]; 25 return component[prop];
24 } else { 26 } else {
25 return ElementController.getProperty(el, prop, true); 27 return ElementController.getProperty(el, prop, true);
26 } 28 }
27 default: 29 default:
28 return this.application.ninja.currentDocument.getComponentFromElement(el)[prop]; 30 return component[prop];
29 } 31 }
30 } 32 }
31 }, 33 },
32 34
33 setProperty: { 35 setProperty: {
34 value: function(el, p, value) { 36 value: function(el, p, value) {
37 var component = el.controller || this.application.ninja.currentDocument.getComponentFromElement(el);
38
35 switch(p) { 39 switch(p) {
36 case "id": 40 case "id":
37 case "class": 41 case "class":
@@ -41,15 +45,14 @@ exports.ComponentController = Montage.create(ElementController, {
41 case "width": 45 case "width":
42 case "height": 46 case "height":
43 if(el.nodeName === "IMG" && (p === "width" || p === "height")) { 47 if(el.nodeName === "IMG" && (p === "width" || p === "height")) {
44 this.application.ninja.currentDocument.getComponentFromElement(el)[p] = value; 48 component[p] = value;
45 } else { 49 } else {
46 ElementController.setProperty(el, p, value); 50 ElementController.setProperty(el, p, value);
47 } 51 }
48 break; 52 break;
49 default: 53 default:
50 if(p === "min" || p === "max") value = parseFloat(value); 54 if(p === "min" || p === "max") value = parseFloat(value);
51 55 component[p] = value;
52 this.application.ninja.currentDocument.getComponentFromElement(el)[p] = value;
53 break; 56 break;
54 57
55 } 58 }
diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js
index 689bc421..3f8f27d3 100755
--- a/js/controllers/elements/shapes-controller.js
+++ b/js/controllers/elements/shapes-controller.js
@@ -105,6 +105,20 @@ exports.ShapesController = Montage.create(CanvasController, {
105 case "editFillMaterial": 105 case "editFillMaterial":
106 NJevent("showMaterialPopup",{materialId : el.elementModel.shapeModel.fillMaterial.getName()}); 106 NJevent("showMaterialPopup",{materialId : el.elementModel.shapeModel.fillMaterial.getName()});
107 break; 107 break;
108 case "animate":
109 if(value)
110 {
111 el.elementModel.shapeModel.animate = true;
112 el.elementModel.shapeModel.GLWorld._previewAnimation = true;
113 el.elementModel.shapeModel.GLWorld.restartRenderLoop();
114 }
115 else
116 {
117 el.elementModel.shapeModel.animate = false;
118 el.elementModel.shapeModel.GLWorld._previewAnimation = false;
119 el.elementModel.shapeModel.GLWorld._canvas.task.stop();
120 }
121 break;
108 default: 122 default:
109 CanvasController.setProperty(el, p, value); 123 CanvasController.setProperty(el, p, value);
110 } 124 }
@@ -123,6 +137,7 @@ exports.ShapesController = Montage.create(CanvasController, {
123 case "border": 137 case "border":
124 case "background": 138 case "background":
125 case "useWebGl": 139 case "useWebGl":
140 case "animate":
126 return this.getShapeProperty(el, p); 141 return this.getShapeProperty(el, p);
127 case "strokeMaterial": 142 case "strokeMaterial":
128 case "fillMaterial": 143 case "fillMaterial":
@@ -489,14 +504,15 @@ exports.ShapesController = Montage.create(CanvasController, {
489 var sm, 504 var sm,
490 fm, 505 fm,
491 world, 506 world,
492 worldData = el.elementModel.shapeModel.GLWorld.export(); 507 worldData = el.elementModel.shapeModel.GLWorld.exportJSON();
493 if(worldData) 508 if(worldData)
494 { 509 {
510 worldData = this.flip3DSense (worldData );
495 world = new World(el, true); 511 world = new World(el, true);
496 el.elementModel.shapeModel.GLWorld = world; 512 el.elementModel.shapeModel.GLWorld = world;
497 el.elementModel.shapeModel.useWebGl = true; 513 el.elementModel.shapeModel.useWebGl = true;
498 el.elementModel.controller.setProperty(el, "-webkit-transform-style", "preserve-3d"); 514 el.elementModel.controller.setProperty(el, "-webkit-transform-style", "preserve-3d");
499 world.import(worldData, true); 515 world.importJSON(worldData);
500 el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot(); 516 el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot();
501 517
502 sm = Object.create(MaterialsModel.getMaterial("FlatMaterial")); 518 sm = Object.create(MaterialsModel.getMaterial("FlatMaterial"));
@@ -526,13 +542,14 @@ exports.ShapesController = Montage.create(CanvasController, {
526 return; 542 return;
527 } 543 }
528 var world, 544 var world,
529 worldData = el.elementModel.shapeModel.GLWorld.export(); 545 worldData = el.elementModel.shapeModel.GLWorld.exportJSON();
530 if(worldData) 546 if(worldData)
531 { 547 {
548 worldData = this.flip3DSense (worldData );
532 world = new World(el, false); 549 world = new World(el, false);
533 el.elementModel.shapeModel.GLWorld = world; 550 el.elementModel.shapeModel.GLWorld = world;
534 el.elementModel.shapeModel.useWebGl = false; 551 el.elementModel.shapeModel.useWebGl = false;
535 world.import(worldData, true); 552 world.importJSON(worldData);
536 el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot(); 553 el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot();
537 el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(null); 554 el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(null);
538 el.elementModel.shapeModel.strokeMaterial = null; 555 el.elementModel.shapeModel.strokeMaterial = null;
@@ -544,6 +561,24 @@ exports.ShapesController = Montage.create(CanvasController, {
544 } 561 }
545 } 562 }
546 } 563 }
564 },
565
566 flip3DSense: {
567 value: function( importStr )
568 {
569 var jObj;
570 var index = importStr.indexOf( ';' );
571 if ((importStr[0] === 'v') && (index < 24))
572 {
573 // JSON format. separate the version info from the JSON info
574 //var vStr = importStr.substr( 0, index+1 );
575 var jStr = importStr.substr( index+1 );
576 jObj = JSON.parse( jStr );
577 jObj.webGL = !jObj.webGL;
578 }
579
580 return jObj;
581 }
547 } 582 }
548 583
549}); 584});