aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/radial-gradient-material.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-03-06 11:05:00 -0800
committerValerio Virgillito2012-03-06 11:05:00 -0800
commit4540b5b4ea2065c3e0d67b46bba8b6764801fbea (patch)
tree4e1561530b1b90ea497bac8e41d193fa605e98b4 /js/lib/rdge/materials/radial-gradient-material.js
parent4e35725e6c9044c37bef28b8c8d36f4b5c89bfd9 (diff)
parent84332ab81c1b445195f1d9be8bbeae0725c8e758 (diff)
downloadninja-4540b5b4ea2065c3e0d67b46bba8b6764801fbea.tar.gz
Merge branch 'refs/heads/master' into panels
Diffstat (limited to 'js/lib/rdge/materials/radial-gradient-material.js')
-rwxr-xr-xjs/lib/rdge/materials/radial-gradient-material.js351
1 files changed, 351 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js
new file mode 100755
index 00000000..13be50f5
--- /dev/null
+++ b/js/lib/rdge/materials/radial-gradient-material.js
@@ -0,0 +1,351 @@
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
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
8var Material = require("js/lib/rdge/materials/material").Material;
9
10var RadialGradientMaterial = function RadialGradientMaterial() {
11 ///////////////////////////////////////////////////////////////////////
12 // Instance variables
13 ///////////////////////////////////////////////////////////////////////
14 this._name = "RadialGradientMaterial";
15 this._shaderName = "radialGradient";
16
17 this._color1 = [1,0,0,1];
18 this._color2 = [0,1,0,1];
19 this._color3 = [0,0,1,1];
20 this._color4 = [0,1,1,1];
21 this._colorStop1 = 0.0;
22 this._colorStop2 = 0.3;
23 this._colorStop3 = 0.6;
24 this._colorStop4 = 1.0;
25// this._colorCount = 4;
26
27 ///////////////////////////////////////////////////////////////////////
28 // Property Accessors
29 ///////////////////////////////////////////////////////////////////////
30 this.getName = function() {
31 return this._name;
32 };
33
34 this.getShaderName = function() {
35 return this._shaderName;
36 };
37
38 this.getColor1 = function() {
39 return this._color1;
40 };
41
42 this.setColor1 = function(c) {
43 this._color1 = c.slice();
44 if (this._shader && this._shader['default']) {
45 this._shader['default'].u_color1.set(c);
46 }
47 };
48
49 this.getColor2 = function() {
50 return this._color2;
51 };
52
53 this.setColor2 = function(c) {
54 this._color2 = c.slice();
55 if (this._shader && this._shader['default']) {
56 this._shader['default'].u_color2.set(c);
57 }
58
59 };
60
61 this.getColor3 = function() {
62 return this._color3;
63 };
64
65 this.setColor3 = function(c) {
66 this._color3 = c.slice();
67 if (this._shader && this._shader['default']) {
68 this._shader['default'].u_color3.set(c);
69 }
70 };
71
72 this.getColor4 = function() {
73 return this._color4;
74 };
75
76 this.setColor4 = function(c) {
77 this._color4 = c.slice();
78 if (this._shader && this._shader['default']) {
79 this._shader['default'].u_color4.set(c);
80 }
81 };
82
83 this.getColorStop1 = function() {
84 return this._colorStop1;
85 };
86
87 this.setColorStop1 = function(s) {
88 this._colorStop1 = s;
89 if (this._shader && this._shader['default']) {
90 this._shader['default'].u_colorStop1.set([s]);
91 }
92 };
93
94 this.getColorStop2 = function() {
95 return this._colorStop2;
96 };
97
98 this.setColorStop2 = function(s) {
99 this._colorStop2 = s;
100 if (this._shader && this._shader['default']) {
101 this._shader['default'].u_colorStop2.set([s]);
102 }
103 };
104
105 this.getColorStop3 = function() {
106 return this._colorStop3;
107 };
108
109 this.setColorStop3 = function(s) {
110 this._colorStop3 = s;
111 if (this._shader && this._shader['default']) {
112 this._shader['default'].u_colorStop3.set([s]);
113 }
114 };
115
116 this.getColorStop4 = function() {
117 return this._colorStop4;
118 };
119
120 this.setColorStop4 = function(s) {
121 this._colorStop4 = s;
122 if (this._shader && this._shader['default']) {
123 this._shader['default'].u_colorStop4.set([s]);
124 }
125 };
126
127 this.getColorCount = function() {
128 return this._colorCount;
129 };
130
131 this.setColorCount = function(c) {
132 this._colorCount = c;
133 if (this._shader && this._shader['default']) {
134 this._shader['default'].u_colorCount.set([c]);
135 }
136 };
137
138 this.isAnimated = function() {
139 return false;
140 };
141
142
143 ///////////////////////////////////////////////////////////////////////
144 // Material Property Accessors
145 ///////////////////////////////////////////////////////////////////////
146 this._propNames = ["color1", "color2", "color3", "color4", "colorStop1", "colorStop2", "colorStop3", "colorStop4", "angle"];
147 this._propLabels = ["Color 1", "Color 2", "Color 3", "Color 4", "Color Stop 1", "Color Stop 2", "Color Stop 3", "Color Stop 4", "Angle"];
148 this._propTypes = ["color", "color", "color", "color", "float", "float", "float", "float", "float"];
149 this._propValues = [];
150
151 this._propValues[ this._propNames[0] ] = this._color1.slice(0);
152 this._propValues[ this._propNames[1] ] = this._color2.slice(0);
153 this._propValues[ this._propNames[2] ] = this._color3.slice(0);
154 this._propValues[ this._propNames[3] ] = this._color4.slice(0);
155
156 this._propValues[ this._propNames[4] ] = this._colorStop1;
157 this._propValues[ this._propNames[5] ] = this._colorStop2;
158 this._propValues[ this._propNames[6] ] = this._colorStop3;
159 this._propValues[ this._propNames[7] ] = this._colorStop4;
160
161 this.setProperty = function( prop, value ) {
162 if (prop === "color") prop = "color1";
163
164 // make sure we have legitimate imput
165 var ok = this.validateProperty( prop, value );
166 if (!ok) {
167 console.log( "invalid property in Radial Gradient Material:" + prop + " : " + value );
168 }
169
170 switch (prop)
171 {
172 case "color1": this.setColor1( value ); break;
173 case "color2": this.setColor2( value ); break;
174 case "color3": this.setColor3( value ); break;
175 case "color4": this.setColor4( value ); break;
176 case "colorStop1": this.setColorStop1( value ); break;
177 case "colorStop2": this.setColorStop2( value ); break;
178 case "colorStop3": this.setColorStop3( value ); break;
179 case "colorStop4": this.setColorStop4( value ); break;
180 case "angle": this.setAngle( value ); break;
181 }
182
183 //this.updateValuesInShader();
184 };
185 ///////////////////////////////////////////////////////////////////////
186
187
188 ///////////////////////////////////////////////////////////////////////
189 // Methods
190 ///////////////////////////////////////////////////////////////////////
191 // duplcate method requirde
192 this.dup = function() {
193 return new RadialGradientMaterial();
194 };
195
196 this.init = function() {
197 // set up the shader
198 this._shader = new jshader();
199 this._shader.def = radialGradientMaterialDef;
200 this._shader.init();
201
202 // set up the material node
203 this._materialNode = createMaterialNode("radialGradientMaterial");
204 this._materialNode.setShader(this._shader);
205
206 // set the shader values in the shader
207 this.updateValuesInShader();
208 };
209
210 this.updateValuesInShader = function() {
211 if (this._shader && this._shader['default']) {