More clean up.

--HG--
branch : dev
This commit is contained in:
Martí­n Lucas Golini
2017-03-18 04:38:37 -03:00
parent 4bfd40b7b9
commit b00b6908ea
8 changed files with 69 additions and 80 deletions

View File

@@ -22,23 +22,25 @@ class EE_API Drawable {
const Uint8& getAlpha();
void setColorFilter( Color color );
void setColor( const ColorA& color );
const Color& getColorFilter();
const ColorA& getColor() const;
void setColorFilter( const ColorA& color );
Color getColorFilter();
void clearColor();
void clearColorFilter();
void resetAlpha();
protected:
Color mColorFilter;
Uint8 mAlpha;
ColorA mColor;
virtual void onAlphaChange();
virtual void onColorFilterChange();
ColorA getColorFilterAlpha();
};
}}

View File

@@ -124,18 +124,6 @@ class EE_API Sprite : public Drawable {
/** Set the animation paused or not */
void setAnimationPaused( const bool& Pause );
/** Set the sprite color */
void setColor( const ColorA& color);
/** @return The sprite color */
const ColorA& getColor() const;
/** Set the sprite Color Alpha */
void setAlpha( const Uint8& alpha );
/** @return The sprite Color Alpha */
const Uint8& getAlpha() const;
/** Set the Current Frame */
void setCurrentFrame( unsigned int CurFrame );
@@ -359,7 +347,6 @@ class EE_API Sprite : public Drawable {
Vector2f mScale;
Float mAnimSpeed;
ColorA mColor;
ColorA * mVertexColors;
int mRepetitions; //!< Number of repetions of the animation, default -1 that equals to loop.

View File

@@ -4,6 +4,10 @@
#include <eepp/ui/base.hpp>
#include <eepp/ui/uiskin.hpp>
namespace EE { namespace Graphics {
class Drawable;
}}
namespace EE { namespace UI {
class EE_API UISkinSimple : public UISkin {
@@ -26,7 +30,7 @@ class EE_API UISkinSimple : public UISkin {
Sizei getBorderSize( const Uint32 & state );
protected:
SubTexture * mSubTexture[ UISkinState::StateCount ];
Drawable * mDrawable[ UISkinState::StateCount ];
ColorA mTempColor;
void stateNormalToState( const Uint32& State );

View File

@@ -3,54 +3,70 @@
namespace EE { namespace Graphics {
Drawable::Drawable() :
mColorFilter(Color::White),
mAlpha(255)
mColor(Color::White)
{}
void Drawable::setAlpha( Uint8 alpha ) {
if ( mAlpha != alpha ) {
mAlpha = alpha;
if ( mColor.a != alpha ) {
mColor.a = alpha;
onAlphaChange();
}
}
const Uint8& Drawable::getAlpha() {
return mAlpha;
return mColor.a;
}
void Drawable::setColorFilter( Color color ) {
if ( mColorFilter != color ) {
mColorFilter = color;
void Drawable::setColor(const ColorA & color) {
mColor = color;
onColorFilterChange();
onAlphaChange();
}
const ColorA& Drawable::getColor() const {
return mColor;
}
void Drawable::setColorFilter( const ColorA& color ) {
if ( mColor.r != color.r || mColor.g != color.g || mColor.b != color.b ) {
mColor.r = color.r;
mColor.g = color.g;
mColor.b = color.b;
onColorFilterChange();
}
}
const Color& Drawable::getColorFilter() {
return mColorFilter;
Color Drawable::getColorFilter() {
return Color( mColor.r, mColor.g, mColor.b );
}
void Drawable::clearColor() {
if ( mColor != ColorA::White ) {
mColor = ColorA::White;
onColorFilterChange();
onAlphaChange();
}
}
void Drawable::clearColorFilter() {
if ( mColorFilter != Color::White ) {
mColorFilter = Color::White;
if ( mColor.r != 255 || mColor.g != 255 || mColor.b != 255 ) {
mColor.r = mColor.g = mColor.b = 255;
onColorFilterChange();
}
}
void Drawable::resetAlpha() {
if ( mAlpha != 255 ) {
mAlpha = 255;
if ( mColor.a != 255 ) {
mColor.a = 255;
onAlphaChange();
}
}
ColorA Drawable::getColorFilterAlpha() {
return ColorA( mColorFilter.r, mColorFilter.g, mColorFilter.b, mAlpha );
}
void Drawable::onAlphaChange() {
}

View File

@@ -16,7 +16,6 @@ Sprite::Sprite() :
mRotation( 0.f ),
mScale( 1.f, 1.f ),
mAnimSpeed( 16.f ),
mColor( 255,255,255,255 ),
mVertexColors( NULL ),
mRepetitions( -1 ),
mBlend( ALPHA_NORMAL ),
@@ -37,7 +36,6 @@ Sprite::Sprite( const std::string& name, const std::string& extension, TextureAt
mRotation( 0.f ),
mScale( 1.f, 1.f ),
mAnimSpeed( 16.f ),
mColor( 255,255,255,255 ),
mVertexColors( NULL ),
mRepetitions( -1 ),
mBlend( ALPHA_NORMAL ),
@@ -59,7 +57,6 @@ Sprite::Sprite( SubTexture * SubTexture ) :
mRotation( 0.f ),
mScale( 1.f, 1.f ),
mAnimSpeed( 16.f ),
mColor( 255,255,255,255 ),
mVertexColors( NULL ),
mRepetitions( -1 ),
mBlend( ALPHA_NORMAL ),
@@ -81,7 +78,6 @@ Sprite::Sprite( const Uint32& TexId, const Sizef &DestSize, const Vector2i &Offs
mRotation( 0.f ),
mScale( 1.f, 1.f ),
mAnimSpeed( 16.f ),
mColor( 255,255,255,255 ),
mVertexColors( NULL ),
mRepetitions( -1 ),
mBlend( ALPHA_NORMAL ),
@@ -618,9 +614,9 @@ void Sprite::draw( const Vector2f& position, const Sizef& size ) {
}
if ( NULL == mVertexColors )
S->draw( position.x, position.y, getColorFilterAlpha(), mRotation, mScale, mBlend, mEffect, mOrigin );
S->draw( position.x, position.y, getColor(), mRotation, mScale, mBlend, mEffect, mOrigin );
else
S->draw( position.x, position.y, mRotation, mScale, getColorFilterAlpha(), getColorFilterAlpha(), getColorFilterAlpha(), getColorFilterAlpha(), mBlend, mEffect, mOrigin );
S->draw( position.x, position.y, mRotation, mScale, getColor(), getColor(), getColor(), getColor(), mBlend, mEffect, mOrigin );
if ( size != Sizef::Zero ) {
S->setDestSize( oldSize );
@@ -780,22 +776,6 @@ void Sprite::setAnimationPaused( const bool& Pause ) {
}
}
void Sprite::setColor( const ColorA& Color) {
mColor = Color;
}
const ColorA& Sprite::getColor() const {
return mColor;
}
void Sprite::setAlpha( const Uint8& Alpha ) {
mColor.a = Alpha;
}
const Uint8& Sprite::getAlpha() const {
return mColor.a;
}
const unsigned int& Sprite::getCurrentFrame() const {
return mCurrentFrame;
}

View File

@@ -168,13 +168,13 @@ void SubTexture::draw( const Quad2f Q, const Vector2f& Offset, const Float& Angl
}
void SubTexture::draw( const Vector2f& position ) {
draw( position.x, position.y, ColorA( mColorFilter.r, mColorFilter.g, mColorFilter.b, mAlpha ) );
draw( position.x, position.y, getColor() );
}
void SubTexture::draw( const Vector2f & position, const Sizef& size ) {
Sizef oldSize( mDestSize );
mDestSize = size;
draw( position.x, position.y, getColorFilterAlpha() );
draw( position.x, position.y, getColor() );
mDestSize = oldSize;
}

View File

@@ -739,5 +739,5 @@ void EE::Graphics::Texture::draw( const Vector2f & position ) {
}
void EE::Graphics::Texture::draw(const Vector2f & position, const Sizef & size) {
drawFast( position.x, position.y, 0, Vector2f::One, mColorFilter, ALPHA_NORMAL, size.x, size.y );
drawFast( position.x, position.y, 0, Vector2f::One, mColor, ALPHA_NORMAL, size.x, size.y );
}

View File

@@ -1,5 +1,6 @@
#include <eepp/ui/uiskinsimple.hpp>
#include <eepp/graphics/textureatlasmanager.hpp>
#include <eepp/graphics/drawable.hpp>
namespace EE { namespace UI {
@@ -7,7 +8,7 @@ UISkinSimple::UISkinSimple( const std::string& Name ) :
UISkin( Name, SkinSimple )
{
for ( Int32 i = 0; i < UISkinState::StateCount; i++ )
mSubTexture[ i ] = NULL;
mDrawable[ i ] = NULL;
setSkins();
}
@@ -19,19 +20,17 @@ void UISkinSimple::draw( const Float& X, const Float& Y, const Float& Width, con
if ( 0 == Alpha )
return;
SubTexture * tSubTexture = mSubTexture[ State ];
mTempColor = mColor[ State ];
if ( NULL != tSubTexture ) {
tSubTexture->setDestSize( Sizef( Width, Height ) );
Drawable * tDrawable = mDrawable[ State ];
mTempColor = mColor[ State ];
if ( NULL != tDrawable ) {
if ( mTempColor.a != Alpha ) {
mTempColor.a = (Uint8)( (Float)mTempColor.a * ( (Float)Alpha / 255.f ) );
}
tSubTexture->draw( X, Y, mTempColor );
tSubTexture->resetDestSize();
tDrawable->setColor( mTempColor );
tDrawable->draw( Vector2f( X, Y ), Sizef( Width, Height ) );
tDrawable->clearColor();
}
}
@@ -40,16 +39,16 @@ void UISkinSimple::setSkin( const Uint32& State ) {
std::string Name( mName + "_" + UISkin::getSkinStateName( State ) );
mSubTexture[ State ] = TextureAtlasManager::instance()->getSubTextureByName( Name );
mDrawable[ State ] = TextureAtlasManager::instance()->getSubTextureByName( Name );
}
bool UISkinSimple::stateExists( const Uint32 & state ) {
return NULL != mSubTexture[ state ];
return NULL != mDrawable[ state ];
}
void UISkinSimple::stateNormalToState( const Uint32& State ) {
if ( NULL == mSubTexture[ State ] )
mSubTexture[ State ] = mSubTexture[ UISkinState::StateNormal ];
if ( NULL == mDrawable[ State ] )
mDrawable[ State ] = mDrawable[ UISkinState::StateNormal ];
}
UISkinSimple * UISkinSimple::clone( const std::string& NewName, const bool& CopyColorsState ) {
@@ -61,7 +60,7 @@ UISkinSimple * UISkinSimple::clone( const std::string& NewName, const bool& Copy
memcpy( &SkinS->mColor[0], &mColor[0], UISkinState::StateCount * sizeof(ColorA) );
}
memcpy( &SkinS->mSubTexture[0], &mSubTexture[0], UISkinState::StateCount * sizeof(SubTexture*) );
memcpy( &SkinS->mDrawable[0], &mDrawable[0], UISkinState::StateCount * sizeof(SubTexture*) );
return SkinS;
}
@@ -71,8 +70,9 @@ UISkin * UISkinSimple::clone() {
}
Sizei UISkinSimple::getSize( const Uint32 & state ) {
if ( NULL != mSubTexture[ state ] ) {
return mSubTexture[ state ]->getDpSize();
if ( NULL != mDrawable[ state ] ) {
Sizef s( mDrawable[ state ]->getSize() );
return Sizei( (Int32)s.x, (Int32)s.y );
}
return Sizei();