Skip to content

Commit 76992d7

Browse files
author
Nicolas Gramlich
committed
Extracted color calculation/conversion methods from Color to ColorUtils. Removed all references to android.graphics.color. Changes around classes that used a ARGB color packed as int (coming from android.graphics.color).
1 parent 6dbfd36 commit 76992d7

File tree

13 files changed

+249
-107
lines changed

13 files changed

+249
-107
lines changed

src/org/andengine/entity/scene/background/modifier/ColorBackgroundModifier.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package org.andengine.entity.scene.background.modifier;
22

33
import org.andengine.entity.scene.background.IBackground;
4+
import org.andengine.util.color.Color;
45
import org.andengine.util.modifier.BaseTripleValueSpanModifier;
56
import org.andengine.util.modifier.ease.EaseLinear;
67
import org.andengine.util.modifier.ease.IEaseFunction;
78

89
/**
9-
* (c) 2010 Nicolas Gramlich
10+
* (c) 2010 Nicolas Gramlich
1011
* (c) 2011 Zynga Inc.
1112
*
1213
* @author Nicolas Gramlich
@@ -25,18 +26,34 @@ public class ColorBackgroundModifier extends BaseTripleValueSpanModifier<IBackgr
2526
// Constructors
2627
// ===========================================================
2728

29+
public ColorBackgroundModifier(final float pDuration, final Color pFromColor, final Color pToColor) {
30+
this(pDuration, pFromColor.getRed(), pToColor.getRed(), pFromColor.getGreen(), pToColor.getGreen(), pFromColor.getBlue(), pToColor.getBlue(), null, EaseLinear.getInstance());
31+
}
32+
2833
public ColorBackgroundModifier(final float pDuration, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue) {
2934
this(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, null, EaseLinear.getInstance());
3035
}
3136

37+
public ColorBackgroundModifier(final float pDuration, final Color pFromColor, final Color pToColor, final IEaseFunction pEaseFunction) {
38+
this(pDuration, pFromColor.getRed(), pToColor.getRed(), pFromColor.getGreen(), pToColor.getGreen(), pFromColor.getBlue(), pToColor.getBlue(), null, pEaseFunction);
39+
}
40+
3241
public ColorBackgroundModifier(final float pDuration, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue, final IEaseFunction pEaseFunction) {
3342
this(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, null, pEaseFunction);
3443
}
3544

45+
public ColorBackgroundModifier(final float pDuration, final Color pFromColor, final Color pToColor, final IBackgroundModifierListener pBackgroundModifierListener) {
46+
super(pDuration, pFromColor.getRed(), pToColor.getRed(), pFromColor.getGreen(), pToColor.getGreen(), pFromColor.getBlue(), pToColor.getBlue(), pBackgroundModifierListener, EaseLinear.getInstance());
47+
}
48+
3649
public ColorBackgroundModifier(final float pDuration, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue, final IBackgroundModifierListener pBackgroundModifierListener) {
3750
super(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, pBackgroundModifierListener, EaseLinear.getInstance());
3851
}
3952

53+
public ColorBackgroundModifier(final float pDuration, final Color pFromColor, final Color pToColor, final IBackgroundModifierListener pBackgroundModifierListener, final IEaseFunction pEaseFunction) {
54+
super(pDuration, pFromColor.getRed(), pToColor.getRed(), pFromColor.getGreen(), pToColor.getGreen(), pFromColor.getBlue(), pToColor.getBlue(), pBackgroundModifierListener, pEaseFunction);
55+
}
56+
4057
public ColorBackgroundModifier(final float pDuration, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue, final IBackgroundModifierListener pBackgroundModifierListener, final IEaseFunction pEaseFunction) {
4158
super(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, pBackgroundModifierListener, pEaseFunction);
4259
}

src/org/andengine/entity/shape/Shape.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ protected void initBlendFunction(final ITexture pTexture) {
146146
}
147147

148148
protected void initBlendFunction(final TextureOptions pTextureOptions) {
149-
if(pTextureOptions.mPreMultipyAlpha) {
149+
if(pTextureOptions.mPreMultiplyAlpha) {
150150
this.setBlendFunction(IShape.BLENDFUNCTION_SOURCE_PREMULTIPLYALPHA_DEFAULT, IShape.BLENDFUNCTION_DESTINATION_PREMULTIPLYALPHA_DEFAULT);
151151
}
152152
}

src/org/andengine/entity/sprite/batch/SpriteBatch.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
import org.andengine.opengl.vbo.HighPerformanceVertexBufferObject;
1616
import org.andengine.opengl.vbo.IVertexBufferObject;
1717
import org.andengine.opengl.vbo.LowMemoryVertexBufferObject;
18-
import org.andengine.opengl.vbo.VertexBufferObjectManager;
1918
import org.andengine.opengl.vbo.VertexBufferObject.DrawType;
19+
import org.andengine.opengl.vbo.VertexBufferObjectManager;
2020
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
2121
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributesBuilder;
2222
import org.andengine.util.adt.transformation.Transformation;
23-
import org.andengine.util.color.Color;
23+
import org.andengine.util.color.ColorUtils;
2424

2525
import android.opengl.GLES20;
2626

@@ -717,7 +717,7 @@ protected void addWithPackedColor(final ITextureRegion pTextureRegion, final flo
717717
* +-2
718718
*/
719719
private void addInner(final ITextureRegion pTextureRegion, final float pX1, final float pY1, final float pX2, final float pY2, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
720-
this.mSpriteBatchVertexBufferObject.addWithPackedColor(pTextureRegion, pX1, pY1, pX2, pY2, Color.packABGRFloat(pRed, pGreen, pBlue, pAlpha));
720+
this.mSpriteBatchVertexBufferObject.addWithPackedColor(pTextureRegion, pX1, pY1, pX2, pY2, ColorUtils.convertRGBAToABGRPackedFloat(pRed, pGreen, pBlue, pAlpha));
721721
}
722722

723723
/**
@@ -726,7 +726,7 @@ private void addInner(final ITextureRegion pTextureRegion, final float pX1, fina
726726
* 2-4
727727
*/
728728
private void addInner(final ITextureRegion pTextureRegion, final float pX1, final float pY1, final float pX2, final float pY2, final float pX3, final float pY3, final float pX4, final float pY4, final float pRed, final float pGreen, final float pBlue, final float pAlpha) {
729-
this.mSpriteBatchVertexBufferObject.addWithPackedColor(pTextureRegion, pX1, pY1, pX2, pY2, pX3, pY3, pX4, pY4, Color.packABGRFloat(pRed, pGreen, pBlue, pAlpha));
729+
this.mSpriteBatchVertexBufferObject.addWithPackedColor(pTextureRegion, pX1, pY1, pX2, pY2, pX3, pY3, pX4, pY4, ColorUtils.convertRGBAToABGRPackedFloat(pRed, pGreen, pBlue, pAlpha));
730730
}
731731

732732
// ===========================================================

src/org/andengine/opengl/font/Font.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,22 @@ public class Font implements IFont {
6565
// ===========================================================
6666

6767
public Font(final FontManager pFontManager, final ITexture pTexture, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final Color pColor) {
68+
this(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColor.getARGBPackedInt());
69+
}
70+
71+
public Font(final FontManager pFontManager, final ITexture pTexture, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColorARGBPackedInt) {
6872
this.mFontManager = pFontManager;
6973
this.mTexture = pTexture;
7074
this.mTextureWidth = pTexture.getWidth();
7175
this.mTextureHeight = pTexture.getHeight();
7276

7377
this.mBackgroundPaint = new Paint();
74-
this.mBackgroundPaint.setColor(Color.TRANSPARENT);
78+
this.mBackgroundPaint.setColor(Color.TRANSPARENT_ARGB_PACKED_INT);
7579
this.mBackgroundPaint.setStyle(Style.FILL);
7680

7781
this.mPaint = new Paint();
7882
this.mPaint.setTypeface(pTypeface);
79-
this.mPaint.setColor(pColor);
83+
this.mPaint.setColor(pColorARGBPackedInt);
8084
this.mPaint.setTextSize(pSize);
8185
this.mPaint.setAntiAlias(pAntiAlias);
8286

@@ -254,7 +258,7 @@ public synchronized void update(final GLState pGLState) {
254258
this.mTexture.bind(pGLState);
255259
final PixelFormat pixelFormat = this.mTexture.getPixelFormat();
256260

257-
final boolean preMultipyAlpha = this.mTexture.getTextureOptions().mPreMultipyAlpha;
261+
final boolean preMultipyAlpha = this.mTexture.getTextureOptions().mPreMultiplyAlpha;
258262
for(int i = lettersPendingToBeDrawnToTexture.size() - 1; i >= 0; i--) {
259263
final Letter letter = lettersPendingToBeDrawnToTexture.get(i);
260264
if(!letter.isWhitespace()) {

src/org/andengine/opengl/font/FontFactory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import org.andengine.opengl.texture.TextureOptions;
66
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
77
import org.andengine.opengl.texture.bitmap.BitmapTexture.BitmapTextureFormat;
8+
import org.andengine.util.color.Color;
89

910
import android.content.res.AssetManager;
10-
import android.graphics.Color;
1111
import android.graphics.Typeface;
1212

1313
/**
@@ -23,7 +23,7 @@ public class FontFactory {
2323
// ===========================================================
2424

2525
private static final boolean ANTIALIAS_DEFAULT = true;
26-
private static final int COLOR_DEFAULT = Color.BLACK;
26+
private static final int COLOR_DEFAULT = Color.BLACK_ARGB_PACKED_INT;
2727

2828
// ===========================================================
2929
// Fields

src/org/andengine/opengl/font/StrokeFont.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.andengine.opengl.font;
22

33
import org.andengine.opengl.texture.ITexture;
4+
import org.andengine.util.color.Color;
45

56
import android.graphics.Paint;
67
import android.graphics.Paint.Style;
@@ -31,21 +32,29 @@ public class StrokeFont extends Font {
3132
// ===========================================================
3233
// Constructors
3334
// ===========================================================
35+
36+
public StrokeFont(final FontManager pFontManager, final ITexture pTexture, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final Color pColor, final float pStrokeWidth, final Color pStrokeColor) {
37+
this(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColor.getARGBPackedInt(), pStrokeWidth, pStrokeColor.getARGBPackedInt());
38+
}
39+
40+
public StrokeFont(final FontManager pFontManager, final ITexture pTexture, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColorARGBPackedInt, final float pStrokeWidth, final int pStrokeColorARGBPackedInt) {
41+
this(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColorARGBPackedInt, pStrokeWidth, pStrokeColorARGBPackedInt, false);
42+
}
3443

35-
public StrokeFont(final FontManager pFontManager, final ITexture pTexture, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor) {
36-
this(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor, false);
44+
public StrokeFont(final FontManager pFontManager, final ITexture pTexture, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final Color pColor, final float pStrokeWidth, final Color pStrokeColor, final boolean pStrokeOnly) {
45+
this(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColor.getARGBPackedInt(), pStrokeWidth, pStrokeColor.getARGBPackedInt(), pStrokeOnly);
3746
}
3847

39-
public StrokeFont(final FontManager pFontManager, final ITexture pTexture, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColor, final float pStrokeWidth, final int pStrokeColor, final boolean pStrokeOnly) {
40-
super(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColor);
48+
public StrokeFont(final FontManager pFontManager, final ITexture pTexture, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColorARGBPackedInt, final float pStrokeWidth, final int pStrokeColorARGBPackedInt, final boolean pStrokeOnly) {
49+
super(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColorARGBPackedInt);
4150

4251
this.mStrokeWidth = pStrokeWidth;
4352

4453
this.mStrokePaint = new Paint();
4554
this.mStrokePaint.setTypeface(pTypeface);
4655
this.mStrokePaint.setStyle(Style.STROKE);
4756
this.mStrokePaint.setStrokeWidth(pStrokeWidth);
48-
this.mStrokePaint.setColor(pStrokeColor);
57+
this.mStrokePaint.setColor(pStrokeColorARGBPackedInt);
4958
this.mStrokePaint.setTextSize(pSize);
5059
this.mStrokePaint.setAntiAlias(pAntiAlias);
5160

src/org/andengine/opengl/texture/TextureOptions.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class TextureOptions {
4040
public final int mMinFilter;
4141
public final float mWrapT;
4242
public final float mWrapS;
43-
public final boolean mPreMultipyAlpha;
43+
public final boolean mPreMultiplyAlpha;
4444

4545
// ===========================================================
4646
// Constructors
@@ -51,7 +51,7 @@ public TextureOptions(final int pMinFilter, final int pMagFilter, final int pWra
5151
this.mMagFilter = pMagFilter;
5252
this.mWrapT = pWrapT;
5353
this.mWrapS = pWrapS;
54-
this.mPreMultipyAlpha = pPreMultiplyAlpha;
54+
this.mPreMultiplyAlpha = pPreMultiplyAlpha;
5555
}
5656

5757
// ===========================================================

src/org/andengine/opengl/texture/atlas/bitmap/BitmapTextureAtlas.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected void writeTextureToHardware(final GLState pGLState) {
140140

141141
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, glInternalFormat, this.mWidth, this.mHeight, 0, glFormat, glType, null);
142142

143-
final boolean preMultipyAlpha = this.mTextureOptions.mPreMultipyAlpha;
143+
final boolean preMultipyAlpha = this.mTextureOptions.mPreMultiplyAlpha;
144144
/* Non alpha premultiplied bitmaps are loaded with ARGB_8888 and converted down manually. */
145145
final Config bitmapConfig = (preMultipyAlpha) ? this.mBitmapTextureFormat.getBitmapConfig() : Config.ARGB_8888;
146146

src/org/andengine/opengl/texture/atlas/bitmap/source/decorator/ColorKeyBitmapTextureAtlasSourceDecorator.java

+22-7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import org.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource;
44
import org.andengine.opengl.texture.atlas.bitmap.source.decorator.shape.IBitmapTextureAtlasSourceDecoratorShape;
5-
6-
import android.graphics.Color;
5+
import org.andengine.util.color.Color;
76

87
/**
98
* (c) 2010 Nicolas Gramlich
@@ -25,25 +24,41 @@ public class ColorKeyBitmapTextureAtlasSourceDecorator extends ColorSwapBitmapTe
2524
// Constructors
2625
// ===========================================================
2726

28-
public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor) {
27+
public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final Color pColorKeyColor) {
2928
super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, Color.TRANSPARENT);
3029
}
3130

32-
public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
31+
public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor) {
32+
super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, Color.TRANSPARENT_ARGB_PACKED_INT);
33+
}
34+
35+
public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final Color pColorKeyColor, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
3336
super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, Color.TRANSPARENT, pTextureAtlasSourceDecoratorOptions);
3437
}
38+
39+
public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
40+
super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, Color.TRANSPARENT_ARGB_PACKED_INT, pTextureAtlasSourceDecoratorOptions);
41+
}
3542

43+
public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final Color pColorKeyColor, final int pTolerance) {
44+
super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, pTolerance, Color.TRANSPARENT);
45+
}
46+
3647
public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor, final int pTolerance) {
37-
super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, Color.TRANSPARENT, pTolerance);
48+
super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, pTolerance, Color.TRANSPARENT_ARGB_PACKED_INT);
3849
}
3950

40-
public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor, final int pTolerance, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
51+
public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final Color pColorKeyColor, final int pTolerance, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
4152
super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, pTolerance, Color.TRANSPARENT, pTextureAtlasSourceDecoratorOptions);
4253
}
54+
55+
public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor, final int pTolerance, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
56+
super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, pTolerance, Color.TRANSPARENT_ARGB_PACKED_INT, pTextureAtlasSourceDecoratorOptions);
57+
}
4358

4459
@Override
4560
public ColorKeyBitmapTextureAtlasSourceDecorator deepCopy() {
46-
return new ColorKeyBitmapTextureAtlasSourceDecorator(this.mBitmapTextureAtlasSource, this.mBitmapTextureAtlasSourceDecoratorShape, this.mColorKeyColor, this.mTolerance, this.mTextureAtlasSourceDecoratorOptions);
61+
return new ColorKeyBitmapTextureAtlasSourceDecorator(this.mBitmapTextureAtlasSource, this.mBitmapTextureAtlasSourceDecoratorShape, this.mColorKeyColorARGBPackedInt, this.mTolerance, this.mTextureAtlasSourceDecoratorOptions);
4762
}
4863

4964
// ===========================================================

0 commit comments

Comments
 (0)