diff options
author | Eric Guzman | 2012-04-02 15:36:08 -0700 |
---|---|---|
committer | Eric Guzman | 2012-04-02 15:36:08 -0700 |
commit | 0241bf331b7e06e206a54be441edf2f4c7261f63 (patch) | |
tree | b7e2f9cad73eed4fc616cf1841cd0be02bd955d4 /js/controllers/elements/shapes-controller.js | |
parent | dde5b5054f93db493e5d4d502e677f5781334b08 (diff) | |
parent | c6de22bf42be90b403491b5f87b1818d9020310c (diff) | |
download | ninja-0241bf331b7e06e206a54be441edf2f4c7261f63.tar.gz |
Merge branch 'refs/heads/master' into CSSPanelUpdates
Diffstat (limited to 'js/controllers/elements/shapes-controller.js')
-rwxr-xr-x | js/controllers/elements/shapes-controller.js | 122 |
1 files changed, 114 insertions, 8 deletions
diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index d72d9c14..ef453bea 100755 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js | |||
@@ -6,10 +6,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
6 | 6 | ||
7 | var Montage = require("montage/core/core").Montage, | 7 | var 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 | njModule = require("js/lib/NJUtils"), |
10 | 10 | World = require("js/lib/drawing/world").World, | |
11 | var World = require("js/lib/drawing/world").World; | 11 | MaterialsModel = require("js/models/materials-model").MaterialsModel; |
12 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; | ||
13 | 12 | ||
14 | exports.ShapesController = Montage.create(CanvasController, { | 13 | exports.ShapesController = Montage.create(CanvasController, { |
15 | 14 | ||
@@ -100,6 +99,51 @@ exports.ShapesController = Montage.create(CanvasController, { | |||
100 | el.elementModel.shapeModel.GLWorld.render(); | 99 | el.elementModel.shapeModel.GLWorld.render(); |
101 | } | 100 | } |
102 | break; | 101 | break; |
102 | case "editStrokeMaterial": | ||
103 | NJevent("showMaterialPopup",{materialId : el.elementModel.shapeModel.strokeMaterial.getName()}); | ||
104 | break; | ||
105 | case "editFillMaterial": | ||
106 | NJevent("showMaterialPopup",{materialId : el.elementModel.shapeModel.fillMaterial.getName()}); | ||
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; | ||
122 | case "strokeHardness": | ||
123 | this.setShapeProperty(el, "strokeHardness", value); | ||
124 | el.elementModel.shapeModel.GLGeomObj.setStrokeHardness(val); | ||
125 | el.elementModel.shapeModel.GLWorld.render(); | ||
126 | break; | ||
127 | case "strokeSmoothing": | ||
128 | this.setShapeProperty(el, "strokeSmoothing", value); | ||
129 | el.elementModel.shapeModel.GLGeomObj.setSmoothingAmount(val); | ||
130 | el.elementModel.shapeModel.GLWorld.render(); | ||
131 | break; | ||
132 | case "doSmoothing": | ||
133 | this.setShapeProperty(el, "doSmoothing", value); | ||
134 | el.elementModel.shapeModel.GLGeomObj.setDoSmoothing(value); | ||
135 | el.elementModel.shapeModel.GLWorld.render(); | ||
136 | break; | ||
137 | case "isCalligraphic": | ||
138 | this.setShapeProperty(el, "isCalligraphic", value); | ||
139 | el.elementModel.shapeModel.GLGeomObj.setStrokeUseCalligraphic(value); | ||
140 | el.elementModel.shapeModel.GLWorld.render(); | ||
141 | break; | ||
142 | case "strokeAngle": | ||
143 | this.setShapeProperty(el, "strokeAngle", value); | ||
144 | el.elementModel.shapeModel.GLGeomObj.setStrokeAngle(Math.PI * val/180); | ||
145 | el.elementModel.shapeModel.GLWorld.render(); | ||
146 | break; | ||
103 | default: | 147 | default: |
104 | CanvasController.setProperty(el, p, value); | 148 | CanvasController.setProperty(el, p, value); |
105 | } | 149 | } |
@@ -118,7 +162,45 @@ exports.ShapesController = Montage.create(CanvasController, { | |||
118 | case "border": | 162 | case "border": |
119 | case "background": | 163 | case "background": |
120 | case "useWebGl": | 164 | case "useWebGl": |
165 | case "animate": | ||
121 | return this.getShapeProperty(el, p); | 166 | return this.getShapeProperty(el, p); |
167 | case "strokeHardness": | ||
168 | if (el.elementModel && el.elementModel.shapeModel){ | ||
169 | return el.elementModel.shapeModel.GLGeomObj.getStrokeHardness(); | ||
170 | } else { | ||
171 | return null; | ||
172 | } | ||
173 | break; | ||
174 | case "doSmoothing": | ||
175 | if (el.elementModel && el.elementModel.shapeModel){ | ||
176 | return el.elementModel.shapeModel.GLGeomObj.getDoSmoothing(); | ||
177 | } else { | ||
178 | return null; | ||
179 | } | ||
180 | break; | ||
181 | case "strokeSmoothing": | ||
182 | if (el.elementModel && el.elementModel.shapeModel){ | ||
183 | return el.elementModel.shapeModel.GLGeomObj.getSmoothingAmount(); | ||
184 | } else { | ||
185 | return null; | ||
186 | } | ||
187 | break; | ||
188 | case "isCalligraphic": | ||
189 | if (el.elementModel && el.elementModel.shapeModel){ | ||
190 | return el.elementModel.shapeModel.GLGeomObj.getStrokeUseCalligraphic(); | ||
191 | } else { | ||
192 | return null; | ||
193 | } | ||
194 | break; | ||
195 | case "strokeAngle": | ||
196 | if (el.elementModel && el.elementModel.shapeModel){ | ||
197 | return 180*el.elementModel.shapeModel.GLGeomObj.getStrokeAngle()/Math.PI; | ||
198 | } else { | ||
199 | return null; | ||
200 | } | ||
201 | break; | ||
202 | |||
203 | |||
122 | case "strokeMaterial": | 204 | case "strokeMaterial": |
123 | case "fillMaterial": | 205 | case "fillMaterial": |
124 | var m = this.getShapeProperty(el, p); | 206 | var m = this.getShapeProperty(el, p); |
@@ -254,6 +336,10 @@ exports.ShapesController = Montage.create(CanvasController, { | |||
254 | color = this.getShapeProperty(el, "stroke"); | 336 | color = this.getShapeProperty(el, "stroke"); |
255 | } | 337 | } |
256 | 338 | ||
339 | if(!css) { | ||
340 | return null; | ||
341 | } | ||
342 | |||
257 | css = this.application.ninja.colorController.colorModel.webGlToCss(color); | 343 | css = this.application.ninja.colorController.colorModel.webGlToCss(color); |
258 | return this.application.ninja.colorController.getColorObjFromCss(css); | 344 | return this.application.ninja.colorController.getColorObjFromCss(css); |
259 | } | 345 | } |
@@ -484,13 +570,14 @@ exports.ShapesController = Montage.create(CanvasController, { | |||
484 | var sm, | 570 | var sm, |
485 | fm, | 571 | fm, |
486 | world, | 572 | world, |
487 | worldData = el.elementModel.shapeModel.GLWorld.export(); | 573 | worldData = el.elementModel.shapeModel.GLWorld.exportJSON(); |
488 | if(worldData) | 574 | if(worldData) |
489 | { | 575 | { |
576 | worldData = this.flip3DSense (worldData ); | ||
490 | world = new World(el, true); | 577 | world = new World(el, true); |
491 | el.elementModel.shapeModel.GLWorld = world; | 578 | el.elementModel.shapeModel.GLWorld = world; |
492 | el.elementModel.shapeModel.useWebGl = true; | 579 | el.elementModel.shapeModel.useWebGl = true; |
493 | world.import(worldData); | 580 | world.importJSON(worldData); |
494 | el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot(); | 581 | el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot(); |
495 | 582 | ||
496 | sm = Object.create(MaterialsModel.getMaterial("FlatMaterial")); | 583 | sm = Object.create(MaterialsModel.getMaterial("FlatMaterial")); |
@@ -520,13 +607,14 @@ exports.ShapesController = Montage.create(CanvasController, { | |||
520 | return; | 607 | return; |
521 | } | 608 | } |
522 | var world, | 609 | var world, |
523 | worldData = el.elementModel.shapeModel.GLWorld.export(); | 610 | worldData = el.elementModel.shapeModel.GLWorld.exportJSON(); |
524 | if(worldData) | 611 | if(worldData) |
525 | { | 612 | { |
613 | worldData = this.flip3DSense (worldData ); | ||
526 | world = new World(el, false); | 614 | world = new World(el, false); |
527 | el.elementModel.shapeModel.GLWorld = world; | 615 | el.elementModel.shapeModel.GLWorld = world; |
528 | el.elementModel.shapeModel.useWebGl = false; | 616 | el.elementModel.shapeModel.useWebGl = false; |
529 | world.import(worldData); | 617 | world.importJSON(worldData); |
530 | el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot(); | 618 | el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot(); |
531 | el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(null); | 619 | el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(null); |
532 | el.elementModel.shapeModel.strokeMaterial = null; | 620 | el.elementModel.shapeModel.strokeMaterial = null; |
@@ -538,6 +626,24 @@ exports.ShapesController = Montage.create(CanvasController, { | |||
538 | } | 626 | } |
539 | } | 627 | } |
540 | } | 628 | } |
629 | }, | ||
630 | |||
631 | flip3DSense: { | ||
632 | value: function( importStr ) | ||
633 | { | ||
634 | var jObj; | ||
635 | var index = importStr.indexOf( ';' ); | ||
636 | if ((importStr[0] === 'v') && (index < 24)) | ||
637 | { | ||
638 | // JSON format. separate the version info from the JSON info | ||
639 | //var vStr = importStr.substr( 0, index+1 ); | ||
640 | var jStr = importStr.substr( index+1 ); | ||
641 | jObj = JSON.parse( jStr ); | ||
642 | jObj.webGL = !jObj.webGL; | ||
643 | } | ||
644 | |||
645 | return jObj; | ||
646 | } | ||
541 | } | 647 | } |
542 | 648 | ||
543 | }); | 649 | }); |