aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/elements
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/elements')
-rwxr-xr-xjs/controllers/elements/element-controller.js15
-rwxr-xr-xjs/controllers/elements/shapes-controller.js442
2 files changed, 317 insertions, 140 deletions
diff --git a/js/controllers/elements/element-controller.js b/js/controllers/elements/element-controller.js
index 9cba6d94..fda3a3c5 100755
--- a/js/controllers/elements/element-controller.js
+++ b/js/controllers/elements/element-controller.js
@@ -5,22 +5,27 @@ 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 NJComponent = require("js/lib/nj-base").NJComponent; 8 Component = require("montage/ui/component").Component;
9 9
10var ElementController = exports.ElementController = Montage.create(NJComponent, { 10exports.ElementController = Montage.create(Component, {
11 11
12 addElement: { 12 addElement: {
13 value: function(el, styles) { 13 value: function(el, styles) {
14 this.application.ninja.currentDocument.documentRoot.appendChild(el); 14 this.application.ninja.currentDocument.documentRoot.appendChild(el);
15 // Nested elements - 15 // Nested elements - TODO make sure the CSS is correct before nesting elements
16 // TODO make sure the CSS is correct before nesting elements
17 // this.application.ninja.currentSelectedContainer.appendChild(el); 16 // this.application.ninja.currentSelectedContainer.appendChild(el);
18 this.application.ninja.stylesController.setElementStyles(el, styles); 17 if(styles) {
18 this.application.ninja.stylesController.setElementStyles(el, styles);
19 }
19 } 20 }
20 }, 21 },
21 22
23 // Remove the element from the DOM and clear the GLWord.
22 removeElement: { 24 removeElement: {
23 value: function(el) { 25 value: function(el) {
26 if(el.elementModel && el.elementModel.shapeModel && el.elementModel.shapeModel.GLWorld) {
27 el.elementModel.shapeModel.GLWorld.clearTree();
28 }
24 el.parentNode.removeChild(el); 29 el.parentNode.removeChild(el);
25 } 30 }
26 }, 31 },
diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js
index f18801fd..b97d04b0 100755
--- a/js/controllers/elements/shapes-controller.js
+++ b/js/controllers/elements/shapes-controller.js
@@ -13,12 +13,62 @@ var Montage = require("montage/core/core").Montage,
13exports.ShapesController = Montage.create(CanvasController, { 13exports.ShapesController = Montage.create(CanvasController, {
14 14
15 setProperty: { 15 setProperty: {
16 value: function(el, p, value) { 16 value: function(el, p, value, eventType, source) {
17 var val = parseInt(value); 17 var val = parseInt(value),
18 canvas,
19 m,
20 color;
18 switch(p) { 21 switch(p) {
19 case "strokeSize": 22 case "strokeSize":
20 // TODO - For now, just handling px units. 23 // TODO - For now, just handling px units.
21 this.setShapeProperty(el, "strokeSize", value); 24 this.setShapeProperty(el, "strokeSize", value);
25 // Changing stroke size should grow/shrink the shape from the center.
26 var delta = ~~(val - el.elementModel.shapeModel.GLGeomObj.getStrokeWidth()),
27 l = this.application.ninja.elementMediator.getProperty(el, "left", parseInt),
28 t = this.application.ninja.elementMediator.getProperty(el, "top", parseInt),
29 w = this.application.ninja.elementMediator.getProperty(el, "width", parseInt),
30 h = this.application.ninja.elementMediator.getProperty(el, "height", parseInt);
31
32 if(el.elementModel.selection === "Line")
33 {
34 var slope = el.elementModel.shapeModel.slope;
35 // set the dimensions
36 if(slope === "horizontal")
37 {
38 h = Math.max(val, 1);
39 }
40 else if(slope === "vertical")
41 {
42 w = Math.max(val, 1);
43 }
44 else
45 {
46 var oldXAdj = el.elementModel.shapeModel.GLGeomObj.getXAdj();
47 var oldYAdj = el.elementModel.shapeModel.GLGeomObj.getYAdj();
48 var theta = Math.atan(el.elementModel.shapeModel.slope);
49 var xAdj = Math.abs((val/2)*Math.sin(theta));
50 var yAdj = Math.abs((val/2)*Math.cos(theta));
51 var dX = ~~(xAdj*2 - oldXAdj*2);
52 var dY = ~~(yAdj*2 - oldYAdj*2);
53
54 if(delta > 0)
55 {
56 l -= dX*2;
57 t -= dY*2;
58 w += dX*2;
59 h += dY*2;
60 }
61
62 el.elementModel.shapeModel.GLGeomObj.setXAdj(xAdj);
63 el.elementModel.shapeModel.GLGeomObj.setYAdj(yAdj);
64
65 }
66 }
67 this.application.ninja.elementMediator.setProperties([el],
68 { "left": [l + "px"],
69 "top": [t + "px"],
70 "width": [w + "px"],
71 "height": [h + "px"] }, eventType, source );
22 el.elementModel.shapeModel.GLGeomObj.setStrokeWidth(val); 72 el.elementModel.shapeModel.GLGeomObj.setStrokeWidth(val);
23 el.elementModel.shapeModel.GLGeomObj.buildBuffers(); 73 el.elementModel.shapeModel.GLGeomObj.buildBuffers();
24 el.elementModel.shapeModel.GLWorld.render(); 74 el.elementModel.shapeModel.GLWorld.render();
@@ -68,42 +118,47 @@ exports.ShapesController = Montage.create(CanvasController, {
68 el.elementModel.shapeModel.GLWorld.render(); 118 el.elementModel.shapeModel.GLWorld.render();
69 break; 119 break;
70 case "useWebGl": 120 case "useWebGl":
71 var canvas = njModule.NJUtils.makeNJElement("canvas", "Canvas", "shape", el.className, true); 121 canvas = njModule.NJUtils.makeNJElement("canvas", "Canvas", "shape", el.className, true);
72 canvas.setAttribute("data-RDGE-id", njModule.NJUtils.generateRandom()); 122 canvas.setAttribute("data-RDGE-id", njModule.NJUtils.generateRandom());
73 canvas.width = el.width; 123 canvas.width = el.width;
74 canvas.height = el.height; 124 canvas.height = el.height;
75 this.application.ninja.elementMediator.replaceElement(el, canvas); 125 canvas.elementModel = el.elementModel;
76 NJevent("elementDeleted", el); 126 this.toggleWebGlMode(canvas, value);
77 el = canvas; 127 this.application.ninja.elementMediator.replaceElement(canvas, el);
78 this.toggleWebGlMode(el, value); 128 break;
79 el.elementModel.shapeModel.GLWorld.render();
80 this.application.ninja.selectionController.selectElement(el);
81 return;
82 case "strokeMaterial": 129 case "strokeMaterial":
83 var sm = Object.create(MaterialsModel.getMaterial(value)); 130 m = Object.create(MaterialsModel.getMaterial(value));
84 if(sm) 131 if(m)
85 { 132 {
86 el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(sm); 133 el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(m);
87 el.elementModel.shapeModel.strokeMaterial = sm; 134 color = this.getMaterialColor(value);
135 if(color)
136 {
137 el.elementModel.shapeModel.GLGeomObj.setStrokeColor(color);
138 }
88 el.elementModel.shapeModel.GLGeomObj.buildBuffers(); 139 el.elementModel.shapeModel.GLGeomObj.buildBuffers();
89 el.elementModel.shapeModel.GLWorld.render(); 140 el.elementModel.shapeModel.GLWorld.render();
90 } 141 }
91 break; 142 break;
92 case "fillMaterial": 143 case "fillMaterial":
93 var fm = Object.create(MaterialsModel.getMaterial(value)); 144 m = Object.create(MaterialsModel.getMaterial(value));
94 if(fm) 145 if(m)
95 { 146 {
96 el.elementModel.shapeModel.GLGeomObj.setFillMaterial(fm); 147 el.elementModel.shapeModel.GLGeomObj.setFillMaterial(m);
97 el.elementModel.shapeModel.fillMaterial = fm; 148 color = this.getMaterialColor(value);
149 if(color)
150 {
151 el.elementModel.shapeModel.GLGeomObj.setFillColor(color);
152 }
98 el.elementModel.shapeModel.GLGeomObj.buildBuffers(); 153 el.elementModel.shapeModel.GLGeomObj.buildBuffers();
99 el.elementModel.shapeModel.GLWorld.render(); 154 el.elementModel.shapeModel.GLWorld.render();
100 } 155 }
101 break; 156 break;
102 case "editStrokeMaterial": 157 case "editStrokeMaterial":
103 NJevent("showMaterialPopup",{materialId : el.elementModel.shapeModel.strokeMaterial.getName()}); 158 NJevent("showMaterialPopup",{materialId : this.getProperty(el, "strokeMaterial")});
104 break; 159 break;
105 case "editFillMaterial": 160 case "editFillMaterial":
106 NJevent("showMaterialPopup",{materialId : el.elementModel.shapeModel.fillMaterial.getName()}); 161 NJevent("showMaterialPopup",{materialId : this.getProperty(el, "fillMaterial")});
107 break; 162 break;
108 case "animate": 163 case "animate":
109 if(value) 164 if(value)
@@ -119,9 +174,35 @@ exports.ShapesController = Montage.create(CanvasController, {
119 el.elementModel.shapeModel.GLWorld._canvas.task.stop(); 174 el.elementModel.shapeModel.GLWorld._canvas.task.stop();
120 } 175 }
121 break; 176 break;
177 case "strokeHardness":
178 this.setShapeProperty(el, "strokeHardness", value);
179 el.elementModel.shapeModel.GLGeomObj.setStrokeHardness(val);
180 el.elementModel.shapeModel.GLWorld.render();
181 break;
182 case "strokeSmoothing":
183 this.setShapeProperty(el, "strokeSmoothing", value);
184 el.elementModel.shapeModel.GLGeomObj.setSmoothingAmount(val);
185 el.elementModel.shapeModel.GLWorld.render();
186 break;
187 case "doSmoothing":
188 this.setShapeProperty(el, "doSmoothing", value);
189 el.elementModel.shapeModel.GLGeomObj.setDoSmoothing(value);
190 el.elementModel.shapeModel.GLWorld.render();
191 break;
192 case "isCalligraphic":
193 this.setShapeProperty(el, "isCalligraphic", value);