diff options
Diffstat (limited to 'js/lib/rdge/materials/radial-gradient-material.js')
-rwxr-xr-x | js/lib/rdge/materials/radial-gradient-material.js | 75 |
1 files changed, 70 insertions, 5 deletions
diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js index c9c2536f..ffca1686 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> |
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | 2 | Copyright (c) 2012, Motorola Mobility, Inc |
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | 3 | All Rights Reserved. |
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | BSD License. |
5 | |||
6 | Redistribution and use in source and binary forms, with or without | ||
7 | modification, 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 | |||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
28 | POSSIBILITY OF SUCH DAMAGE. | ||
5 | </copyright> */ | 29 | </copyright> */ |
6 | 30 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 31 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; |
@@ -113,7 +137,48 @@ var RadialGradientMaterial = function RadialGradientMaterial() { | |||
113 | { | 137 | { |
114 | jObj.u_texTransform = this._textureTransform.slice(); | 138 | jObj.u_texTransform = this._textureTransform.slice(); |
115 | return jObj; | 139 | return jObj; |
116 | } | 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 | }; | ||
117 | }; | 182 | }; |
118 | 183 | ||
119 | /////////////////////////////////////////////////////////////////////////////////////// | 184 | /////////////////////////////////////////////////////////////////////////////////////// |
@@ -170,4 +235,4 @@ RadialGradientMaterial.prototype = new Material(); | |||
170 | 235 | ||
171 | if (typeof exports === "object") { | 236 | if (typeof exports === "object") { |
172 | exports.RadialGradientMaterial = RadialGradientMaterial; | 237 | exports.RadialGradientMaterial = RadialGradientMaterial; |
173 | } \ No newline at end of file | 238 | } |