aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/linear-gradient-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/linear-gradient-material.js')
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js82
1 files changed, 78 insertions, 4 deletions
diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js
index 7e53db84..50ef56f0 100755
--- a/js/lib/rdge/materials/linear-gradient-material.js
+++ b/js/lib/rdge/materials/linear-gradient-material.js
@@ -1,8 +1,32 @@
1/* <copyright> 1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/> 2Copyright (c) 2012, Motorola Mobility, Inc
3 No 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 </copyright> */ 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.
29</copyright> */
6 30
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; 31var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser;
8var Material = require("js/lib/rdge/materials/material").Material; 32var Material = require("js/lib/rdge/materials/material").Material;
@@ -79,6 +103,56 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
79 this.setShaderValues(); 103 this.setShaderValues();
80 this.update( 0 ); 104 this.update( 0 );
81 }; 105 };
106
107 // Only Linear Gradient and Radial Gradients support gradients;
108 this.gradientType = "linear";
109
110 this.getGradientData = function() {
111 var angle = Math.round(this._angle*180/Math.PI),
112 color,
113 colorStr,
114 css = "-webkit-gradient(linear, " + angle + "deg";
115
116 // TODO - Angle is not supported in -webkit-gradient syntax, so just default to across:
117 css = '-webkit-gradient(linear, left top, right top';
118
119 // TODO - Also, Color Model requires from and to in the gradient string
120 color = this.getProperty('u_color1');
121 colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100);
122 css += ', from(rgba(' + colorStr + '))';
123
124 for (var i=2; i < 4; i++) {
125 color = this.getProperty('u_color'+i);
126 colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100);
127 css += ', color-stop(' + this.getProperty('u_colorStop'+i) + ', rgba(' + colorStr + '))';
128 }
129
130 color = this.getProperty('u_color4');
131 colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100);
132 css += ', to(rgba(' + colorStr + '))';
133
134 css += ')';
135
136 return css;
137 };
138
139 // Only Linear Gradient and Radial Gradient have gradient data.
140 this.setGradientData = function(colors) {
141 var len = colors.length;
142 // TODO - Current shaders only support 4 color stops
143 if (len > 4) {
144 len = 4;
145 }
146
147 for (var n = 0; n < len; n++) {
148 var position = colors[n].position/100;
149 var cs = colors[n].value;
150 var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a];
151
152 this.setProperty("u_color" + (n + 1), stop.slice(0));
153 this.setProperty("u_colorStop" + (n + 1), position);
154 }
155 };
82}; 156};
83 157
84/////////////////////////////////////////////////////////////////////////////////////// 158///////////////////////////////////////////////////////////////////////////////////////