diff options
Diffstat (limited to 'js/lib/rdge/materials/linear-gradient-material.js')
-rwxr-xr-x | js/lib/rdge/materials/linear-gradient-material.js | 50 |
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 7e53db84..d26143de 100755 --- a/js/lib/rdge/materials/linear-gradient-material.js +++ b/js/lib/rdge/materials/linear-gradient-material.js | |||
@@ -79,6 +79,56 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
79 | this.setShaderValues(); | 79 | this.setShaderValues(); |
80 | this.update( 0 ); | 80 | this.update( 0 ); |
81 | }; | 81 | }; |
82 | |||
83 | // Only Linear Gradient and Radial Gradients support gradients; | ||
84 | this.gradientType = "linear"; | ||
85 | |||
86 | this.getGradientData = function() { | ||
87 | var angle = Math.round(this._angle*180/Math.PI), | ||
88 | color, | ||
89 | colorStr, | ||
90 | css = "-webkit-gradient(linear, " + angle + "deg"; | ||
91 | |||
92 | // TODO - Angle is not supported in -webkit-gradient syntax, so just default to across: | ||
93 | css = '-webkit-gradient(linear, left top, right top'; | ||
94 | |||
95 | // TODO - Also, Color Model requires from and to in the gradient string | ||
96 | color = this.getProperty('u_color1'); | ||
97 | colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100); | ||
98 | css += ', from(rgba(' + colorStr + '))'; | ||
99 | |||
100 | for (var i=2; i < 4; i++) { | ||
101 | color = this.getProperty('u_color'+i); | ||
102 | colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100); | ||
103 | css += ', color-stop(' + this.getProperty('u_colorStop'+i) + ', rgba(' + colorStr + '))'; | ||
104 | } | ||
105 | |||
106 | color = this.getProperty('u_color4'); | ||
107 | colorStr = Math.round(color[0] * 255) + ', ' + Math.round(color[1] * 255) + ', ' + Math.round(color[2] * 255) + ', ' + Math.round(color[3] * 100); | ||
108 | css += ', to(rgba(' + colorStr + '))'; | ||
109 | |||
110 | css += ')'; | ||
111 | |||
112 | return css; | ||
113 | }; | ||
114 | |||
115 | // Only Linear Gradient and Radial Gradient have gradient data. | ||
116 | this.setGradientData = function(colors) { | ||
117 | var len = colors.length; | ||
118 | // TODO - Current shaders only support 4 color stops | ||
119 | if (len > 4) { | ||
120 | len = 4; | ||
121 | } | ||
122 | |||
123 | for (var n = 0; n < len; n++) { | ||
124 | var position = colors[n].position/100; | ||
125 | var cs = colors[n].value; | ||
126 | var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a]; | ||
127 | |||
128 | this.setProperty("u_color" + (n + 1), stop.slice(0)); | ||
129 | this.setProperty("u_colorStop" + (n + 1), position); | ||
130 | } | ||
131 | }; | ||
82 | }; | 132 | }; |
83 | 133 | ||
84 | /////////////////////////////////////////////////////////////////////////////////////// | 134 | /////////////////////////////////////////////////////////////////////////////////////// |