diff options
Diffstat (limited to 'js/lib/rdge/materials/linear-gradient-material.js')
-rwxr-xr-x | js/lib/rdge/materials/linear-gradient-material.js | 83 |
1 files changed, 79 insertions, 4 deletions
diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js index f5c54726..137ced27 100755 --- a/js/lib/rdge/materials/linear-gradient-material.js +++ b/js/lib/rdge/materials/linear-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; |
@@ -95,9 +119,60 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
95 | this._propValues[this._propNames[8]] = [ Math.cos(this._angle), Math.sin(this._angle) ]; | 119 | this._propValues[this._propNames[8]] = [ Math.cos(this._angle), Math.sin(this._angle) ]; |
96 | 120 | ||
97 | var nProps = this._propNames.length; | 121 | var nProps = this._propNames.length; |
98 | for (var i=0; i<nProps; i++) | 122 | for (var i=0; i<nProps; i++) { |
99 | this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); | 123 | this.setProperty( this._propNames[i], this._propValues[this._propNames[i]] ); |
124 | } | ||
100 | }; | 125 | }; |
126 | |||
127 | // Only Linear Gradient and Radial Gradients support gradients; | ||
128 | this.gradientType = "linear"; | ||
129 | |||
130 | this.getGradientData = function() { | ||
131 | var angle = Math.round(this._angle*180/Math.PI), | ||
132 | color, | ||
133 | colorStr, | ||
134 | css = "-webkit-gradient(linear, " + angle + "deg"; | ||
135 | |||
136 | // TODO - Angle is not supported in -webkit-gradient syntax, so just default to across: | ||
137 | css = '-webkit-gradient(linear, left top, right top'; | ||
138 | |||
139 | // TODO - Also, Color Model requires from and to in the gradient string | ||
140 | color = this.getProperty('u_color1'); | ||
141 | colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100); | ||
142 | css += ', from(rgba(' + colorStr + '))'; | ||
143 | |||
144 | for (var i=2; i < 4; i++) { | ||
145 | color = this.getProperty('u_color'+i); | ||
146 | colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100); | ||
147 | css += ', color-stop(' + this.getProperty('u_colorStop'+i) + ', rgba(' + colorStr + '))'; | ||
148 | } | ||
149 | |||
150 | color = this.getProperty('u_color4'); | ||
151 | colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100); | ||
152 | css += ', to(rgba(' + colorStr + '))'; | ||
153 | |||
154 | css += ')'; | ||
155 | |||
156 | return css; | ||
157 | }; | ||
158 | |||
159 | // Only Linear Gradient and Radial Gradient have gradient data. | ||
160 | this.setGradientData = function(colors) { | ||
161 | var len = colors.length; | ||
162 | // TODO - Current shaders only support 4 color stops | ||
163 | if (len > 4) { | ||
164 | len = 4; | ||
165 | } | ||
166 | |||
167 | for (var n = 0; n < len; n++) { | ||
168 | var position = colors[n].position/100; | ||
169 | var cs = colors[n].value; | ||
170 | var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a]; | ||
171 | |||
172 | this.setProperty("u_color" + (n + 1), stop.slice(0)); | ||
173 | this.setProperty("u_colorStop" + (n + 1), position); | ||
174 | } | ||
175 | }; | ||
101 | }; | 176 | }; |
102 | 177 | ||
103 | /////////////////////////////////////////////////////////////////////////////////////// | 178 | /////////////////////////////////////////////////////////////////////////////////////// |