Permalink
Browse files

Extracted color calculation/conversion methods from Color to ColorUti…

…ls. Removed all references to android.graphics.color. Changes around classes that used a ARGB color packed as int (coming from android.graphics.color).
  • Loading branch information...
1 parent 6dbfd36 commit 76992d7184c58ffedf73d7955ef9660c5880a4e0 Nicolas Gramlich committed Feb 16, 2012
@@ -1,12 +1,13 @@
package org.andengine.entity.scene.background.modifier;
import org.andengine.entity.scene.background.IBackground;
+import org.andengine.util.color.Color;
import org.andengine.util.modifier.BaseTripleValueSpanModifier;
import org.andengine.util.modifier.ease.EaseLinear;
import org.andengine.util.modifier.ease.IEaseFunction;
/**
- * (c) 2010 Nicolas Gramlich
+ * (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
@@ -25,18 +26,34 @@
// Constructors
// ===========================================================
+ public ColorBackgroundModifier(final float pDuration, final Color pFromColor, final Color pToColor) {
+ this(pDuration, pFromColor.getRed(), pToColor.getRed(), pFromColor.getGreen(), pToColor.getGreen(), pFromColor.getBlue(), pToColor.getBlue(), null, EaseLinear.getInstance());
+ }
+
public ColorBackgroundModifier(final float pDuration, final float pFromRed, final float pToRed, final float pFromGreen, final float pToGreen, final float pFromBlue, final float pToBlue) {
this(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, null, EaseLinear.getInstance());
}
+ public ColorBackgroundModifier(final float pDuration, final Color pFromColor, final Color pToColor, final IEaseFunction pEaseFunction) {
+ this(pDuration, pFromColor.getRed(), pToColor.getRed(), pFromColor.getGreen(), pToColor.getGreen(), pFromColor.getBlue(), pToColor.getBlue(), null, pEaseFunction);
+ }
+
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) {
this(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, null, pEaseFunction);
}
+ public ColorBackgroundModifier(final float pDuration, final Color pFromColor, final Color pToColor, final IBackgroundModifierListener pBackgroundModifierListener) {
+ super(pDuration, pFromColor.getRed(), pToColor.getRed(), pFromColor.getGreen(), pToColor.getGreen(), pFromColor.getBlue(), pToColor.getBlue(), pBackgroundModifierListener, EaseLinear.getInstance());
+ }
+
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) {
super(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, pBackgroundModifierListener, EaseLinear.getInstance());
}
+ public ColorBackgroundModifier(final float pDuration, final Color pFromColor, final Color pToColor, final IBackgroundModifierListener pBackgroundModifierListener, final IEaseFunction pEaseFunction) {
+ super(pDuration, pFromColor.getRed(), pToColor.getRed(), pFromColor.getGreen(), pToColor.getGreen(), pFromColor.getBlue(), pToColor.getBlue(), pBackgroundModifierListener, pEaseFunction);
+ }
+
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) {
super(pDuration, pFromRed, pToRed, pFromGreen, pToGreen, pFromBlue, pToBlue, pBackgroundModifierListener, pEaseFunction);
}
@@ -146,7 +146,7 @@ protected void initBlendFunction(final ITexture pTexture) {
}
protected void initBlendFunction(final TextureOptions pTextureOptions) {
- if(pTextureOptions.mPreMultipyAlpha) {
+ if(pTextureOptions.mPreMultiplyAlpha) {
this.setBlendFunction(IShape.BLENDFUNCTION_SOURCE_PREMULTIPLYALPHA_DEFAULT, IShape.BLENDFUNCTION_DESTINATION_PREMULTIPLYALPHA_DEFAULT);
}
}
@@ -15,12 +15,12 @@
import org.andengine.opengl.vbo.HighPerformanceVertexBufferObject;
import org.andengine.opengl.vbo.IVertexBufferObject;
import org.andengine.opengl.vbo.LowMemoryVertexBufferObject;
-import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.opengl.vbo.VertexBufferObject.DrawType;
+import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributes;
import org.andengine.opengl.vbo.attribute.VertexBufferObjectAttributesBuilder;
import org.andengine.util.adt.transformation.Transformation;
-import org.andengine.util.color.Color;
+import org.andengine.util.color.ColorUtils;
import android.opengl.GLES20;
@@ -717,7 +717,7 @@ protected void addWithPackedColor(final ITextureRegion pTextureRegion, final flo
* +-2
*/
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) {
- this.mSpriteBatchVertexBufferObject.addWithPackedColor(pTextureRegion, pX1, pY1, pX2, pY2, Color.packABGRFloat(pRed, pGreen, pBlue, pAlpha));
+ this.mSpriteBatchVertexBufferObject.addWithPackedColor(pTextureRegion, pX1, pY1, pX2, pY2, ColorUtils.convertRGBAToABGRPackedFloat(pRed, pGreen, pBlue, pAlpha));
}
/**
@@ -726,7 +726,7 @@ private void addInner(final ITextureRegion pTextureRegion, final float pX1, fina
* 2-4
*/
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) {
- this.mSpriteBatchVertexBufferObject.addWithPackedColor(pTextureRegion, pX1, pY1, pX2, pY2, pX3, pY3, pX4, pY4, Color.packABGRFloat(pRed, pGreen, pBlue, pAlpha));
+ this.mSpriteBatchVertexBufferObject.addWithPackedColor(pTextureRegion, pX1, pY1, pX2, pY2, pX3, pY3, pX4, pY4, ColorUtils.convertRGBAToABGRPackedFloat(pRed, pGreen, pBlue, pAlpha));
}
// ===========================================================
@@ -65,18 +65,22 @@
// ===========================================================
public Font(final FontManager pFontManager, final ITexture pTexture, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final Color pColor) {
+ this(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColor.getARGBPackedInt());
+ }
+
+ public Font(final FontManager pFontManager, final ITexture pTexture, final Typeface pTypeface, final float pSize, final boolean pAntiAlias, final int pColorARGBPackedInt) {
this.mFontManager = pFontManager;
this.mTexture = pTexture;
this.mTextureWidth = pTexture.getWidth();
this.mTextureHeight = pTexture.getHeight();
this.mBackgroundPaint = new Paint();
- this.mBackgroundPaint.setColor(Color.TRANSPARENT);
+ this.mBackgroundPaint.setColor(Color.TRANSPARENT_ARGB_PACKED_INT);
this.mBackgroundPaint.setStyle(Style.FILL);
this.mPaint = new Paint();
this.mPaint.setTypeface(pTypeface);
- this.mPaint.setColor(pColor);
+ this.mPaint.setColor(pColorARGBPackedInt);
this.mPaint.setTextSize(pSize);
this.mPaint.setAntiAlias(pAntiAlias);
@@ -254,7 +258,7 @@ public synchronized void update(final GLState pGLState) {
this.mTexture.bind(pGLState);
final PixelFormat pixelFormat = this.mTexture.getPixelFormat();
- final boolean preMultipyAlpha = this.mTexture.getTextureOptions().mPreMultipyAlpha;
+ final boolean preMultipyAlpha = this.mTexture.getTextureOptions().mPreMultiplyAlpha;
for(int i = lettersPendingToBeDrawnToTexture.size() - 1; i >= 0; i--) {
final Letter letter = lettersPendingToBeDrawnToTexture.get(i);
if(!letter.isWhitespace()) {
@@ -5,9 +5,9 @@
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.bitmap.BitmapTexture.BitmapTextureFormat;
+import org.andengine.util.color.Color;
import android.content.res.AssetManager;
-import android.graphics.Color;
import android.graphics.Typeface;
/**
@@ -23,7 +23,7 @@
// ===========================================================
private static final boolean ANTIALIAS_DEFAULT = true;
- private static final int COLOR_DEFAULT = Color.BLACK;
+ private static final int COLOR_DEFAULT = Color.BLACK_ARGB_PACKED_INT;
// ===========================================================
// Fields
@@ -1,6 +1,7 @@
package org.andengine.opengl.font;
import org.andengine.opengl.texture.ITexture;
+import org.andengine.util.color.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
@@ -31,21 +32,29 @@
// ===========================================================
// Constructors
// ===========================================================
+
+ 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) {
+ this(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColor.getARGBPackedInt(), pStrokeWidth, pStrokeColor.getARGBPackedInt());
+ }
+
+ 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) {
+ this(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColorARGBPackedInt, pStrokeWidth, pStrokeColorARGBPackedInt, false);
+ }
- 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) {
- this(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColor, pStrokeWidth, pStrokeColor, false);
+ 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) {
+ this(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColor.getARGBPackedInt(), pStrokeWidth, pStrokeColor.getARGBPackedInt(), pStrokeOnly);
}
- 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) {
- super(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColor);
+ 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) {
+ super(pFontManager, pTexture, pTypeface, pSize, pAntiAlias, pColorARGBPackedInt);
this.mStrokeWidth = pStrokeWidth;
this.mStrokePaint = new Paint();
this.mStrokePaint.setTypeface(pTypeface);
this.mStrokePaint.setStyle(Style.STROKE);
this.mStrokePaint.setStrokeWidth(pStrokeWidth);
- this.mStrokePaint.setColor(pStrokeColor);
+ this.mStrokePaint.setColor(pStrokeColorARGBPackedInt);
this.mStrokePaint.setTextSize(pSize);
this.mStrokePaint.setAntiAlias(pAntiAlias);
@@ -40,7 +40,7 @@
public final int mMinFilter;
public final float mWrapT;
public final float mWrapS;
- public final boolean mPreMultipyAlpha;
+ public final boolean mPreMultiplyAlpha;
// ===========================================================
// Constructors
@@ -51,7 +51,7 @@ public TextureOptions(final int pMinFilter, final int pMagFilter, final int pWra
this.mMagFilter = pMagFilter;
this.mWrapT = pWrapT;
this.mWrapS = pWrapS;
- this.mPreMultipyAlpha = pPreMultiplyAlpha;
+ this.mPreMultiplyAlpha = pPreMultiplyAlpha;
}
// ===========================================================
@@ -140,7 +140,7 @@ protected void writeTextureToHardware(final GLState pGLState) {
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, glInternalFormat, this.mWidth, this.mHeight, 0, glFormat, glType, null);
- final boolean preMultipyAlpha = this.mTextureOptions.mPreMultipyAlpha;
+ final boolean preMultipyAlpha = this.mTextureOptions.mPreMultiplyAlpha;
/* Non alpha premultiplied bitmaps are loaded with ARGB_8888 and converted down manually. */
final Config bitmapConfig = (preMultipyAlpha) ? this.mBitmapTextureFormat.getBitmapConfig() : Config.ARGB_8888;
@@ -2,8 +2,7 @@
import org.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource;
import org.andengine.opengl.texture.atlas.bitmap.source.decorator.shape.IBitmapTextureAtlasSourceDecoratorShape;
-
-import android.graphics.Color;
+import org.andengine.util.color.Color;
/**
* (c) 2010 Nicolas Gramlich
@@ -25,25 +24,41 @@
// Constructors
// ===========================================================
- public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor) {
+ public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final Color pColorKeyColor) {
super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, Color.TRANSPARENT);
}
- public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
+ public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor) {
+ super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, Color.TRANSPARENT_ARGB_PACKED_INT);
+ }
+
+ public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final Color pColorKeyColor, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, Color.TRANSPARENT, pTextureAtlasSourceDecoratorOptions);
}
+
+ public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
+ super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, Color.TRANSPARENT_ARGB_PACKED_INT, pTextureAtlasSourceDecoratorOptions);
+ }
+ public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final Color pColorKeyColor, final int pTolerance) {
+ super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, pTolerance, Color.TRANSPARENT);
+ }
+
public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor, final int pTolerance) {
- super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, Color.TRANSPARENT, pTolerance);
+ super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, pTolerance, Color.TRANSPARENT_ARGB_PACKED_INT);
}
- public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor, final int pTolerance, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
+ public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final Color pColorKeyColor, final int pTolerance, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, pTolerance, Color.TRANSPARENT, pTextureAtlasSourceDecoratorOptions);
}
+
+ public ColorKeyBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int pColorKeyColor, final int pTolerance, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
+ super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pColorKeyColor, pTolerance, Color.TRANSPARENT_ARGB_PACKED_INT, pTextureAtlasSourceDecoratorOptions);
+ }
@Override
public ColorKeyBitmapTextureAtlasSourceDecorator deepCopy() {
- return new ColorKeyBitmapTextureAtlasSourceDecorator(this.mBitmapTextureAtlasSource, this.mBitmapTextureAtlasSourceDecoratorShape, this.mColorKeyColor, this.mTolerance, this.mTextureAtlasSourceDecoratorOptions);
+ return new ColorKeyBitmapTextureAtlasSourceDecorator(this.mBitmapTextureAtlasSource, this.mBitmapTextureAtlasSourceDecoratorShape, this.mColorKeyColorARGBPackedInt, this.mTolerance, this.mTextureAtlasSourceDecoratorOptions);
}
// ===========================================================
Oops, something went wrong.

0 comments on commit 76992d7

Please sign in to comment.