diff options
Diffstat (limited to 'js/panels/Materials/materials-popup.reel/materials-popup.js')
-rw-r--r-- | js/panels/Materials/materials-popup.reel/materials-popup.js | 674 |
1 files changed, 674 insertions, 0 deletions
diff --git a/js/panels/Materials/materials-popup.reel/materials-popup.js b/js/panels/Materials/materials-popup.reel/materials-popup.js new file mode 100644 index 00000000..afdc3628 --- /dev/null +++ b/js/panels/Materials/materials-popup.reel/materials-popup.js | |||
@@ -0,0 +1,674 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var Montage = require("montage/core/core").Montage, | ||
8 | Component = require("montage/ui/component").Component; | ||
9 | var Button = require("js/components/button.reel").Button; | ||
10 | |||
11 | //////////////////////////////////////////////////////////////////////// | ||
12 | //Exporting as MaterialsPopup | ||
13 | exports.MaterialsPopup = Montage.create(Component, { | ||
14 | //////////////////////////////////////////////////////////////////// | ||
15 | okButton: { | ||
16 | enumerable: false, | ||
17 | value: null | ||
18 | }, | ||
19 | |||
20 | cancelButton: { | ||
21 | enumerable: false, | ||
22 | value: null | ||
23 | }, | ||
24 | |||
25 | //////////////////////////////////////////////////////////////////// | ||
26 | // Material Properties | ||
27 | |||
28 | materialsProperties: { | ||
29 | enumerable: true, | ||
30 | serializable: true, | ||
31 | value: null | ||
32 | }, | ||
33 | |||
34 | _materialName: { | ||
35 | enumerable: true, | ||
36 | value: "Material" | ||
37 | }, | ||
38 | |||
39 | materialTitle: { | ||
40 | enumerable: true, | ||
41 | value: null | ||
42 | }, | ||
43 | |||
44 | captureAction: { | ||
45 | value:function(event) { | ||
46 | switch(event._currentTarget.label) | ||
47 | { | ||
48 | case "Cancel": | ||
49 | console.log("Cancel material edit"); | ||
50 | break; | ||
51 | case "OK": | ||
52 | console.log("Committing material with the following values:"); | ||
53 | for(var i=0, len=this.materialsProperties.childComponents.length; i< len; i++) | ||
54 | { | ||
55 | var childControl = this.materialsProperties.childComponents[i]; | ||
56 | var childValue = childControl._control[childControl._prop]; | ||
57 | |||
58 | if(typeof childValue === "object") | ||
59 | { | ||
60 | console.log(childControl.label + " is "); | ||
61 | console.dir(childValue); | ||
62 | } | ||
63 | else | ||
64 | { | ||
65 | console.log(childControl.label + " is " + childValue); | ||
66 | } | ||
67 | console.log("--------------"); | ||
68 | |||
69 | } | ||
70 | break; | ||
71 | } | ||
72 | } | ||
73 | }, | ||
74 | |||
75 | updatePreview: | ||
76 | { | ||
77 | value: function(event) | ||
78 | { | ||
79 | if(event.type === "propertyChanging") | ||
80 | { | ||
81 | this._handlePropertyChanging(event); | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | this._handlePropertyChange(event); | ||
86 | } | ||
87 | } | ||
88 | }, | ||
89 | |||
90 | _handlePropertyChanging: | ||
91 | { | ||
92 | value: function(event) | ||
93 | { | ||
94 | if(typeof event.propertyValue === "object") | ||
95 | { | ||
96 | console.log(event.propertyLabel + " changing to "); | ||
97 | console.dir(event.propertyValue); | ||
98 | } | ||
99 | else | ||
100 | { | ||
101 | console.log(event.propertyLabel + " changing to " + event.propertyValue); | ||
102 | } | ||
103 | |||
104 | if (event.propertyLabel && event.propertyValue) | ||
105 | this.applyProperty( event.propertyLabel, event.propertyValue ); | ||
106 | } | ||
107 | }, | ||
108 | |||
109 | _handlePropertyChange: | ||
110 | { | ||
111 | value: function(event) | ||
112 | { | ||
113 | if(typeof event.propertyValue === "object") | ||
114 | { | ||
115 | console.log(event.propertyLabel + " changed to "); | ||
116 | console.dir(event.propertyValue); | ||
117 | } | ||
118 | else | ||
119 | { | ||
120 | console.log(event.propertyLabel + " changed to " + event.propertyValue); | ||
121 | } | ||
122 | |||
123 | if (event.propertyLabel) | ||
124 | this.applyProperty( event.propertyLabel, event.propertyValue ); | ||
125 | } | ||
126 | }, | ||
127 | |||
128 | applyProperty: | ||
129 | { | ||
130 | value: function( propLabel, propValue) | ||
131 | { | ||
132 | // find the property lable in the array | ||
133 | // This assumes no duplication in labels | ||
134 | if (this._propLabels) | ||
135 | { | ||
136 | // the label cones through with a trailing ':'. remove that | ||
137 | var ch = propLabel[ propLabel.length - 1]; | ||
138 | if (ch == ':') | ||
139 | propLabel = propLabel.substr(0, propLabel.length - 1); | ||
140 | |||
141 | var index; | ||
142 | var nProps = this._propLabels.length; | ||
143 | for (var i=0; i<nProps; i++) | ||
144 | { | ||
145 | if (this._propLabels[i] == propLabel) | ||
146 | { | ||
147 | index = i; | ||
148 | break; | ||
149 | } | ||
150 | } | ||
151 | if ((index != null) && this._material) | ||
152 | { | ||
153 | var value = this.decodeValue( this._propTypes[index], propValue ); | ||
154 | this._material.setProperty( this._propNames[index], value ); | ||
155 | } | ||
156 | } | ||
157 | } | ||
158 | }, | ||
159 | |||
160 | decodeValue: | ||
161 | { | ||
162 | value: function( type, value ) | ||
163 | { | ||
164 | var rtnValue; | ||
165 | switch (type) | ||
166 | { | ||
167 | case "color": | ||
168 | rtnValue = [ value['r']/255.0, value['g']/255.0, value['b']/255.0, value['a'] ]; | ||
169 | break; | ||
170 | |||
171 | case "vector2d": | ||
172 | case "vector3d": | ||
173 | rtnValue = []; | ||
174 | for (var i in value) rtnValue.push( value[i] ); | ||
175 | break; | ||
176 | |||
177 | case "float": | ||
178 | rtnValue = value; | ||
179 | break; | ||
180 | |||
181 | case "file": | ||
182 | if (value && (value.length > 0)) | ||
183 | { | ||
184 | var index = value.lastIndexOf( "/" ); | ||
185 | if (index < 0) index = value.lastIndexOf( "\\" ); | ||
186 | if (index >= 0) | ||
187 | value = value.substr( index+1 ); | ||
188 | value = "assets\\images\\" + value; | ||
189 | rtnValue = value.slice(0); | ||
190 | } | ||
191 | break; | ||
192 | |||
193 | case "checkbox": | ||
194 | rtnValue = value; | ||
195 | break; | ||
196 | |||
197 | default: | ||
198 | console.log( "unrecognized material control type: " + type ); | ||
199 | break; | ||
200 | } | ||
201 | return rtnValue; | ||
202 | } | ||
203 | }, | ||
204 | |||
205 | //////////////////////////////////////////////////////////////////// | ||
206 | // | ||
207 | prepareForDraw: { | ||
208 | enumerable: false, | ||
209 | value: function() { | ||
210 | this.cancelButton.addEventListener("action", this, true); | ||
211 | |||