aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/radial-gradient-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/radial-gradient-material.js')
-rwxr-xr-xjs/lib/rdge/materials/radial-gradient-material.js43
1 files changed, 42 insertions, 1 deletions
diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js
index 6a5a9e9a..ffca1686 100755
--- a/js/lib/rdge/materials/radial-gradient-material.js
+++ b/js/lib/rdge/materials/radial-gradient-material.js
@@ -137,7 +137,48 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
137 { 137 {
138 jObj.u_texTransform = this._textureTransform.slice(); 138 jObj.u_texTransform = this._textureTransform.slice();
139 return jObj; 139 return jObj;
140 } 140 };
141
142 // Only Linear Gradient and Radial Gradient have gradient data.
143 this.gradientType = "radial";
144
145 this.getGradientData = function() {
146 var angle = Math.round(this._angle*180/Math.PI),
147 color,
148 colorStr,
149 css = "-webkit-gradient(linear, " + angle + "deg";
150
151 // TODO - Angle is not supported in -webkit-gradient syntax, so just default to across:
152 css = '-webkit-radial-gradient(50% 50%, ellipse cover';
153
154 // TODO - Also, Color Model requires from and to in the gradient string
155 for (var i=1; i < 5; i++) {
156 color = this.getProperty('u_color'+i);
157 colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100);
158 css += ', rgba(' + colorStr + ') ' + Math.round(this.getProperty('u_colorStop'+i)*100) + '%';
159 }
160
161 css += ')';
162
163 return css;
164 };
165
166 this.setGradientData = function(colors) {
167 var len = colors.length;
168 // TODO - Current shaders only support 4 color stops
169 if (len > 4) {
170 len = 4;
171 }
172
173 for (var n = 0; n < len; n++) {
174 var position = colors[n].position/100;
175 var cs = colors[n].value;
176 var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a];
177
178 this.setProperty("u_color" + (n + 1), stop.slice(0));
179 this.setProperty("u_colorStop" + (n + 1), position);
180 }
181 };
141}; 182};
142 183
143/////////////////////////////////////////////////////////////////////////////////////// 184///////////////////////////////////////////////////////////////////////////////////////