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.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js
index 981bf9fd..50ef56f0 100755
--- a/js/lib/rdge/materials/linear-gradient-material.js
+++ b/js/lib/rdge/materials/linear-gradient-material.js
@@ -103,6 +103,56 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
103 this.setShaderValues(); 103 this.setShaderValues();
104 this.update( 0 ); 104 this.update( 0 );
105 }; 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 };
106}; 156};
107 157
108/////////////////////////////////////////////////////////////////////////////////////// 158///////////////////////////////////////////////////////////////////////////////////////