aboutsummaryrefslogtreecommitdiff
path: root/js/panels/Materials/materials-popup.reel/materials-popup.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-06-27 14:21:27 -0700
committerNivesh Rajbhandari2012-06-27 14:21:27 -0700
commit978b9049d057d2a0995758275f68da8641193201 (patch)
treed26fadef6100d5eb87e871a68f8c71fac9ab27a6 /js/panels/Materials/materials-popup.reel/materials-popup.js
parent8351c3685a6db703d1940817abc71f92ef4e1bd4 (diff)
downloadninja-978b9049d057d2a0995758275f68da8641193201.tar.gz
Integrating Materials UI changes. Squashed commit of the following:
commit 89ccb55130e67c4516e616ccc56d2a649a2b9160 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Wed Jun 27 14:20:01 2012 -0700 Position Materials Editor popup and change buttons' text color. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 89bca82adc781f4913f8d302a49a8baa907631c5 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Wed Jun 27 12:00:51 2012 -0700 Support deleting and editing custom materials. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 5be5160c4786beb70e8ad4d75562adb135718c6c Merge: 1d9d9f6 2ebf3e3 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Wed Jun 27 11:11:37 2012 -0700 Merge branch 'refs/heads/ninja-internal' into WebGLMaterials Conflicts: js/data/panels-data.js Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 1d9d9f6e66ea7585f07ed461cebba99e71f65de0 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Tue Jun 26 22:01:22 2012 -0700 "Save as" support to duplicate material with modified settings. Also removed Add button and disabled Reset button for now. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit bf1037508dbc686f2884765344832f906cbf06d0 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Tue Jun 26 17:23:31 2012 -0700 Added UI for duplicating and deleting materials in the Materials Library. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 54930792f9c417df5f739831164aa1f96a41d67a Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Tue Jun 26 14:29:17 2012 -0700 Added preview of material in materials editor popup and fixed some styling. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/panels/Materials/materials-popup.reel/materials-popup.js')
-rwxr-xr-xjs/panels/Materials/materials-popup.reel/materials-popup.js333
1 files changed, 106 insertions, 227 deletions
diff --git a/js/panels/Materials/materials-popup.reel/materials-popup.js b/js/panels/Materials/materials-popup.reel/materials-popup.js
index 40f07509..3f702459 100755
--- a/js/panels/Materials/materials-popup.reel/materials-popup.js
+++ b/js/panels/Materials/materials-popup.reel/materials-popup.js
@@ -6,7 +6,10 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
6 6
7var Montage = require("montage/core/core").Montage, 7var Montage = require("montage/core/core").Montage,
8 Component = require("montage/ui/component").Component, 8 Component = require("montage/ui/component").Component,
9 MaterialsModel = require("js/models/materials-model").MaterialsModel; 9 MaterialsModel = require("js/models/materials-model").MaterialsModel,
10 NJUtils = require("js/lib/NJUtils").NJUtils,
11 World = require("js/lib/drawing/world").World,
12 Rectangle = require("js/lib/geom/rectangle").Rectangle;
10 13
11//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
12//Exporting as MaterialsPopup 15//Exporting as MaterialsPopup
@@ -22,11 +25,35 @@ exports.MaterialsPopup = Montage.create(Component, {
22 serializable: true 25 serializable: true
23 }, 26 },
24 27
28 saveAsButton: {
29 value: null,
30 serializable: true
31 },
32
33 resetButton: {
34 value: null,
35 serializable: true
36 },
37
38 materialsLibraryRef: {
39 value: null
40 },
41
25 materialTitle: { 42 materialTitle: {
26 value: null, 43 value: null,
27 serializable: true 44 serializable: true
28 }, 45 },
29 46
47 previewCanvas: {
48 value: null,
49 serializable: true
50 },
51
52 previewShape: {
53 value: null,
54 serializable: true
55 },
56
30 // Material Properties 57 // Material Properties
31 _materialName: { 58 _materialName: {
32 enumerable: true, 59 enumerable: true,
@@ -65,6 +92,12 @@ exports.MaterialsPopup = Montage.create(Component, {
65 92
66 } 93 }
67 break; 94 break;
95 case "Save As...":
96 this.saveAs();
97 break;
98 case "Reset":
99 this.reset();
100 break;
68 } 101 }
69 102
70 // Notify Materials Library to close popup 103 // Notify Materials Library to close popup
@@ -72,6 +105,28 @@ exports.MaterialsPopup = Montage.create(Component, {
72 } 105 }
73 }, 106 },
74 107
108 saveAs:
109 {
110 value: function()
111 {
112 console.log("Save As...");
113 var materialCopy = prompt("Save material as", this._materialName + "_Copy");
114
115 if (materialCopy)
116 {
117 this.materialsLibraryRef.duplicateMaterial(materialCopy);
118 }
119 }
120 },
121
122 reset:
123 {
124 value: function()
125 {
126 console.log("Reset");
127 }
128 },
129
75 revertToOriginalValues: 130 revertToOriginalValues:
76 { 131 {
77 value: function() 132 value: function()
@@ -195,6 +250,7 @@ exports.MaterialsPopup = Montage.create(Component, {
195 this._material.setProperty( this._propNames[index], value ); 250 this._material.setProperty( this._propNames[index], value );
196 } 251 }
197 252
253 var obj, matArray, matTypeArray, nMats, iMat, world;
198 if (this._useSelection) 254 if (this._useSelection)
199 { 255 {
200 console.log( "apply to selection" ); 256 console.log( "apply to selection" );
@@ -206,25 +262,38 @@ exports.MaterialsPopup = Montage.create(Component, {
206 for (var iObj=0; iObj<nObjs; iObj++) 262 for (var iObj=0; iObj<nObjs; iObj++)
207 { 263 {
208 var canvas = selection[iObj]; 264 var canvas = selection[iObj];
209 var obj;
210 if (canvas.elementModel && canvas.elementModel.shapeModel) obj = canvas.elementModel.shapeModel.GLGeomObj; 265 if (canvas.elementModel && canvas.elementModel.shapeModel) obj = canvas.elementModel.shapeModel.GLGeomObj;
211 if (obj) 266 if (obj)
212 { 267 {
213 var matArray = obj._materialArray; 268 matArray = obj._materialArray;
214 var matTypeArray = obj._materialTypeArray; 269 matTypeArray = obj._materialTypeArray;
215 var nMats = matArray.length; 270 nMats = matArray.length;
216 for (var iMat=0; iMat<nMats; iMat++) 271 for (iMat=0; iMat<nMats; iMat++)
217 { 272 {
218 if (matTypeArray[iMat] === this._whichMaterial) 273 if (matTypeArray[iMat] === this._whichMaterial)
219 matArray[iMat].setProperty( this._propNames[index], value ); 274 matArray[iMat].setProperty( this._propNames[index], value );
220 } 275 }
221 var world = obj.getWorld(); 276 world = obj.getWorld();
222 if (world) 277 if (world)
223 world.restartRenderLoop(); 278 world.restartRenderLoop();
224 } 279 }
225 } 280 }
226 } 281 }
227 } 282 }
283
284 // Update preview material
285 obj = this.previewShape;
286 matArray = obj._materialArray;
287 matTypeArray = obj._materialTypeArray;
288 nMats = matArray.length;
289 for (iMat=0; iMat<nMats; iMat++)
290 {
291 if (matTypeArray[iMat] === "fill")
292 matArray[iMat].setProperty( this._propNames[index], value );
293 }
294 world = obj.getWorld();
295 if (world)
296 world.restartRenderLoop();
228 } 297 }
229 } 298 }
230 }, 299 },
@@ -286,8 +355,13 @@ exports.MaterialsPopup = Montage.create(Component, {
286 enumerable: false, 355 enumerable: false,
287 value: function() { 356 value: function() {
288 this.cancelButton.addEventListener("action", this, true); 357 this.cancelButton.addEventListener("action", this, true);
289
290 this.okButton.addEventListener("action", this, true); 358 this.okButton.addEventListener("action", this, true);
359 this.saveAsButton.addEventListener("action", this, true);
360 this.resetButton.addEventListener("action", this, true);
361
362 if (!this.previewCanvas.getAttribute( "data-RDGE-id" )) {
363 this.previewCanvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() );
364 }
291 } 365 }
292 }, 366 },
293 //////////////////////////////////////////////////////////////////// 367 ////////////////////////////////////////////////////////////////////
@@ -295,7 +369,23 @@ exports.MaterialsPopup = Montage.create(Component, {
295 didDraw: { 369 didDraw: {
296 enumerable: false, 370 enumerable: false,
297 value: function() { 371 value: function() {
298 this.materialTitle.innerHTML = this._materialName; 372
373 var world;