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

View File

@@ -1,42 +0,0 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2016 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.watabou.gltextures;
import android.graphics.Bitmap;
public class Gradient extends SmartTexture {
public Gradient( int colors[] ) {
super( Bitmap.createBitmap( colors.length, 1, Bitmap.Config.ARGB_8888 ) );
for (int i=0; i < colors.length; i++) {
bitmap.setPixel( i, 0, colors[i] );
}
bitmap( bitmap );
filter( LINEAR, LINEAR );
wrap( CLAMP, CLAMP );
TextureCache.add( Gradient.class, this );
}
}

View File

@@ -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;
}