aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/linear-gradient-material.js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-07-09 11:43:36 -0700
committerNivesh Rajbhandari2012-07-09 11:43:36 -0700
commitac27d538af33ca8d67d3d88729f49c05793afda7 (patch)
tree4be9251ff087e93a37b1f463ae9eaaaf779caeeb /js/lib/rdge/materials/linear-gradient-material.js
parenteff1851b2189bea8b89065980d02541cecea5ddf (diff)
downloadninja-ac27d538af33ca8d67d3d88729f49c05793afda7.tar.gz
PI, drawing and editing fixes for shapes and materials.
IKNinja-1841 - Cannot change webgl shape with LinearGradient and RadialGradient to solid color. IKNINJA-1851 - Cannot draw webgl shapes with Linear/RadialGradient material. IKNINJA-1864 - PI doesn't update the color of shape if WebGL material switches to Flat. IKNINJA-1886 - Gradient edits not applied to WebGL Stage object. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
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 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///////////////////////////////////////////////////////////////////////////////////////