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.js80
1 files changed, 73 insertions, 7 deletions
diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js
index a5fc2224..6ce28ae4 100755
--- a/js/lib/rdge/materials/radial-gradient-material.js
+++ b/js/lib/rdge/materials/radial-gradient-material.js
@@ -1,7 +1,31 @@
1/* <copyright> 1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/> 2Copyright (c) 2012, Motorola Mobility, Inc
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> 3All Rights Reserved.
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4BSD License.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8
9 - Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 - Neither the name of Motorola Mobility nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28POSSIBILITY OF SUCH DAMAGE.
5</copyright> */ 29</copyright> */
6 30
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; 31var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
@@ -88,8 +112,9 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
88 this._propValues[this._propNames[7]] = this._defaultColorStop4; 112 this._propValues[this._propNames[7]] = this._defaultColorStop4;
89 113
90 var nProps = this._propNames.length; 114 var nProps = this._propNames.length;
91 for (var i=0; i<nProps; i++) 115 for (var i=0; i<nProps; i++) {
92 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); 116 this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] );
117 }
93 }; 118 };
94 119
95 this.fitToBounds = function( bounds ) 120 this.fitToBounds = function( bounds )
@@ -123,7 +148,7 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
123 this._shader['default'].u_texTransform.set( this._textureTransform ); 148 this._shader['default'].u_texTransform.set( this._textureTransform );
124 149
125 } 150 }
126 } 151 };
127 152
128 this.fitToPrimitiveArray = function( primArray ) 153 this.fitToPrimitiveArray = function( primArray )
129 { 154 {
@@ -159,7 +184,48 @@ var RadialGradientMaterial = function RadialGradientMaterial() {
159 { 184 {
160 jObj.u_texTransform = this._textureTransform.slice(); 185 jObj.u_texTransform = this._textureTransform.slice();
161 return jObj; 186 return jObj;
162 } 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) + '%';
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 };
163}; 229};
164 230
165/////////////////////////////////////////////////////////////////////////////////////// 231///////////////////////////////////////////////////////////////////////////////////////
@@ -216,4 +282,4 @@ RadialGradientMaterial.prototype = new Material();
216 282
217if (typeof exports === "object") { 283if (typeof exports === "object") {
218 exports.RadialGradientMaterial = RadialGradientMaterial; 284 exports.RadialGradientMaterial = RadialGradientMaterial;
219} \ No newline at end of file 285}