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.js92
1 files changed, 90 insertions, 2 deletions
diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js
index ab7cf484..f1094771 100755
--- a/js/lib/rdge/materials/radial-gradient-material.js
+++ b/js/lib/rdge/materials/radial-gradient-material.js
@@ -99,9 +99,26 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
99 this.setShaderValues(); 99 this.setShaderValues();
100 }; 100 };
101 101
102 this.fitToPrimitive = function( prim ) 102 this.resetToDefault = function()
103 { 103 {
104 var bounds = ShapePrimitive.getBounds( prim ); 104 this._propValues[this._propNames[0]] = this._defaultColor1.slice(0);
105 this._propValues[this._propNames[1]] = this._defaultColor2.slice(0);
106 this._propValues[this._propNames[2]] = this._defaultColor3.slice(0);
107 this._propValues[this._propNames[3]] = this._defaultColor4.slice(0);
108
109 this._propValues[this._propNames[4]] = this._defaultColorStop1;
110 this._propValues[this._propNames[5]] = this._defaultColorStop2;
111 this._propValues[this._propNames[6]] = this._defaultColorStop3;
112 this._propValues[this._propNames[7]] = this._defaultColorStop4;
113
114 var nProps = this._propNames.length;
115 for (var i=0; i<nProps; i++) {
116 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] );
117 }
118 };
119
120 this.fitToBounds = function( bounds )
121 {
105 if (bounds) 122 if (bounds)
106 { 123 {
107 var dx = Math.abs( bounds[3] - bounds[0] ), 124 var dx = Math.abs( bounds[3] - bounds[0] ),
@@ -133,11 +150,82 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
133 } 150 }
134 }; 151 };
135 152
153 this.fitToPrimitiveArray = function( primArray )
154 {
155 if (!primArray) return;
156 var nPrims = primArray.length;
157 if (nPrims == 0) return;
158 var bounds = ShapePrimitive.getBounds( primArray[0] );
159 for (var i=1; i<nPrims; i++)
160 {
161 var prim = primArray[i];
162 var b2 = ShapePrimitive.getBounds( prim );
163
164 // [xMin, yMin, zMin, xMax, yMax, zMax]
165 if (b2[0] < bounds[0]) bounds[0] = b2[0];
166 if (b2[1] < bounds[1]) bounds[1] = b2[1];
167 if (b2[2] < bounds[2]) bounds[2] = b2[2];
168
169 if (b2[3] > bounds[3]) bounds[3] = b2[3];
170 if (b2[4] > bounds[4]) bounds[4] = b2[4];
171 if (b2[5] > bounds[5]) bounds[5] = b2[5];
172 }
173
174 this.fitToBounds( bounds );
175 };
176
177 this.fitToPrimitive = function( prim )
178 {
179 var bounds = ShapePrimitive.getBounds( prim );
180 this.fitToBounds( bounds );
181 };
182
136 this.customExport = function( jObj ) 183 this.customExport = function( jObj )
137 { 184 {
138 jObj.u_texTransform = this._textureTransform.slice(); 185 jObj.u_texTransform = this._textureTransform.slice();
139 return jObj; 186 return jObj;
187 };
188
189 // Only Linear Gradient and Radial Gradient have gradient data.
190 this.gradientType = "radial";
191
192 this.getGradientData = function() {
193 var angle = Math.round(this._angle*180/Math.PI),
194 color,
195 colorStr,
196 css = "-webkit-gradient(linear, " + angle + "deg";
197
198 // TODO - Angle is not supported in -webkit-gradient syntax, so just default to across:
199 css = '-webkit-radial-gradient(50% 50%, ellipse cover';
200
201 // TODO - Also, Color Model requires from and to in the gradient string
202 for (var i=1; i < 5; i++) {
203 color = this.getProperty('u_color'+i);
204 colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100);
205 css += ', rgba(' + colorStr + ') ' + Math.round(this.getProperty('u_colorStop'+i)*100) + '%';
140 } 206 }
207
208 css += ')';
209
210 return css;
211};
212
213 this.setGradientData = function(colors) {
214 var len = colors.length;
215 // TODO - Current shaders only support 4 color stops
216 if (len > 4) {
217 len = 4;
218 }
219
220 for (var n = 0; n < len; n++) {
221 var position = colors[n].position/100;
222 var cs = colors[n].value;
223 var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a];
224
225 this.setProperty("u_color" + (n + 1), stop.slice(0));
226 this.setProperty("u_colorStop" + (n + 1), position);
227 }
228 };
141}; 229};
142 230
143/////////////////////////////////////////////////////////////////////////////////////// 231///////////////////////////////////////////////////////////////////////////////////////