v0.4.2b: corrected gradient functionality

This commit is contained in:
Evan Debenham
2016-09-13 20:34:49 -04:00
parent aaadf4afb6
commit 940363c3bc
4 changed files with 14 additions and 54 deletions
@@ -66,9 +66,9 @@ public class TextureCache {
}
}
public static SmartTexture createGradient( int width, int height, int... colors ) {
public static SmartTexture createGradient( int... colors ) {
final String key = "" + width + "x" + height + ":" + colors;
final String key = "" + colors;
if (all.containsKey( key )) {
@@ -76,13 +76,15 @@ public class TextureCache {
} else {
Bitmap bmp = Bitmap.createBitmap( width, height, Bitmap.Config.ARGB_8888 );
Canvas canvas = new Canvas( bmp );
Paint paint = new Paint();
paint.setShader( new LinearGradient( 0, 0, 0, height, colors, null, TileMode.CLAMP ) );
canvas.drawPaint( paint );
Bitmap bmp = Bitmap.createBitmap( colors.length, 1, Bitmap.Config.ARGB_8888 );
for (int i=0; i < colors.length; i++) {
bmp.setPixel( i, 0, colors[i] );
}
SmartTexture tx = new SmartTexture( bmp );
tx.filter( Texture.LINEAR, Texture.LINEAR );
tx.wrap( Texture.CLAMP, Texture.CLAMP );
all.put( key, tx );
return tx;
}