v0.4.2b: corrected gradient functionality
This commit is contained in:
parent
aaadf4afb6
commit
940363c3bc
|
@ -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 );
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ package com.shatteredpixel.shatteredpixeldungeon.effects;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.opengl.GLES20;
|
||||
import com.watabou.gltextures.Gradient;
|
||||
import com.watabou.gltextures.SmartTexture;
|
||||
import com.watabou.gltextures.TextureCache;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.Group;
|
||||
import com.watabou.noosa.NoosaScript;
|
||||
|
@ -56,7 +56,7 @@ public class Flare extends Visual {
|
|||
super( 0, 0, 0, 0 );
|
||||
|
||||
int gradient[] = {0xFFFFFFFF, 0x00FFFFFF};
|
||||
texture = new Gradient( gradient );
|
||||
texture = TextureCache.createGradient( gradient );
|
||||
|
||||
this.nRays = nRays;
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.sprites.RatSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
|
||||
import com.watabou.gltextures.Gradient;
|
||||
import com.watabou.gltextures.SmartTexture;
|
||||
import com.watabou.gltextures.TextureCache;
|
||||
import com.watabou.glwrap.Matrix;
|
||||
import com.watabou.glwrap.Quad;
|
||||
import com.watabou.input.Touchscreen.Touch;
|
||||
|
@ -205,7 +205,7 @@ public class SurfaceScene extends PixelScene {
|
|||
public Sky( boolean dayTime ) {
|
||||
super( 0, 0, 1, 1 );
|
||||
|
||||
texture = new Gradient( dayTime ? day : night );
|
||||
texture = TextureCache.createGradient( dayTime ? day : night );
|
||||
|
||||
float[] vertices = new float[16];
|
||||
verticesBuffer = Quad.create();
|
||||
|
|
Loading…
Reference in New Issue
Block a user