diff --git a/include/eepp/gaming/base.hpp b/include/eepp/gaming/base.hpp index 846420bed..758d7a7c7 100644 --- a/include/eepp/gaming/base.hpp +++ b/include/eepp/gaming/base.hpp @@ -9,7 +9,7 @@ using namespace EE::Math; #include -#include +#include #include #include #include diff --git a/include/eepp/graphics/base.hpp b/include/eepp/graphics/base.hpp index 9572e410e..ee844b72a 100644 --- a/include/eepp/graphics/base.hpp +++ b/include/eepp/graphics/base.hpp @@ -9,7 +9,7 @@ #include using namespace EE::Math; -#include +#include #include #include #include diff --git a/include/eepp/graphics/console.hpp b/include/eepp/graphics/console.hpp index e1eec8d4c..d3368cb67 100755 --- a/include/eepp/graphics/console.hpp +++ b/include/eepp/graphics/console.hpp @@ -40,7 +40,7 @@ class EE_API Console : protected LogReaderInterface { Uint32 getBackgroundTextureId() const { return mTexId; } /** Set the Console Background Color */ - void setBackgroundColor( const ColorA& BackColor ) { mConColor = BackColor; mMaxAlpha = mConColor.a(); } + void setBackgroundColor( const ColorA& BackColor ) { mConColor = BackColor; mMaxAlpha = mConColor.a; } void setCharacterSize( const Uint32& characterSize ); diff --git a/include/eepp/graphics/drawable.hpp b/include/eepp/graphics/drawable.hpp new file mode 100644 index 000000000..72adc0a36 --- /dev/null +++ b/include/eepp/graphics/drawable.hpp @@ -0,0 +1,46 @@ +#ifndef EE_GRAPHICS_DRAWABLE_HPP +#define EE_GRAPHICS_DRAWABLE_HPP + +#include +#include +using namespace EE::Math; +using namespace EE::System; + +namespace EE { namespace Graphics { + +class EE_API Drawable { + public: + Drawable(); + + virtual Sizef getSize() = 0; + + virtual void draw( const Vector2f& position ) = 0; + + virtual void draw( const Vector2f& position, const Sizef& size ) = 0; + + void setAlpha( Uint8 alpha ); + + const Uint8& getAlpha(); + + void setColorFilter( Color color ); + + const Color& getColorFilter(); + + void clearColorFilter(); + + void resetAlpha(); + + protected: + Color mColorFilter; + Uint8 mAlpha; + + virtual void onAlphaChange(); + + virtual void onColorFilterChange(); + + ColorA getColorFilterAlpha(); +}; + +}} + +#endif diff --git a/include/eepp/graphics/fontstyleconfig.hpp b/include/eepp/graphics/fontstyleconfig.hpp index edab88623..b269d5aea 100644 --- a/include/eepp/graphics/fontstyleconfig.hpp +++ b/include/eepp/graphics/fontstyleconfig.hpp @@ -2,7 +2,7 @@ #define EE_GRAPHICS_FONTSTYLECONFIG_HPP #include -#include +#include using namespace EE::System; namespace EE { namespace Graphics { diff --git a/include/eepp/graphics/image.hpp b/include/eepp/graphics/image.hpp index d923bfce8..4ca7d0e49 100644 --- a/include/eepp/graphics/image.hpp +++ b/include/eepp/graphics/image.hpp @@ -7,7 +7,7 @@ #include using namespace EE::Math; -#include +#include using namespace EE::System; #include diff --git a/include/eepp/graphics/particle.hpp b/include/eepp/graphics/particle.hpp index 2f7102399..2b809ebbe 100755 --- a/include/eepp/graphics/particle.hpp +++ b/include/eepp/graphics/particle.hpp @@ -16,10 +16,10 @@ class EE_API Particle{ const ColorAf& getColor() const { return mColor; } - Float r() { return mColor.r(); } - Float g() { return mColor.g(); } - Float b() { return mColor.b(); } - Float a() { return mColor.a(); } + Float r() { return mColor.r; } + Float g() { return mColor.g; } + Float b() { return mColor.b; } + Float a() { return mColor.a; } void reset(const Float &x, const Float &y, const Float &xspeed, const Float &yspeed, const Float &xacc, const Float &yacc, const Float size = 16); diff --git a/include/eepp/graphics/sprite.hpp b/include/eepp/graphics/sprite.hpp index fcb4f40dd..eff543fe4 100755 --- a/include/eepp/graphics/sprite.hpp +++ b/include/eepp/graphics/sprite.hpp @@ -9,7 +9,7 @@ namespace EE { namespace Graphics { /** @brief A Sprite controller class, can hold and control sprites animations. */ -class EE_API Sprite { +class EE_API Sprite : public Drawable { public: /// Event ID - Sprite - User Data typedef cb::Callback3< void, Uint32, Sprite *, void * > SpriteCallback; @@ -267,15 +267,9 @@ class EE_API Sprite { */ void draw( const EE_BLEND_MODE& Blend, const EE_RENDER_MODE& Effect ); - /** Draw the sprite to the screen forcing the Blend Mode - * @param Blend The Blend Mode - */ - void draw( const EE_BLEND_MODE& Blend ); + void draw(const Vector2f & position); - /** Draw the sprite to the screen forcing the Render Type - * @param Effect The Render Type - */ - void draw( const EE_RENDER_MODE& Effect ); + void draw(const Vector2f & position, const Sizef & size); /** Set the number of repetitions of the animation. Any number below 0 the animation will loop. */ void setRepetitions( const int& Repeations ); diff --git a/include/eepp/graphics/subtexture.hpp b/include/eepp/graphics/subtexture.hpp index 0ba821670..0437ed7a3 100644 --- a/include/eepp/graphics/subtexture.hpp +++ b/include/eepp/graphics/subtexture.hpp @@ -4,11 +4,12 @@ #include #include #include +#include namespace EE { namespace Graphics { /** @brief A SubTexture is a part of a texture that represent an sprite.*/ -class EE_API SubTexture { +class EE_API SubTexture : public Drawable { public: /** Creates an empty SubTexture */ SubTexture(); @@ -86,6 +87,10 @@ class EE_API SubTexture { void draw( const Quad2f Q, const Vector2f& offset = Vector2f(), const Float& Angle = 0.f, const Vector2f& Scale = Vector2f::One, const ColorA& Color0 = ColorA(), const ColorA& Color1 = ColorA(), const ColorA& Color2 = ColorA(), const ColorA& Color3 = ColorA(), const EE_BLEND_MODE& Blend = ALPHA_NORMAL ); + virtual void draw( const Vector2f& position ); + + virtual void draw(const Vector2f& position, const Sizef & size ); + /** @return The texture instance used by the SubTexture. */ Graphics::Texture * getTexture(); @@ -132,7 +137,7 @@ class EE_API SubTexture { Sizei getRealSize(); /** @return This is the same as Destination Size but with the values rounded as integers. */ - Sizei getSize(); + Sizef getSize(); /** @return A pixel pointer to the texture loaded in memory ( downloaded from VRAM doing Lock()/Unlock() ). */ const Uint8* getPixelsPtr(); @@ -157,7 +162,7 @@ class EE_API SubTexture { void setOriDestSize(const Sizef & oriDestSize); protected: Uint8 * mPixels; - Uint8 * mAlpha; + Uint8 * mAlphaMask; std::string mName; Uint32 mId; Uint32 mTexId; diff --git a/include/eepp/graphics/texture.hpp b/include/eepp/graphics/texture.hpp index 9b77001ec..60e2c718a 100755 --- a/include/eepp/graphics/texture.hpp +++ b/include/eepp/graphics/texture.hpp @@ -3,13 +3,14 @@ #include #include +#include #include #include #include namespace EE { namespace Graphics { -class EE_API Texture : public Image, private NonCopyable { +class EE_API Texture : public Image, public Drawable, private NonCopyable { public: static Uint32 getMaximumSize(); @@ -215,6 +216,14 @@ class EE_API Texture : public Image, private NonCopyable { */ void drawQuadEx( Quad2f Q, const Vector2f& Offset = Vector2f(), const Float &Angle = 0.0f, const Vector2f &scale = Vector2f::One, const ColorA& Color0 = ColorA(255,255,255,255), const ColorA& Color1 = ColorA(255,255,255,255), const ColorA& Color2 = ColorA(255,255,255,255), const ColorA& Color3 = ColorA(255,255,255,255), const EE_BLEND_MODE &Blend = ALPHA_NORMAL, Recti texSector = Recti(0,0,0,0) ); + Sizef getSize(); + + Sizei getPixelSize(); + + void draw(const Vector2f & position); + + void draw(const Vector2f & position, const Sizef & size); + /** Set the texture factory internal id of the texture */ void setId( const Uint32& id ); diff --git a/include/eepp/physics/base.hpp b/include/eepp/physics/base.hpp index 357bcddb8..dc1274017 100644 --- a/include/eepp/physics/base.hpp +++ b/include/eepp/physics/base.hpp @@ -11,7 +11,7 @@ using namespace EE::Math; #include -#include +#include #include using namespace EE::System; diff --git a/include/eepp/system.hpp b/include/eepp/system.hpp index e55249d33..b24b6e252 100644 --- a/include/eepp/system.hpp +++ b/include/eepp/system.hpp @@ -1,7 +1,7 @@ #ifndef EEPP_SYSTEM_HPP #define EEPP_SYSTEM_HPP -#include +#include #include #include #include diff --git a/include/eepp/system/color.hpp b/include/eepp/system/color.hpp new file mode 100755 index 000000000..665116eb8 --- /dev/null +++ b/include/eepp/system/color.hpp @@ -0,0 +1,254 @@ +#ifndef EE_SYSTEMCCOLORS_H +#define EE_SYSTEMCCOLORS_H + +#include +#include +#include + +namespace EE { namespace System { + +/** @brief Template class for a RGB color */ +template +class tColor { + public: + T r; + T g; + T b; + + tColor() : + r(255), + g(255), + b(255) + { + } + + /** Creates an RGB color from each component. + ** @param r Red component + ** @param g Green component + ** @param b Blue component + */ + tColor(T r, T g, T b) : + r(r), + g(g), + b(b) + { + } + + /** From 32 bits value with RGB(A) byte order */ + tColor( Uint32 Col ) + { + Col = BitOp::swapLE32( Col ); + r = static_cast( Col >> 16 ); + g = static_cast( Col >> 8 ); + b = static_cast( Col >> 0 ); + } + + bool operator==( const tColor& Col ) { + return ( r == Col.r && g == Col.g && b == Col.b ); + } + + bool operator!=( const tColor& Col ) { + return !( r == Col.r && g == Col.g && b == Col.b ); + } +}; + +/** @brief Template class for a RGBA color */ +template +class tColorA { + public: + union { + Uint32 Value; + + struct + { + T r; + T g; + T b; + T a; //! Alpha color component ( transparency ) + }; + }; + + tColorA() : + r(255), + g(255), + b(255), + a(255) + { + } + + /** Creates an RGBA color from each component. + ** @param r Red component + ** @param g Green component + ** @param b Blue component + ** @param a Alpha component + */ + tColorA(T r, T g, T b, T a) : + r(r), + g(g), + b(b), + a(a) + { + } + + /** @brief Creates a RGBA color from a RGB color, the Alpha component is set as non-transparent. */ + tColorA( const tColor& Col ) : + r( Col.r ), + g( Col.g ), + b( Col.b ), + a( 255 ) + { + } + + /** @brief Creates a RGBA color from a RGB color. + ** @param Col The RGB color + ** @param a The Alpha component value + */ + tColorA( const tColor& Col, T a ) : + r( Col.r ), + g( Col.g ), + b( Col.b ), + a( a ) + { + } + + tColorA( const tColorA& Col ) : + Value( Col.Value ) + { + } + + /** From a 32 bits value with RGBA byte order */ + tColorA( const Uint32& Col ) : + Value( BitOp::swapBE32( Col ) ) + { + } + + //! @return The color represented as an Uint32 ( as 0xAABBGGRR for Little Endian ) + Uint32 getValue() const { + return Value; + } + + /** @brief Assign the RGBA colors, from each component. */ + void assign( T r, T g, T b, T a ) { + this->r = r; this->g = g; this->b = b; this->a = a; + } + + /** @brief Assign the color value from other RGBA color. */ + void assign( const tColorA& Col ) { + Value = Col.Value; + } + + bool operator==( const tColorA& Col ) const { + return ( r == Col.r && g == Col.g && b == Col.b && a == Col.a ); + } + + bool operator!=( const tColorA& Col ) const { + return !(*this == Col); + } + + tColorA operator+( const tColorA& Col ) const { + return tColorA( eemin( this->r + Col.r , 255 ), + eemin( this->g + Col.g , 255 ), + eemin( this->b + Col.b , 255 ), + eemin( this->a + Col.a , 255 ) + ); + } + + tColorA operator-( const tColorA& Col ) const { + return tColorA( eemax( this->r - Col.r , 0 ), + eemax( this->g - Col.g , 0 ), + eemax( this->b - Col.b , 0 ), + eemax( this->a - Col.a , 0 ) + ); + } + + tColorA operator*( const tColorA& Col ) const { + return tColorA( ( this->r * Col.r / 255 ), + ( this->g * Col.g / 255 ), + ( this->b * Col.b / 255 ), + ( this->a * Col.a / 255 ) + ); + } + + tColor toColor() { + return tColor( r, g, b ); + } +}; + +class EE_API ColorA : public tColorA +{ + public: + ColorA(); + + ColorA( Uint8 r, Uint8 g, Uint8 b, Uint8 a ); + + ColorA( const tColor& Col ); + + ColorA( const tColor& Col, Uint8 a ); + + ColorA( const tColorA& Col ); + + ColorA( const Uint32& Col ); + + static ColorA colorFromPointer( void *ptr ); + + static ColorA fromString( const char * str ); + + static ColorA fromString( const std::string& str ); + + static const ColorA Transparent; + static const ColorA White; + static const ColorA Black; +}; + +typedef tColor Colorf; +typedef tColorA ColorAf; +typedef tColorA ColorAff; + +//! @brief Small class to help in some color operations +class EE_API Color : public tColor { +public: + Color(); + + /** Creates an RGB color from each component. + ** @param r Red component + ** @param g Green component + ** @param b Blue component + */ + Color(Uint8 r, Uint8 g, Uint8 b); + + Color( const tColor& color ); + + Color( Uint32 Col ); + + /** Blend a source color to destination color */ + static ColorAf blend( ColorAf srcf, ColorAf dstf ); + + /** Blend a source color to destination color */ + static ColorA blend( ColorA src, ColorA dst ); + + static const Color White; + static const Color Black; + static const Color Red; + static const Color Green; + static const Color Blue; + static const Color Yellow; + static const Color Cyan; + static const Color Magenta; + static const Color Silver; + static const Color Gray; + static const Color Maroon; + static const Color Olive; + static const Color OfficeGreen; + static const Color Purple; + static const Color Teal; + static const Color Navy; +}; + +typedef Color RGB; +typedef Colorf RGBf; +typedef ColorA RGBA; +typedef ColorAf RGBAf; + +}} + +#endif diff --git a/include/eepp/system/colors.hpp b/include/eepp/system/colors.hpp deleted file mode 100755 index cb7c5fc3d..000000000 --- a/include/eepp/system/colors.hpp +++ /dev/null @@ -1,324 +0,0 @@ -#ifndef EE_SYSTEMCCOLORS_H -#define EE_SYSTEMCCOLORS_H - -#include -#include -#include -#include - -namespace EE { namespace System { - -/** @brief Template class for a RGB color */ -template -class tColor { - public: - T Red; - T Green; - T Blue; - - tColor() : - Red(255), - Green(255), - Blue(255) - { - } - - /** Creates an RGB color from each component. - ** @param r Red component - ** @param g Green component - ** @param b Blue component - */ - tColor(T r, T g, T b) : - Red(r), - Green(g), - Blue(b) - { - } - - /** From 32 bits value with RGB(A) byte order */ - tColor( Uint32 Col ) - { - Col = BitOp::swapLE32( Col ); - Red = static_cast( Col >> 16 ); - Green = static_cast( Col >> 8 ); - Blue = static_cast( Col >> 0 ); - } - - T r() const { return Red; } //! @return the Red component - T g() const { return Green; } //! @return the Green component - T b() const { return Blue; } //! @return the Blue component - - bool operator==(tColor& Col) { - return ( Red == Col.r() && Green == Col.g() && Blue == Col.b() ); - } - - bool operator!=(tColor& Col) { - return !( Red == Col.r() && Green == Col.g() && Blue == Col.b() ); - } -}; - -/** @brief Template class for a RGBA color */ -template -class tColorA { - public: - static const tColorA Transparent; ///< Transparent predefined color - static const tColorA Black; ///< Black predefined color - - union { - Uint32 Value; - - struct - { - T Red; - T Green; - T Blue; - T Alpha; //! Alpha color component ( transparency ) - }; - }; - - tColorA() : - Red(255), - Green(255), - Blue(255), - Alpha(255) - { - } - - /** Creates an RGBA color from each component. - ** @param r Red component - ** @param g Green component - ** @param b Blue component - ** @param a Alpha component - */ - tColorA(T r, T g, T b, T a) : - Red(r), - Green(g), - Blue(b), - Alpha(a) - { - } - - /** @brief Creates a RGBA color from a RGB color, the Alpha component is set as non-transparent. */ - tColorA( const tColor& Col ) : - Red( Col.Red ), - Green( Col.Green ), - Blue( Col.Blue ), - Alpha( 255 ) - { - } - - /** @brief Creates a RGBA color from a RGB color. - ** @param Col The RGB color - ** @param a The Alpha component value - */ - tColorA( const tColor& Col, T a ) : - Red( Col.Red ), - Green( Col.Green ), - Blue( Col.Blue ), - Alpha( a ) - { - } - - tColorA( const tColorA& Col ) : - Value( Col.Value ) - { - } - - /** From a 32 bits value with RGBA byte order */ - tColorA( const Uint32& Col ) : - Value( BitOp::swapBE32( Col ) ) - { - } - - T r() const { return Red; } //! @return the Red component - T g() const { return Green; } //! @return the Green component - T b() const { return Blue; } //! @return the Blue component - T a() const { return Alpha; } //! @return the Alpha component - - //! @return The color represented as an Uint32 ( as 0xAABBGGRR for Little Endian ) - Uint32 getValue() const { - return Value; - } - - /** @brief Assign the RGBA colors, from each component. */ - void assign( T r, T g, T b, T a ) { - Red = r; Green = g; Blue = b; Alpha = a; - } - - /** @brief Assign the color value from other RGBA color. */ - void assign( const tColorA& Col ) { - Value = Col.Value; - } - - bool operator==( const tColorA& Col ) const { - return ( Red == Col.Red && Green == Col.Green && Blue == Col.Blue && Alpha == Col.Alpha ); - } - - bool operator!=( const tColorA& Col ) const { - return !(*this == Col); - } - - tColorA operator+( const tColorA& Col ) const { - return tColorA( eemin( this->Red + Col.Red , 255 ), - eemin( this->Green + Col.Green , 255 ), - eemin( this->Blue + Col.Blue , 255 ), - eemin( this->Alpha + Col.Alpha , 255 ) - ); - } - - tColorA operator-( const tColorA& Col ) const { - return tColorA( eemax( this->Red - Col.Red , 0 ), - eemax( this->Green - Col.Green , 0 ), - eemax( this->Blue - Col.Blue , 0 ), - eemax( this->Alpha - Col.Alpha , 0 ) - ); - } - - tColorA operator*( const tColorA& Col ) const { - return tColorA( ( this->Red * Col.Red / 255 ), - ( this->Green * Col.Green / 255 ), - ( this->Blue * Col.Blue / 255 ), - ( this->Alpha * Col.Alpha / 255 ) - ); - } - - tColor toColor() { - return tColor( Red, Green, Blue ); - } -}; - -template -const tColorA tColorA::Transparent = tColorA(0,0,0,0); - -template -const tColorA tColorA::Black = tColorA(0,0,0,255); - -class tColorAI : public tColorA -{ - public: - tColorAI() : - tColorA() - {} - - tColorAI(Uint8 r, Uint8 g, Uint8 b, Uint8 a) : - tColorA(r,g,b,a) - {} - - tColorAI( const tColor& Col ) : - tColorA( Col ) - {} - - tColorAI( const tColor& Col, Uint8 a ) : - tColorA( Col, a ) - {} - - tColorAI( const tColorA& Col ) : - tColorA( Col.Value ) - {} - - tColorAI( const Uint32& Col ) : - tColorA( Col ) - {} - - static inline tColorAI colorFromPointer(void *ptr) { - unsigned long val = (long)ptr; - - // hash the pointer up nicely - val = (val+0x7ed55d16) + (val<<12); - val = (val^0xc761c23c) ^ (val>>19); - val = (val+0x165667b1) + (val<<5); - val = (val+0xd3a2646c) ^ (val<<9); - val = (val+0xfd7046c5) + (val<<3); - val = (val^0xb55a4f09) ^ (val>>16); - - unsigned char r = (val>>0) & 0xFF; - unsigned char g = (val>>8) & 0xFF; - unsigned char b = (val>>16) & 0xFF; - - unsigned char max = r>g ? (r>b ? r : b) : (g>b ? g : b); - - const int mult = 127; - const int add = 63; - r = (r*mult)/max + add; - g = (g*mult)/max + add; - b = (b*mult)/max + add; - - return tColorAI(r, g, b, 255); - } - - static inline tColorAI fromString( const char * str ) { - return tColorAI( std::strtoul( str, NULL, 16 ) ); - } - - static inline tColorAI fromString( const std::string& str ) { - return tColorAI( std::strtoul( str.c_str(), NULL, 16 ) ); - } -}; - -typedef tColor Colorf; -typedef tColorAI ColorA; -typedef tColorA ColorAf; -typedef tColorA ColorAff; - -//! @brief Small class to help in some color operations -class Color : public tColor { -public: - Color() : tColor() - { - } - - /** Creates an RGB color from each component. - ** @param r Red component - ** @param g Green component - ** @param b Blue component - */ - Color(Uint8 r, Uint8 g, Uint8 b) : tColor( r, g, b ) - { - } - - Color( const tColor& color ) : - tColor( color.Red, color.Green, color.Blue ) - { - } - - Color( Uint32 Col ) - { - Col = BitOp::swapLE32( Col ); - Red = static_cast( Col >> 16 ); - Green = static_cast( Col >> 8 ); - Blue = static_cast( Col >> 0 ); - } - - /** Blend a source color to destination color */ - static inline ColorAf blend( ColorAf srcf, ColorAf dstf ) { - Float alpha = srcf.Alpha + dstf.Alpha * ( 1.f - srcf.Alpha ); - Float red = ( srcf.Red * srcf.Alpha + dstf.Red * dstf.Alpha * ( 1.f - srcf.Alpha ) ) / alpha; - Float green = ( srcf.Green * srcf.Alpha + dstf.Green * dstf.Alpha * ( 1.f - srcf.Alpha ) ) / alpha; - Float blue = ( srcf.Blue * srcf.Alpha + dstf.Blue * dstf.Alpha * ( 1.f - srcf.Alpha ) ) / alpha; - - return ColorAf( red, green, blue, alpha ); - } - - #define EE_COLOR_BLEND_FTOU8(color) (Uint8)( color == 1.f ? 255 : (color * 255.99f)) - - /** Blend a source color to destination color */ - static inline ColorA blend( ColorA src, ColorA dst ) { - ColorAf srcf( (Float)src.Red / 255.f, (Float)src.Green / 255.f, (Float)src.Blue / 255.f, (Float)src.Alpha / 255.f ); - ColorAf dstf( (Float)dst.Red / 255.f, (Float)dst.Green / 255.f, (Float)dst.Blue / 255.f, (Float)dst.Alpha / 255.f ); - Float alpha = srcf.Alpha + dstf.Alpha * ( 1.f - srcf.Alpha ); - Float red = ( srcf.Red * srcf.Alpha + dstf.Red * dstf.Alpha * ( 1.f - srcf.Alpha ) ) / alpha; - Float green = ( srcf.Green * srcf.Alpha + dstf.Green * dstf.Alpha * ( 1.f - srcf.Alpha ) ) / alpha; - Float blue = ( srcf.Blue * srcf.Alpha + dstf.Blue * dstf.Alpha * ( 1.f - srcf.Alpha ) ) / alpha; - - return ColorA( EE_COLOR_BLEND_FTOU8(red), EE_COLOR_BLEND_FTOU8(green), EE_COLOR_BLEND_FTOU8(blue), EE_COLOR_BLEND_FTOU8(alpha) ); - } -}; - -typedef Color RGB; -typedef Colorf RGBf; -typedef ColorA RGBA; -typedef ColorAf RGBAf; - -}} - -#endif diff --git a/include/eepp/ui/base.hpp b/include/eepp/ui/base.hpp index bd2c0b941..95d5729af 100644 --- a/include/eepp/ui/base.hpp +++ b/include/eepp/ui/base.hpp @@ -14,7 +14,7 @@ using namespace EE::Math; #include -#include +#include #include #include using namespace EE::System; diff --git a/include/eepp/window/base.hpp b/include/eepp/window/base.hpp index 08a8ab47b..6bdfb6b48 100644 --- a/include/eepp/window/base.hpp +++ b/include/eepp/window/base.hpp @@ -7,7 +7,7 @@ #include using namespace EE::Math; -#include +#include #include #include #include diff --git a/projects/linux/ee.files b/projects/linux/ee.files index f7846b839..da58fe27b 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -1,3 +1,4 @@ +../../include/eepp/graphics/drawable.hpp ../../include/eepp/graphics/font.hpp ../../include/eepp/graphics/fontstyleconfig.hpp ../../include/eepp/graphics/fonttruetype.hpp @@ -5,6 +6,7 @@ ../../include/eepp/graphics/text.hpp ../../include/eepp/math/interpolation1d.hpp ../../include/eepp/math/interpolation2d.hpp +../../include/eepp/system/color.hpp ../../include/eepp/system/translator.hpp ../../include/eepp/ui/uidragablecontrol.hpp ../../include/eepp/ui/uiimage.hpp @@ -18,6 +20,7 @@ ../../include/eepp/ui/uithemedefault.hpp ../../include/eepp/ui/uiwidget.hpp ../../src/eepp/gaming/mapobjectlayer.cpp +../../src/eepp/graphics/drawable.cpp ../../src/eepp/graphics/fonttruetype.cpp ../../src/eepp/graphics/fonttruetypeloader.cpp ../../src/eepp/graphics/globalbatchrenderer.cpp @@ -26,6 +29,7 @@ ../../src/eepp/graphics/text.cpp ../../src/eepp/math/interpolation1d.cpp ../../src/eepp/math/interpolation2d.cpp +../../src/eepp/system/color.cpp ../../src/eepp/system/translator.cpp ../../src/eepp/ui/uidragablecontrol.cpp ../../src/eepp/ui/uihelper.cpp @@ -361,7 +365,6 @@ ee.includes ../../include/eepp/math/ease.hpp ../../include/eepp/math/easing.hpp ../../include/eepp/math/perlinnoise.hpp -../../include/eepp/system/colors.hpp ../../src/eepp/system/safedatapointer.cpp ../../src/eepp/math/easing.cpp ../../src/eepp/math/perlinnoise.cpp diff --git a/src/eepp/gaming/gameobjectvirtual.cpp b/src/eepp/gaming/gameobjectvirtual.cpp index 00936ec47..f6a15c0e2 100644 --- a/src/eepp/gaming/gameobjectvirtual.cpp +++ b/src/eepp/gaming/gameobjectvirtual.cpp @@ -47,7 +47,7 @@ Uint32 GameObjectVirtual::getRealType() const { Sizei GameObjectVirtual::getSize() { if ( NULL != mSubTexture ) - return mSubTexture->getSize(); + return Sizei( (Int32)mSubTexture->getDestSize().x, (Int32)mSubTexture->getDestSize().y ); if ( NULL != mLayer ) return mLayer->getMap()->getTileSize(); @@ -104,7 +104,7 @@ void GameObjectVirtual::draw() { Primitives P; ColorA C( mDataId ); - C.Alpha = 255; + C.a = 255; P.setColor( C ); diff --git a/src/eepp/gaming/mapeditor/mapeditor.cpp b/src/eepp/gaming/mapeditor/mapeditor.cpp index 8f1e7867b..ad40021e8 100644 --- a/src/eepp/gaming/mapeditor/mapeditor.cpp +++ b/src/eepp/gaming/mapeditor/mapeditor.cpp @@ -567,9 +567,9 @@ void MapEditor::onLightRadiusChange( MapLight * Light ) { void MapEditor::onLightSelect( MapLight * Light ) { ColorA Col( Light->getColor() ); - mUIRedSlider->setValue( Col.r() ); - mUIGreenSlider->setValue( Col.g() ); - mUIBlueSlider->setValue( Col.b() ); + mUIRedSlider->setValue( Col.r ); + mUIGreenSlider->setValue( Col.g ); + mUIBlueSlider->setValue( Col.b ); mLightRadius->setValue( Light->getRadius() ); mLightTypeChk->setActive( Light->getType() == LIGHT_ISOMETRIC ? true : false ); } @@ -585,39 +585,39 @@ void MapEditor::onNewLight( const UIEvent * Event ) { void MapEditor::onRedChange( const UIEvent * Event ) { ColorA Col = mUIBaseColor->getBackground()->getColor(); - Col.Red = (Uint8)mUIRedSlider->getValue(); + Col.r = (Uint8)mUIRedSlider->getValue(); mUIBaseColor->getBackground()->setColor( Col ); mUIRedTxt->setText( String::toStr( (Int32)mUIRedSlider->getValue() ) ); if ( NULL != mUIMap->getSelectedLight() ) { RGB lCol( mUIMap->getSelectedLight()->getColor() ); - lCol.Red = Col.r(); + lCol.r = Col.r; mUIMap->getSelectedLight()->setColor( lCol ); } } void MapEditor::onGreenChange( const UIEvent * Event ) { ColorA Col = mUIBaseColor->getBackground()->getColor(); - Col.Green = (Uint8)mUIGreenSlider->getValue(); + Col.g = (Uint8)mUIGreenSlider->getValue(); mUIBaseColor->getBackground()->setColor( Col ); mUIGreenTxt->setText( String::toStr( (Uint32)mUIGreenSlider->getValue() ) ); if ( NULL != mUIMap->getSelectedLight() ) { RGB lCol( mUIMap->getSelectedLight()->getColor() ); - lCol.Green = Col.g(); + lCol.g = Col.g; mUIMap->getSelectedLight()->setColor( lCol ); } } void MapEditor::onBlueChange( const UIEvent * Event ) { ColorA Col = mUIBaseColor->getBackground()->getColor(); - Col.Blue = (Uint8)mUIBlueSlider->getValue(); + Col.b = (Uint8)mUIBlueSlider->getValue(); mUIBaseColor->getBackground()->setColor( Col ); mUIBlueTxt->setText( String::toStr( (Uint32)mUIBlueSlider->getValue() ) ); if ( NULL != mUIMap->getSelectedLight() ) { RGB lCol( mUIMap->getSelectedLight()->getColor() ); - lCol.Blue = Col.b(); + lCol.b = Col.b; mUIMap->getSelectedLight()->setColor( lCol ); } } diff --git a/src/eepp/gaming/mapeditor/tilemapproperties.cpp b/src/eepp/gaming/mapeditor/tilemapproperties.cpp index 3dae3c267..c9afa08f6 100644 --- a/src/eepp/gaming/mapeditor/tilemapproperties.cpp +++ b/src/eepp/gaming/mapeditor/tilemapproperties.cpp @@ -52,29 +52,29 @@ TileMapProperties::TileMapProperties( TileMap * Map ) : mUIRedSlider = UISlider::New()->setOrientation( UI_HORIZONTAL ); mUIRedSlider->setParent( mUIWindow->getContainer() )->setSize( 255, 20 )->setPosition( Txt->getPosition().x + Txt->getSize().getWidth() + 16, Txt->getPosition().y ); mUIRedSlider->setMaxValue( 255 ); - mUIRedSlider->setValue( mMap->getBaseColor().r() ); + mUIRedSlider->setValue( mMap->getBaseColor().r ); mUIRedSlider->addEventListener( UIEvent::EventOnValueChange, cb::Make1( this, &TileMapProperties::onRedChange ) ); - mUIRedTxt = createTextBox( String::toStr( (Uint32)mMap->getBaseColor().r() ), mUIWindow->getContainer(), Sizei(), Vector2i( mUIRedSlider->getPosition().x + mUIRedSlider->getSize().getWidth() + 4, mUIRedSlider->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE, Text::Shadow ); + mUIRedTxt = createTextBox( String::toStr( (Uint32)mMap->getBaseColor().r ), mUIWindow->getContainer(), Sizei(), Vector2i( mUIRedSlider->getPosition().x + mUIRedSlider->getSize().getWidth() + 4, mUIRedSlider->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE, Text::Shadow ); Txt = createTextBox( "Green Color:", mUIWindow->getContainer(), Sizei(), Vector2i( mUIBaseColor->getPosition().x + mUIBaseColor->getSize().getWidth() + 4, mUIRedSlider->getPosition().y + mUIRedSlider->getSize().getHeight() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE, Text::Shadow ); mUIGreenSlider = UISlider::New()->setOrientation( UI_HORIZONTAL ); mUIGreenSlider->setParent( mUIWindow->getContainer() )->setSize( 255, 20 )->setPosition( mUIRedSlider->getPosition().x, Txt->getPosition().y ); mUIGreenSlider->setMaxValue( 255 ); - mUIGreenSlider->setValue( mMap->getBaseColor().g() ); + mUIGreenSlider->setValue( mMap->getBaseColor().g ); mUIGreenSlider->addEventListener( UIEvent::EventOnValueChange, cb::Make1( this, &TileMapProperties::onGreenChange ) ); - mUIGreenTxt = createTextBox( String::toStr( (Uint32)mMap->getBaseColor().g() ), mUIWindow->getContainer(), Sizei(), Vector2i( mUIGreenSlider->getPosition().x + mUIGreenSlider->getSize().getWidth() + 4, mUIGreenSlider->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE, Text::Shadow ); + mUIGreenTxt = createTextBox( String::toStr( (Uint32)mMap->getBaseColor().g ), mUIWindow->getContainer(), Sizei(), Vector2i( mUIGreenSlider->getPosition().x + mUIGreenSlider->getSize().getWidth() + 4, mUIGreenSlider->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE, Text::Shadow ); Txt = createTextBox( "Blue Color:", mUIWindow->getContainer(), Sizei(), Vector2i( mUIBaseColor->getPosition().x + mUIBaseColor->getSize().getWidth() + 4, mUIGreenSlider->getPosition().y + mUIGreenSlider->getSize().getHeight() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE, Text::Shadow ); mUIBlueSlider = UISlider::New()->setOrientation( UI_HORIZONTAL ); mUIBlueSlider->setParent( mUIWindow->getContainer() )->setSize( 255, 20 )->setPosition( mUIRedSlider->getPosition().x, Txt->getPosition().y ); mUIBlueSlider->setMaxValue( 255 ); - mUIBlueSlider->setValue( mMap->getBaseColor().b() ); + mUIBlueSlider->setValue( mMap->getBaseColor().b ); mUIBlueSlider->addEventListener( UIEvent::EventOnValueChange, cb::Make1( this, &TileMapProperties::onBlueChange ) ); - mUIBlueTxt = createTextBox( String::toStr( (Uint32)mMap->getBaseColor().b() ), mUIWindow->getContainer(), Sizei(), Vector2i( mUIBlueSlider->getPosition().x + mUIBlueSlider->getSize().getWidth() + 4, mUIBlueSlider->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE, Text::Shadow ); + mUIBlueTxt = createTextBox( String::toStr( (Uint32)mMap->getBaseColor().b ), mUIWindow->getContainer(), Sizei(), Vector2i( mUIBlueSlider->getPosition().x + mUIBlueSlider->getSize().getWidth() + 4, mUIBlueSlider->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE, Text::Shadow ); } Uint32 TxtBoxFlags = UI_CONTROL_DEFAULT_FLAGS | UI_HALIGN_CENTER | UI_VALIGN_CENTER; @@ -140,34 +140,34 @@ TileMapProperties::~TileMapProperties() { void TileMapProperties::onRedChange( const UIEvent * Event ) { ColorA Col = mUIBaseColor->getBackground()->getColor(); - Col.Red = (Uint8)mUIRedSlider->getValue(); + Col.r = (Uint8)mUIRedSlider->getValue(); mUIBaseColor->getBackground()->setColor( Col ); mUIRedTxt->setText( String::toStr( (Int32)mUIRedSlider->getValue() ) ); ColorA MapCol = mMap->getBaseColor(); - MapCol.Red = Col.Red; + MapCol.r = Col.r; mMap->setBaseColor( MapCol ); } void TileMapProperties::onGreenChange( const UIEvent * Event ) { ColorA Col = mUIBaseColor->getBackground()->getColor(); - Col.Green = (Uint8)mUIGreenSlider->getValue(); + Col.g = (Uint8)mUIGreenSlider->getValue(); mUIBaseColor->getBackground()->setColor( Col ); mUIGreenTxt->setText( String::toStr( (Uint32)mUIGreenSlider->getValue() ) ); ColorA MapCol = mMap->getBaseColor(); - MapCol.Green = Col.Green; + MapCol.g = Col.g; mMap->setBaseColor( MapCol ); } void TileMapProperties::onBlueChange( const UIEvent * Event ) { ColorA Col = mUIBaseColor->getBackground()->getColor(); - Col.Blue = (Uint8)mUIBlueSlider->getValue(); + Col.b = (Uint8)mUIBlueSlider->getValue(); mUIBaseColor->getBackground()->setColor( Col ); mUIBlueTxt->setText( String::toStr( (Uint32)mUIBlueSlider->getValue() ) ); ColorA MapCol = mMap->getBaseColor(); - MapCol.Blue = Col.Blue; + MapCol.b = Col.b; mMap->setBaseColor( MapCol ); } diff --git a/src/eepp/gaming/mapeditor/uimapnew.cpp b/src/eepp/gaming/mapeditor/uimapnew.cpp index 4233df061..2ba301c11 100644 --- a/src/eepp/gaming/mapeditor/uimapnew.cpp +++ b/src/eepp/gaming/mapeditor/uimapnew.cpp @@ -153,7 +153,7 @@ UIMapNew::UIMapNew( UIMap * Map, cb::Callback0 NewMapCb, bool ResizeMap ) mUIRedTxt = createTextBox( String::toStr( 255 ), mUIWindow->getContainer(), Sizei(), Vector2i( mUIRedSlider->getPosition().x + mUIRedSlider->getSize().getWidth() + 4, mUIRedSlider->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE, Text::Shadow ); if ( ResizeMap ) { - mUIRedSlider->setValue( mUIMap->Map()->getBaseColor().r() ); + mUIRedSlider->setValue( mUIMap->Map()->getBaseColor().r ); } Txt = createTextBox( "Green Color:", mUIWindow->getContainer(), Sizei(), Vector2i( mUIBaseColor->getPosition().x + mUIBaseColor->getSize().getWidth() + 4, mUIRedSlider->getPosition().y + mUIRedSlider->getSize().getHeight() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE, Text::Shadow ); @@ -167,7 +167,7 @@ UIMapNew::UIMapNew( UIMap * Map, cb::Callback0 NewMapCb, bool ResizeMap ) mUIGreenTxt = createTextBox( String::toStr( 255 ), mUIWindow->getContainer(), Sizei(), Vector2i( mUIGreenSlider->getPosition().x + mUIGreenSlider->getSize().getWidth() + 4, mUIGreenSlider->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE, Text::Shadow ); if ( ResizeMap ) { - mUIGreenSlider->setValue( mUIMap->Map()->getBaseColor().g() ); + mUIGreenSlider->setValue( mUIMap->Map()->getBaseColor().g ); } Txt = createTextBox( "Blue Color:", mUIWindow->getContainer(), Sizei(), Vector2i( mUIBaseColor->getPosition().x + mUIBaseColor->getSize().getWidth() + 4, mUIGreenSlider->getPosition().y + mUIGreenSlider->getSize().getHeight() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE, Text::Shadow ); @@ -181,7 +181,7 @@ UIMapNew::UIMapNew( UIMap * Map, cb::Callback0 NewMapCb, bool ResizeMap ) mUIBlueTxt = createTextBox( String::toStr( 255 ), mUIWindow->getContainer(), Sizei(), Vector2i( mUIBlueSlider->getPosition().x + mUIBlueSlider->getSize().getWidth() + 4, mUIBlueSlider->getPosition().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE, Text::Shadow ); if ( ResizeMap ) { - mUIBlueSlider->setValue( mUIMap->Map()->getBaseColor().b() ); + mUIBlueSlider->setValue( mUIMap->Map()->getBaseColor().b ); } UIPushButton * OKButton = UIPushButton::New(); @@ -206,21 +206,21 @@ UIMapNew::~UIMapNew() { void UIMapNew::onRedChange( const UIEvent * Event ) { ColorA Col = mUIBaseColor->getBackground()->getColor(); - Col.Red = (Uint8)mUIRedSlider->getValue(); + Col.r = (Uint8)mUIRedSlider->getValue(); mUIBaseColor->getBackground()->setColor( Col ); mUIRedTxt->setText( String::toStr( (Int32)mUIRedSlider->getValue() ) ); } void UIMapNew::onGreenChange( const UIEvent * Event ) { ColorA Col = mUIBaseColor->getBackground()->getColor(); - Col.Green = (Uint8)mUIGreenSlider->getValue(); + Col.g = (Uint8)mUIGreenSlider->getValue(); mUIBaseColor->getBackground()->setColor( Col ); mUIGreenTxt->setText( String::toStr( (Uint32)mUIGreenSlider->getValue() ) ); } void UIMapNew::onBlueChange( const UIEvent * Event ) { ColorA Col = mUIBaseColor->getBackground()->getColor(); - Col.Blue = (Uint8)mUIBlueSlider->getValue(); + Col.b = (Uint8)mUIBlueSlider->getValue(); mUIBaseColor->getBackground()->setColor( Col ); mUIBlueTxt->setText( String::toStr( (Uint32)mUIBlueSlider->getValue() ) ); } diff --git a/src/eepp/gaming/maplight.cpp b/src/eepp/gaming/maplight.cpp index 22d8d7a67..0dc2b1b98 100755 --- a/src/eepp/gaming/maplight.cpp +++ b/src/eepp/gaming/maplight.cpp @@ -44,21 +44,21 @@ RGB MapLight::processVertex( const Float& PointX, const Float& PointY, const RGB Uint8 TmpColor; Float LightC; - LightC = eeabs( static_cast ( mColor.r() - BaseColor.r() ) ) / mRadius; - TmpColor = Uint8( (Float)mColor.r() - (VertexDist * LightC) ); - TmpRGB.Red = VertexColor.r() + ( TmpColor - VertexColor.r() ); + LightC = eeabs( static_cast ( mColor.r - BaseColor.r ) ) / mRadius; + TmpColor = Uint8( (Float)mColor.r - (VertexDist * LightC) ); + TmpRGB.r = VertexColor.r + ( TmpColor - VertexColor.r ); - LightC = eeabs( static_cast ( mColor.g() - BaseColor.g() ) ) / mRadius; - TmpColor = Uint8( (Float)mColor.g() - (VertexDist * LightC) ); - TmpRGB.Green = VertexColor.g() + ( TmpColor - VertexColor.g() ); + LightC = eeabs( static_cast ( mColor.g - BaseColor.g ) ) / mRadius; + TmpColor = Uint8( (Float)mColor.g - (VertexDist * LightC) ); + TmpRGB.g = VertexColor.g + ( TmpColor - VertexColor.g ); - LightC = eeabs( static_cast ( mColor.b() - BaseColor.b() ) ) / mRadius; - TmpColor = Uint8( (Float)mColor.b() - (VertexDist * LightC) ); - TmpRGB.Blue = VertexColor.b() + ( TmpColor - VertexColor.b() ); + LightC = eeabs( static_cast ( mColor.b - BaseColor.b ) ) / mRadius; + TmpColor = Uint8( (Float)mColor.b - (VertexDist * LightC) ); + TmpRGB.b = VertexColor.b + ( TmpColor - VertexColor.b ); - if ( TmpRGB.r() < VertexColor.r() ) TmpRGB.Red = VertexColor.r(); - if ( TmpRGB.g() < VertexColor.g() ) TmpRGB.Green = VertexColor.g(); - if ( TmpRGB.b() < VertexColor.b() ) TmpRGB.Blue = VertexColor.b(); + if ( TmpRGB.r < VertexColor.r ) TmpRGB.r = VertexColor.r; + if ( TmpRGB.g < VertexColor.g ) TmpRGB.g = VertexColor.g; + if ( TmpRGB.b < VertexColor.b ) TmpRGB.b = VertexColor.b; return TmpRGB; } @@ -84,21 +84,21 @@ ColorA MapLight::processVertex( const Float& PointX, const Float& PointY, const Uint8 TmpColor; Float LightC; - LightC = eeabs( static_cast ( mColor.r() - BaseColor.r() ) ) / mRadius; - TmpColor = Uint8( (Float)mColor.r() - (VertexDist * LightC) ); - TmpRGB.Red = VertexColor.r() + ( TmpColor - VertexColor.r() ); + LightC = eeabs( static_cast ( mColor.r - BaseColor.r ) ) / mRadius; + TmpColor = Uint8( (Float)mColor.r - (VertexDist * LightC) ); + TmpRGB.r = VertexColor.r + ( TmpColor - VertexColor.r ); - LightC = eeabs( static_cast ( mColor.g() - BaseColor.g() ) ) / mRadius; - TmpColor = Uint8( (Float)mColor.g() - (VertexDist * LightC) ); - TmpRGB.Green = VertexColor.g() + ( TmpColor - VertexColor.g() ); + LightC = eeabs( static_cast ( mColor.g - BaseColor.g ) ) / mRadius; + TmpColor = Uint8( (Float)mColor.g - (VertexDist * LightC) ); + TmpRGB.g = VertexColor.g + ( TmpColor - VertexColor.g ); - LightC = eeabs( static_cast ( mColor.b() - BaseColor.b() ) ) / mRadius; - TmpColor = Uint8( (Float)mColor.b() - (VertexDist * LightC) ); - TmpRGB.Blue = VertexColor.b() + ( TmpColor - VertexColor.b() ); + LightC = eeabs( static_cast ( mColor.b - BaseColor.b ) ) / mRadius; + TmpColor = Uint8( (Float)mColor.b - (VertexDist * LightC) ); + TmpRGB.b = VertexColor.b + ( TmpColor - VertexColor.b ); - if ( TmpRGB.r() < VertexColor.r() ) TmpRGB.Red = VertexColor.r(); - if ( TmpRGB.g() < VertexColor.g() ) TmpRGB.Green = VertexColor.g(); - if ( TmpRGB.b() < VertexColor.b() ) TmpRGB.Blue = VertexColor.b(); + if ( TmpRGB.r < VertexColor.r ) TmpRGB.r = VertexColor.r; + if ( TmpRGB.g < VertexColor.g ) TmpRGB.g = VertexColor.g; + if ( TmpRGB.b < VertexColor.b ) TmpRGB.b = VertexColor.b; return TmpRGB; } diff --git a/src/eepp/gaming/maplightmanager.cpp b/src/eepp/gaming/maplightmanager.cpp index 3a031f633..900d1c76d 100644 --- a/src/eepp/gaming/maplightmanager.cpp +++ b/src/eepp/gaming/maplightmanager.cpp @@ -53,9 +53,9 @@ void MapLightManager::updateByVertex() { for ( Int32 x = start.x; x < end.x; x++ ) { for ( Int32 y = start.y; y < end.y; y++ ) { if ( firstLight ) { - mTileColors[x][y][0]->Red = mTileColors[x][y][1]->Red = mTileColors[x][y][2]->Red = mTileColors[x][y][3]->Red = BaseColor.Red; - mTileColors[x][y][0]->Green = mTileColors[x][y][1]->Green = mTileColors[x][y][2]->Green = mTileColors[x][y][3]->Green = BaseColor.Green; - mTileColors[x][y][0]->Blue = mTileColors[x][y][1]->Blue = mTileColors[x][y][2]->Blue = mTileColors[x][y][3]->Blue = BaseColor.Blue; + mTileColors[x][y][0]->r = mTileColors[x][y][1]->r = mTileColors[x][y][2]->r = mTileColors[x][y][3]->r = BaseColor.r; + mTileColors[x][y][0]->g = mTileColors[x][y][1]->g = mTileColors[x][y][2]->g = mTileColors[x][y][3]->g = BaseColor.g; + mTileColors[x][y][0]->b = mTileColors[x][y][1]->b = mTileColors[x][y][2]->b = mTileColors[x][y][3]->b = BaseColor.b; } Pos.x = x * TileSize.x; @@ -106,9 +106,9 @@ void MapLightManager::updateByTile() { for ( Int32 x = start.x; x < end.x; x++ ) { for ( Int32 y = start.y; y < end.y; y++ ) { if ( firstLight ) { - mTileColors[x][y][0]->Red = BaseColor.Red; - mTileColors[x][y][0]->Green = BaseColor.Green; - mTileColors[x][y][0]->Blue = BaseColor.Blue; + mTileColors[x][y][0]->r = BaseColor.r; + mTileColors[x][y][0]->g = BaseColor.g; + mTileColors[x][y][0]->b = BaseColor.b; } Pos.x = x * TileSize.x; diff --git a/src/eepp/gaming/tilemap.cpp b/src/eepp/gaming/tilemap.cpp index 072c9a774..d25a0b8c4 100644 --- a/src/eepp/gaming/tilemap.cpp +++ b/src/eepp/gaming/tilemap.cpp @@ -220,9 +220,9 @@ void TileMap::draw() { if ( getDrawBackground() ) { Primitives P; - Uint8 Alpha = static_cast( (Float)mBackColor.a() * ( (Float)mBackAlpha / 255.f ) ); + Uint8 Alpha = static_cast( (Float)mBackColor.a * ( (Float)mBackAlpha / 255.f ) ); - P.setColor( ColorA( mBackColor.r(), mBackColor.g(), mBackColor.b(), Alpha ) ); + P.setColor( ColorA( mBackColor.r, mBackColor.g, mBackColor.b, Alpha ) ); P.drawRectangle( Rectf( Vector2f( mScreenPos.x, mScreenPos.y ), Sizef( mViewSize.x, mViewSize.y ) ), 0.f, Vector2f::One ); P.setColor( ColorA( 255, 255, 255, 255 ) ); } @@ -293,12 +293,12 @@ void TileMap::gridDraw() { ColorA TileTexCol2( *mLightManager->getTileColor( TPos, 2 ) ); ColorA TileTexCol3( *mLightManager->getTileColor( TPos, 3 ) ); - TileTexCol0.Alpha = TileTexCol1.Alpha = TileTexCol2.Alpha = TileTexCol3.Alpha = mBackAlpha; + TileTexCol0.a = TileTexCol1.a = TileTexCol2.a = TileTexCol3.a = mBackAlpha; mTileTex->drawEx( tx, ty, 0, 0, 0, Vector2f::One, TileTexCol0, TileTexCol1, TileTexCol2, TileTexCol3 ); } else { TileTexCol = *mLightManager->getTileColor( TPos ); - TileTexCol.Alpha = mBackAlpha; + TileTexCol.a = mBackAlpha; mTileTex->draw( tx, ty, 0, Vector2f::One, TileTexCol ); } diff --git a/src/eepp/graphics/console.cpp b/src/eepp/graphics/console.cpp index 3afd966aa..095fb4eaf 100755 --- a/src/eepp/graphics/console.cpp +++ b/src/eepp/graphics/console.cpp @@ -123,7 +123,7 @@ void Console::create( Font * Font, const bool& MakeDefaultCommands, const bool& mTexId = TextureId; mMaxLogLines = MaxLogLines; - mMaxAlpha = (Float)mConColor.a(); + mMaxAlpha = (Float)mConColor.a; mEnabled = true; @@ -168,17 +168,17 @@ void Console::draw() { if ( mY > 0.0f ) { if ( mTexId == 0 ) { - mPri.setColor( ColorA( mConColor.r(), mConColor.g(), mConColor.b(), static_cast(mA) ) ); + mPri.setColor( ColorA( mConColor.r, mConColor.g, mConColor.b, static_cast(mA) ) ); mPri.drawRectangle( Rectf( Vector2f( 0.0f, 0.0f ), Sizef( mWidth, mY ) ) ); } else { - ColorA C( mConColor.r(), mConColor.g(), mConColor.b(), static_cast(mA) ); + ColorA C( mConColor.r, mConColor.g, mConColor.b, static_cast(mA) ); Texture * Tex = TextureFactory::instance()->getTexture( mTexId ); if ( NULL != Tex ) Tex->drawEx( 0.0f, 0.0f, mWidth, mY, 0.0f, Vector2f::One, C, C, C, C ); } - mPri.setColor( ColorA( mConLineColor.r(), mConLineColor.g(), mConLineColor.b(), static_cast(mA) ) ); + mPri.setColor( ColorA( mConLineColor.r, mConLineColor.g, mConLineColor.b, static_cast(mA) ) ); mPri.drawRectangle( Rectf( Vector2f( 0.0f, mY ), Sizef( mWidth, PixelDensity::dpToPx( 2.0f ) ) ) ); Int32 linesInScreen = this->linesOnScreen(); @@ -202,7 +202,7 @@ void Console::draw() { Text& text = mTextCache[Pos]; text.setStyleConfig( mFontStyleConfig ); - text.setColor( ColorA ( mFontStyleConfig.Color.r(), mFontStyleConfig.Color.g(), mFontStyleConfig.Color.b(), static_cast(mA) ) ); + text.setColor( ColorA ( mFontStyleConfig.Color.r, mFontStyleConfig.Color.g, mFontStyleConfig.Color.b, static_cast(mA) ) ); text.setString( mCmdLog[i] ); text.draw( mFontSize, CurY ); @@ -214,13 +214,13 @@ void Console::draw() { Text& text = mTextCache[ mTextCache.size() - 1 ]; text.setStyleConfig( mFontStyleConfig ); - text.setColor( ColorA( mFontLineColor.r(), mFontLineColor.g(), mFontLineColor.b(), static_cast(mA) ) ); + text.setColor( ColorA( mFontLineColor.r, mFontLineColor.g, mFontLineColor.b, static_cast(mA) ) ); text.setString( "> " + mTBuf->getBuffer() ); text.draw( mFontSize, CurY ); Text& text2 = mTextCache[ mTextCache.size() - 2 ]; text2.setStyleConfig( mFontStyleConfig ); - text2.setColor( ColorA ( mFontLineColor.r(), mFontLineColor.g(), mFontLineColor.b(), static_cast(mCurAlpha) ) ); + text2.setColor( ColorA ( mFontLineColor.r, mFontLineColor.g, mFontLineColor.b, static_cast(mCurAlpha) ) ); if ( (unsigned int)mTBuf->getCursorPos() == mTBuf->getBuffer().size() ) { Uint32 width = text.getTextWidth(); diff --git a/src/eepp/graphics/drawable.cpp b/src/eepp/graphics/drawable.cpp new file mode 100644 index 000000000..5ebd19fac --- /dev/null +++ b/src/eepp/graphics/drawable.cpp @@ -0,0 +1,60 @@ +#include + +namespace EE { namespace Graphics { + +Drawable::Drawable() : + mColorFilter(Color::White), + mAlpha(255) +{} + +void Drawable::setAlpha( Uint8 alpha ) { + if ( mAlpha != alpha ) { + mAlpha = alpha; + + onAlphaChange(); + } +} + +const Uint8& Drawable::getAlpha() { + return mAlpha; +} + +void Drawable::setColorFilter( Color color ) { + if ( mColorFilter != color ) { + mColorFilter = color; + + onColorFilterChange(); + } +} + +const Color& Drawable::getColorFilter() { + return mColorFilter; +} + +void Drawable::clearColorFilter() { + if ( mColorFilter != Color::White ) { + mColorFilter = Color::White; + + onColorFilterChange(); + } +} + +void Drawable::resetAlpha() { + if ( mAlpha != 255 ) { + mAlpha = 255; + + onAlphaChange(); + } +} + +ColorA Drawable::getColorFilterAlpha() { + return ColorA( mColorFilter.r, mColorFilter.g, mColorFilter.b, mAlpha ); +} + +void Drawable::onAlphaChange() { +} + +void Drawable::onColorFilterChange() { +} + +}} diff --git a/src/eepp/graphics/fonttruetype.cpp b/src/eepp/graphics/fonttruetype.cpp index dac40b53c..882ded9fd 100644 --- a/src/eepp/graphics/fonttruetype.cpp +++ b/src/eepp/graphics/fonttruetype.cpp @@ -544,7 +544,7 @@ Recti FontTrueType::findGlyphRect(Page& page, unsigned int width, unsigned int h continue; // Check if there's enough horizontal space left in the row - if (width > page.texture->getSize().x - it->width) + if (width > page.texture->getPixelSize().x - it->width) continue; // Make sure that this new row is the best found so far @@ -559,11 +559,11 @@ Recti FontTrueType::findGlyphRect(Page& page, unsigned int width, unsigned int h // If we didn't find a matching row, create a new one (10% taller than the glyph) if (!row) { int rowHeight = height + height / 10; - while ((page.nextRow + rowHeight >= (Uint32)page.texture->getSize().y) || (width >= (Uint32)page.texture->getSize().x)) + while ((page.nextRow + rowHeight >= (Uint32)page.texture->getPixelSize().y) || (width >= (Uint32)page.texture->getPixelSize().x)) { // Not enough space: resize the texture if possible - unsigned int textureWidth = page.texture->getSize().x; - unsigned int textureHeight = page.texture->getSize().y; + unsigned int textureWidth = page.texture->getPixelSize().x; + unsigned int textureHeight = page.texture->getPixelSize().y; if ( ( textureWidth * 2 <= Texture::getMaximumSize()) && (textureHeight * 2 <= Texture::getMaximumSize() ) ) { // Make the texture 2 times bigger diff --git a/src/eepp/graphics/framebuffer.cpp b/src/eepp/graphics/framebuffer.cpp index b9de7a9dd..003b8a113 100644 --- a/src/eepp/graphics/framebuffer.cpp +++ b/src/eepp/graphics/framebuffer.cpp @@ -53,7 +53,7 @@ ColorAf FrameBuffer::getClearColor() const { } void FrameBuffer::clear() { - GLi->clearColor( mClearColor.r(), mClearColor.g(), mClearColor.b(), mClearColor.a() ); + GLi->clearColor( mClearColor.r, mClearColor.g, mClearColor.b, mClearColor.a ); GLi->clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); mWindow->setClearColor( mWindow->getClearColor() ); } diff --git a/src/eepp/graphics/image.cpp b/src/eepp/graphics/image.cpp index a7fbab915..1adf2a949 100644 --- a/src/eepp/graphics/image.cpp +++ b/src/eepp/graphics/image.cpp @@ -493,37 +493,37 @@ void Image::replaceColor( const ColorA& ColorKey, const ColorA& NewColor ) { Pos = i * mChannels; if ( 4 == mChannels ) { - if ( mPixels[ Pos ] == ColorKey.r() && mPixels[ Pos + 1 ] == ColorKey.g() && mPixels[ Pos + 2 ] == ColorKey.b() && mPixels[ Pos + 3 ] == ColorKey.a() ) { - mPixels[ Pos ] = NewColor.r(); - mPixels[ Pos + 1 ] = NewColor.g(); - mPixels[ Pos + 2 ] = NewColor.b(); - mPixels[ Pos + 3 ] = NewColor.a(); + if ( mPixels[ Pos ] == ColorKey.r && mPixels[ Pos + 1 ] == ColorKey.g && mPixels[ Pos + 2 ] == ColorKey.b && mPixels[ Pos + 3 ] == ColorKey.a ) { + mPixels[ Pos ] = NewColor.r; + mPixels[ Pos + 1 ] = NewColor.g; + mPixels[ Pos + 2 ] = NewColor.b; + mPixels[ Pos + 3 ] = NewColor.a; } } else if ( 3 == mChannels ) { - if ( mPixels[ Pos ] == ColorKey.r() && mPixels[ Pos + 1 ] == ColorKey.g() && mPixels[ Pos + 2 ] == ColorKey.b() ) { - mPixels[ Pos ] = NewColor.r(); - mPixels[ Pos + 1 ] = NewColor.g(); - mPixels[ Pos + 2 ] = NewColor.b(); + if ( mPixels[ Pos ] == ColorKey.r && mPixels[ Pos + 1 ] == ColorKey.g && mPixels[ Pos + 2 ] == ColorKey.b ) { + mPixels[ Pos ] = NewColor.r; + mPixels[ Pos + 1 ] = NewColor.g; + mPixels[ Pos + 2 ] = NewColor.b; } } else if ( 2 == mChannels ) { - if ( mPixels[ Pos ] == ColorKey.r() && mPixels[ Pos + 1 ] == ColorKey.g() ) { - mPixels[ Pos ] = NewColor.r(); - mPixels[ Pos + 1 ] = NewColor.g(); + if ( mPixels[ Pos ] == ColorKey.r && mPixels[ Pos + 1 ] == ColorKey.g ) { + mPixels[ Pos ] = NewColor.r; + mPixels[ Pos + 1 ] = NewColor.g; } } else if ( 1 == mChannels ) { - if ( mPixels[ Pos ] == ColorKey.r() ) { - mPixels[ Pos ] = NewColor.r(); + if ( mPixels[ Pos ] == ColorKey.r ) { + mPixels[ Pos ] = NewColor.r; } } } } void Image::createMaskFromColor( const ColorA& ColorKey, Uint8 Alpha ) { - replaceColor( ColorKey, ColorA( ColorKey.r(), ColorKey.g(), ColorKey.b(), Alpha ) ); + replaceColor( ColorKey, ColorA( ColorKey.r, ColorKey.g, ColorKey.b, Alpha ) ); } void Image::createMaskFromColor( const RGB& ColorKey, Uint8 Alpha ) { - createMaskFromColor( ColorA( ColorKey.r(), ColorKey.g(), ColorKey.b(), 255 ), Alpha ); + createMaskFromColor( ColorA( ColorKey.r, ColorKey.g, ColorKey.b, 255 ), Alpha ); } void Image::fillWithColor( const ColorA& Color ) { @@ -536,13 +536,13 @@ void Image::fillWithColor( const ColorA& Color ) { for ( unsigned int i = 0; i < size; i += mChannels ) { for ( z = 0; z < mChannels; z++ ) { if ( 0 == z ) - mPixels[ i + z ] = Color.r(); + mPixels[ i + z ] = Color.r; else if ( 1 == z ) - mPixels[ i + z ] = Color.g(); + mPixels[ i + z ] = Color.g; else if ( 2 == z ) - mPixels[ i + z ] = Color.b(); + mPixels[ i + z ] = Color.b; else if ( 3 == z ) - mPixels[ i + z ] = Color.a(); + mPixels[ i + z ] = Color.a; } } } diff --git a/src/eepp/graphics/particle.cpp b/src/eepp/graphics/particle.cpp index 2a6449834..f6f264de1 100755 --- a/src/eepp/graphics/particle.cpp +++ b/src/eepp/graphics/particle.cpp @@ -30,8 +30,8 @@ void Particle::update(const Float &pTime) { mY = mY + mYSpeed * pTime; mXSpeed = mXSpeed + mXAcc * pTime; mYSpeed = mYSpeed + mYAcc * pTime; - mColor.Alpha -= mAlphaDecay * pTime; - if (mColor.Alpha < 0) mColor.Alpha = 0; + mColor.a -= mAlphaDecay * pTime; + if (mColor.a < 0) mColor.a = 0; } }} diff --git a/src/eepp/graphics/pixeldensity.cpp b/src/eepp/graphics/pixeldensity.cpp index 9e8712339..9f592f260 100644 --- a/src/eepp/graphics/pixeldensity.cpp +++ b/src/eepp/graphics/pixeldensity.cpp @@ -62,7 +62,7 @@ Sizef PixelDensity::dpToPx( Sizef size ) { } Sizef PixelDensity::pxToDp( Sizef size ) { - return size * getPixelDensity(); + return size / getPixelDensity(); } Sizei PixelDensity::dpToPxI( Sizef size ) { diff --git a/src/eepp/graphics/scrollparallax.cpp b/src/eepp/graphics/scrollparallax.cpp index f306e3f2b..909de8e8a 100755 --- a/src/eepp/graphics/scrollparallax.cpp +++ b/src/eepp/graphics/scrollparallax.cpp @@ -81,7 +81,7 @@ const Vector2f& ScrollParallax::getPosition() const { } void ScrollParallax::draw() { - if ( NULL != mSubTexture && mAABB.Left != mAABB.Right && mAABB.Top != mAABB.Bottom && 0 != mColor.Alpha ) { + if ( NULL != mSubTexture && mAABB.Left != mAABB.Right && mAABB.Top != mAABB.Bottom && 0 != mColor.a ) { mPos += mSpeed * (Float)mElapsed.getElapsed().asSeconds(); if ( mPos.x > mAABB.Left + mRealSize.getWidth() || mPos.x < mAABB.Left - mRealSize.getWidth() ) diff --git a/src/eepp/graphics/sprite.cpp b/src/eepp/graphics/sprite.cpp index 548f8edae..1d7a18891 100755 --- a/src/eepp/graphics/sprite.cpp +++ b/src/eepp/graphics/sprite.cpp @@ -598,12 +598,33 @@ void Sprite::draw() { draw( mBlend, mEffect ); } -void Sprite::draw( const EE_BLEND_MODE& Blend ) { - draw( Blend, mEffect ); +void Sprite::draw( const Vector2f& position ) { + draw( position, Sizef::Zero ); } -void Sprite::draw( const EE_RENDER_MODE& Effect ) { - draw( mBlend, Effect ); +void Sprite::draw( const Vector2f& position, const Sizef& size ) { + if ( SPR_FGET( SPRITE_FLAG_AUTO_ANIM ) ) + update(); + + SubTexture * S = getCurrentSubTexture(); + + if ( S == NULL ) + return; + + Sizef oldSize = S->getDestSize(); + + if ( size != Sizef::Zero ) { + S->setDestSize( size ); + } + + if ( NULL == mVertexColors ) + S->draw( position.x, position.y, getColorFilterAlpha(), mRotation, mScale, mBlend, mEffect, mOrigin ); + else + S->draw( position.x, position.y, mRotation, mScale, getColorFilterAlpha(), getColorFilterAlpha(), getColorFilterAlpha(), getColorFilterAlpha(), mBlend, mEffect, mOrigin ); + + if ( size != Sizef::Zero ) { + S->setDestSize( oldSize ); + } } unsigned int Sprite::getFrame( const unsigned int& FrameNum ) { @@ -658,7 +679,7 @@ Sizef Sprite::setSize( const unsigned int& FrameNum, const unsigned int& SubFram } Sizef Sprite::getSize() { - return mFrames[ mCurrentFrame ].Spr[ mCurrentSubFrame ]->getDestSize(); + return mFrames[ mCurrentFrame ].Spr[ mCurrentSubFrame ]->getSize(); } void Sprite::setRepetitions( const int& Repeations ) { @@ -768,11 +789,11 @@ const ColorA& Sprite::getColor() const { } void Sprite::setAlpha( const Uint8& Alpha ) { - mColor.Alpha = Alpha; + mColor.a = Alpha; } const Uint8& Sprite::getAlpha() const { - return mColor.Alpha; + return mColor.a; } const unsigned int& Sprite::getCurrentFrame() const { diff --git a/src/eepp/graphics/subtexture.cpp b/src/eepp/graphics/subtexture.cpp index 09dccb115..dd9dbb7b7 100644 --- a/src/eepp/graphics/subtexture.cpp +++ b/src/eepp/graphics/subtexture.cpp @@ -10,7 +10,7 @@ namespace EE { namespace Graphics { SubTexture::SubTexture() : mPixels(NULL), - mAlpha(NULL), + mAlphaMask(NULL), mId(0), mTexId(0), mTexture(NULL), @@ -25,7 +25,7 @@ SubTexture::SubTexture() : SubTexture::SubTexture( const Uint32& TexId, const std::string& Name ) : mPixels(NULL), - mAlpha(NULL), + mAlphaMask(NULL), mName( Name ), mId( String::hash( mName ) ), mTexId( TexId ), @@ -41,7 +41,7 @@ SubTexture::SubTexture( const Uint32& TexId, const std::string& Name ) : SubTexture::SubTexture( const Uint32& TexId, const Recti& SrcRect, const std::string& Name ) : mPixels(NULL), - mAlpha(NULL), + mAlphaMask(NULL), mName( Name ), mId( String::hash( mName ) ), mTexId( TexId ), @@ -57,7 +57,7 @@ SubTexture::SubTexture( const Uint32& TexId, const Recti& SrcRect, const std::st SubTexture::SubTexture( const Uint32& TexId, const Recti& SrcRect, const Sizef& DestSize, const std::string& Name ) : mPixels(NULL), - mAlpha(NULL), + mAlphaMask(NULL), mName( Name ), mId( String::hash( mName ) ), mTexId( TexId ), @@ -73,7 +73,7 @@ SubTexture::SubTexture( const Uint32& TexId, const Recti& SrcRect, const Sizef& SubTexture::SubTexture( const Uint32& TexId, const Recti& SrcRect, const Sizef& DestSize, const Vector2i &Offset, const std::string& Name ) : mPixels(NULL), - mAlpha(NULL), + mAlphaMask(NULL), mName( Name ), mId( String::hash( mName ) ), mTexId( TexId ), @@ -128,7 +128,7 @@ void SubTexture::setSrcRect( const Recti& Rect ) { if ( NULL != mPixels ) cacheColors(); - if ( NULL != mAlpha ) + if ( NULL != mAlphaMask ) cacheAlphaMask(); } @@ -167,6 +167,17 @@ void SubTexture::draw( const Quad2f Q, const Vector2f& Offset, const Float& Angl mTexture->drawQuadEx( Q, Offset, Angle, Scale, Color0, Color1, Color2, Color3, Blend, mSrcRect ); } +void SubTexture::draw( const Vector2f& position ) { + draw( position.x, position.y, ColorA( mColorFilter.r, mColorFilter.g, mColorFilter.b, mAlpha ) ); +} + +void SubTexture::draw( const Vector2f & position, const Sizef& size ) { + Sizef oldSize( mDestSize ); + mDestSize = size; + draw( position.x, position.y, getColorFilterAlpha() ); + mDestSize = oldSize; +} + Graphics::Texture * SubTexture::getTexture() { return mTexture; } @@ -185,18 +196,18 @@ void SubTexture::replaceColor( ColorA ColorKey, ColorA NewColor ) { } void SubTexture::createMaskFromColor(ColorA ColorKey, Uint8 Alpha) { - replaceColor( ColorKey, ColorA( ColorKey.r(), ColorKey.g(), ColorKey.b(), Alpha ) ); + replaceColor( ColorKey, ColorA( ColorKey.r, ColorKey.g, ColorKey.b, Alpha ) ); } void SubTexture::createMaskFromColor(RGB ColorKey, Uint8 Alpha) { - createMaskFromColor( ColorA( ColorKey.r(), ColorKey.g(), ColorKey.b(), 255 ), Alpha ); + createMaskFromColor( ColorA( ColorKey.r, ColorKey.g, ColorKey.b, 255 ), Alpha ); } void SubTexture::cacheAlphaMask() { Uint32 size = ( mSrcRect.Right - mSrcRect.Left ) * ( mSrcRect.Bottom - mSrcRect.Top ); - eeSAFE_DELETE_ARRAY( mAlpha ); - mAlpha = eeNewArray( Uint8, size ); + eeSAFE_DELETE_ARRAY( mAlphaMask ); + mAlphaMask = eeNewArray( Uint8, size ); mTexture->lock(); @@ -210,7 +221,7 @@ void SubTexture::cacheAlphaMask() { for ( int x = mSrcRect.Left; x < mSrcRect.Right; x++ ) { rX = x - mSrcRect.Left; - mAlpha[ rX + rY * rW ] = mTexture->getPixel( x, y ).a(); + mAlphaMask[ rX + rY * rW ] = mTexture->getPixel( x, y ).a; } } @@ -243,10 +254,10 @@ void SubTexture::cacheColors() { Pos = ( rX + rY * rW ) * Channels; - if ( Channels >= 1 ) mPixels[ Pos ] = tColor.r(); - if ( Channels >= 2 ) mPixels[ Pos + 1 ] = tColor.g(); - if ( Channels >= 3 ) mPixels[ Pos + 2 ] = tColor.b(); - if ( Channels >= 4 ) mPixels[ Pos + 3 ] = tColor.a(); + if ( Channels >= 1 ) mPixels[ Pos ] = tColor.r; + if ( Channels >= 2 ) mPixels[ Pos + 1 ] = tColor.g; + if ( Channels >= 3 ) mPixels[ Pos + 2 ] = tColor.b; + if ( Channels >= 4 ) mPixels[ Pos + 3 ] = tColor.a; } } @@ -255,10 +266,10 @@ void SubTexture::cacheColors() { Uint8 SubTexture::getAlphaAt( const Int32& X, const Int32& Y ) { if ( mTexture->hasLocalCopy() ) - return mTexture->getPixel( mSrcRect.Left + X, mSrcRect.Right + Y ).a(); + return mTexture->getPixel( mSrcRect.Left + X, mSrcRect.Right + Y ).a; - if ( NULL != mAlpha ) - return mAlpha[ X + Y * ( mSrcRect.Right - mSrcRect.Left ) ]; + if ( NULL != mAlphaMask ) + return mAlphaMask[ X + Y * ( mSrcRect.Right - mSrcRect.Left ) ]; if ( NULL != mPixels ) return mPixels[ ( X + Y * ( mSrcRect.Right - mSrcRect.Left ) ) * mTexture->getChannels() + 3 ]; @@ -296,10 +307,10 @@ void SubTexture::setColorAt( const Int32& X, const Int32& Y, const ColorA& Color Uint32 Channels = mTexture->getChannels(); unsigned int Pos = ( X + Y * ( mSrcRect.Right - mSrcRect.Left ) ) * Channels; - if ( Channels >= 1 ) mPixels[ Pos ] = Color.r(); - if ( Channels >= 2 ) mPixels[ Pos + 1 ] = Color.g(); - if ( Channels >= 3 ) mPixels[ Pos + 2 ] = Color.b(); - if ( Channels >= 4 ) mPixels[ Pos + 3 ] = Color.a(); + if ( Channels >= 1 ) mPixels[ Pos ] = Color.r; + if ( Channels >= 2 ) mPixels[ Pos + 1 ] = Color.g; + if ( Channels >= 3 ) mPixels[ Pos + 2 ] = Color.b; + if ( Channels >= 4 ) mPixels[ Pos + 3 ] = Color.a; } else { cacheColors(); setColorAt( X, Y, Color ); @@ -308,7 +319,7 @@ void SubTexture::setColorAt( const Int32& X, const Int32& Y, const ColorA& Color void SubTexture::clearCache() { eeSAFE_DELETE_ARRAY( mPixels ); - eeSAFE_DELETE_ARRAY( mAlpha ); + eeSAFE_DELETE_ARRAY( mAlphaMask ); } Uint8 * SubTexture::lock() { @@ -349,8 +360,8 @@ Sizei SubTexture::getRealSize() { return mSrcRect.getSize(); } -Sizei SubTexture::getSize() { - return Sizei( (Int32)mDestSize.x, (Int32)mDestSize.y ); +Sizef SubTexture::getSize() { + return Sizef( (Float)((Int32)( mOriDestSize.getWidth() / mPixelDensity )), (Float)((Int32)( mOriDestSize.getHeight() / mPixelDensity )) ); } const Uint8* SubTexture::getPixelsPtr() { diff --git a/src/eepp/graphics/text.cpp b/src/eepp/graphics/text.cpp index 0a75541a7..3b87c896a 100644 --- a/src/eepp/graphics/text.cpp +++ b/src/eepp/graphics/text.cpp @@ -354,7 +354,7 @@ Uint32 Text::getStyle() const { void Text::setAlpha( const Uint8& alpha ) { std::size_t s = mColors.size(); for ( Uint32 i = 0; i < s; i++ ) { - mColors[ i ].Alpha = alpha; + mColors[ i ].a = alpha; } } @@ -444,10 +444,10 @@ void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const ColorA Col = getFillColor(); - if ( Col.a() != 255 ) { + if ( Col.a != 255 ) { ColorA ShadowColor = getShadowColor(); - ShadowColor.Alpha = (Uint8)( (Float)ShadowColor.Alpha * ( (Float)Col.a() / (Float)255 ) ); + ShadowColor.a = (Uint8)( (Float)ShadowColor.a * ( (Float)Col.a / (Float)255 ) ); setFillColor( ShadowColor ); } else { @@ -518,7 +518,7 @@ void Text::draw(const Float & X, const Float & Y, const Vector2f & Scale, const } void Text::ensureGeometryUpdate() { - Sizei textureSize = mFont->getTexture(mRealCharacterSize)->getSize(); + Sizei textureSize = mFont->getTexture(mRealCharacterSize)->getPixelSize(); if ( textureSize != mTextureSize ) mGeometryNeedUpdate = true; diff --git a/src/eepp/graphics/texture.cpp b/src/eepp/graphics/texture.cpp index 13d6028d0..5117a6956 100755 --- a/src/eepp/graphics/texture.cpp +++ b/src/eepp/graphics/texture.cpp @@ -285,7 +285,7 @@ void Texture::replaceColor( const ColorA& ColorKey, const ColorA& NewColor ) { void Texture::createMaskFromColor( const ColorA& ColorKey, Uint8 Alpha ) { lock( true ); - Image::replaceColor( ColorKey, ColorA( ColorKey.r(), ColorKey.g(), ColorKey.b(), Alpha ) ); + Image::replaceColor( ColorKey, ColorA( ColorKey.r, ColorKey.g, ColorKey.b, Alpha ) ); unlock( false, true ); } @@ -725,3 +725,19 @@ void Texture::drawQuadEx( Quad2f Q, const Vector2f& Offset, const Float &Angle, } }} + +Sizef EE::Graphics::Texture::getSize() { + return Sizef( PixelDensity::pxToDp( mImgWidth ), PixelDensity::pxToDp( mImgHeight ) ); +} + +Sizei EE::Graphics::Texture::getPixelSize() { + return Sizei( mImgWidth, mImgHeight ); +} + +void EE::Graphics::Texture::draw( const Vector2f & position ) { + drawFast( position.x, position.y ); +} + +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 ); +} diff --git a/src/eepp/graphics/textureloader.cpp b/src/eepp/graphics/textureloader.cpp index db38a1877..b88f000aa 100644 --- a/src/eepp/graphics/textureloader.cpp +++ b/src/eepp/graphics/textureloader.cpp @@ -450,7 +450,7 @@ void TextureLoader::loadFromPixels() { Image * tImg = eeNew ( Image, ( mPixels, mImgWidth, mImgHeight, mChannels ) ); - tImg->createMaskFromColor( ColorA( mColorKey->r(), mColorKey->g(), mColorKey->b(), 255 ), 0 ); + tImg->createMaskFromColor( ColorA( mColorKey->r, mColorKey->g, mColorKey->b, 255 ), 0 ); tImg->avoidFreeImage( true ); @@ -538,7 +538,7 @@ const Uint32& TextureLoader::getId() const { void TextureLoader::setColorKey( RGB Color ) { eeSAFE_DELETE( mColorKey ); - mColorKey = eeNew( RGB, ( Color.r(), Color.g(), Color.b() ) ); + mColorKey = eeNew( RGB, ( Color.r, Color.g, Color.b ) ); } const std::string& TextureLoader::filepath() const { diff --git a/src/eepp/graphics/vertexbuffer.cpp b/src/eepp/graphics/vertexbuffer.cpp index 3cc666943..d71967cff 100644 --- a/src/eepp/graphics/vertexbuffer.cpp +++ b/src/eepp/graphics/vertexbuffer.cpp @@ -54,10 +54,10 @@ void VertexBuffer::addVertexCoord( const Vector2f& VertexCoord, const Uint32& Te } void VertexBuffer::addColor( const ColorA& Color ) { - mColorArray.push_back( Color.r() ); - mColorArray.push_back( Color.g() ); - mColorArray.push_back( Color.b() ); - mColorArray.push_back( Color.a() ); + mColorArray.push_back( Color.r ); + mColorArray.push_back( Color.g ); + mColorArray.push_back( Color.b ); + mColorArray.push_back( Color.a ); } void VertexBuffer::addIndex( const Uint32& Index ) { diff --git a/src/eepp/system/color.cpp b/src/eepp/system/color.cpp new file mode 100644 index 000000000..60cfb8d95 --- /dev/null +++ b/src/eepp/system/color.cpp @@ -0,0 +1,135 @@ +#include +#include + +namespace EE { namespace System { + +const Color Color::White = Color(255,255,255); +const Color Color::Black = Color(0,0,0); +const Color Color::Red = Color(255,0,0); +const Color Color::Green = Color(0,255,0); +const Color Color::Blue = Color(0,0,255); +const Color Color::Yellow = Color(255,255,0); +const Color Color::Cyan = Color(0,255,255); +const Color Color::Magenta = Color(255,0,255); +const Color Color::Silver = Color(192,0,192); +const Color Color::Gray = Color(128,128,128); +const Color Color::Maroon = Color(128,0,0); +const Color Color::Olive = Color(128,128,0); +const Color Color::OfficeGreen = Color(0,128,0); +const Color Color::Purple = Color(128,0,128); +const Color Color::Teal = Color(0,128,128); +const Color Color::Navy = Color(0,0,128); + +const ColorA ColorA::Transparent = ColorA(0,0,0,0); +const ColorA ColorA::White = ColorA(255,255,255,255); +const ColorA ColorA::Black = ColorA(0,0,0,255); + +Color::Color() : tColor() +{ +} + +/** Creates an RGB color from each component. +** @param r Red component +** @param g Green component +** @param b Blue component +*/ +Color::Color( Uint8 r, Uint8 g, Uint8 b ) : tColor( r, g, b ) +{ +} + +Color::Color( const tColor& color ) : + tColor( color.r, color.g, color.b ) +{ +} + +Color::Color( Uint32 Col ) +{ + Col = BitOp::swapLE32( Col ); + r = static_cast( Col >> 16 ); + g = static_cast( Col >> 8 ); + b = static_cast( Col >> 0 ); +} + +/** Blend a source color to destination color */ +ColorAf Color::blend( ColorAf srcf, ColorAf dstf ) { + Float alpha = srcf.a + dstf.a * ( 1.f - srcf.a ); + Float red = ( srcf.r * srcf.a + dstf.r * dstf.a * ( 1.f - srcf.a ) ) / alpha; + Float green = ( srcf.g * srcf.a + dstf.g * dstf.a * ( 1.f - srcf.a ) ) / alpha; + Float blue = ( srcf.b * srcf.a + dstf.b * dstf.a * ( 1.f - srcf.a ) ) / alpha; + + return ColorAf( red, green, blue, alpha ); +} + +#define EE_COLOR_BLEND_FTOU8(color) (Uint8)( color == 1.f ? 255 : (color * 255.99f)) + +/** Blend a source color to destination color */ +ColorA Color::blend( ColorA src, ColorA dst ) { + ColorAf srcf( (Float)src.r / 255.f, (Float)src.g / 255.f, (Float)src.b / 255.f, (Float)src.a / 255.f ); + ColorAf dstf( (Float)dst.r / 255.f, (Float)dst.g / 255.f, (Float)dst.b / 255.f, (Float)dst.a / 255.f ); + Float alpha = srcf.a + dstf.a * ( 1.f - srcf.a ); + Float red = ( srcf.r * srcf.a + dstf.r * dstf.a * ( 1.f - srcf.a ) ) / alpha; + Float green = ( srcf.g * srcf.a + dstf.g * dstf.a * ( 1.f - srcf.a ) ) / alpha; + Float blue = ( srcf.b * srcf.a + dstf.b * dstf.a * ( 1.f - srcf.a ) ) / alpha; + + return ColorA( EE_COLOR_BLEND_FTOU8(red), EE_COLOR_BLEND_FTOU8(green), EE_COLOR_BLEND_FTOU8(blue), EE_COLOR_BLEND_FTOU8(alpha) ); +} + +ColorA::ColorA() : + tColorA() +{} + +ColorA::ColorA(Uint8 r, Uint8 g, Uint8 b, Uint8 a) : + tColorA(r,g,b,a) +{} + +ColorA::ColorA( const tColor& Col ) : + tColorA( Col ) +{} + +ColorA::ColorA( const tColor& Col, Uint8 a ) : + tColorA( Col, a ) +{} + +ColorA::ColorA( const tColorA& Col ) : + tColorA( Col.Value ) +{} + +ColorA::ColorA( const Uint32& Col ) : + tColorA( Col ) +{} + +ColorA ColorA::colorFromPointer( void *ptr ) { + unsigned long val = (long)ptr; + + // hash the pointer up nicely + val = (val+0x7ed55d16) + (val<<12); + val = (val^0xc761c23c) ^ (val>>19); + val = (val+0x165667b1) + (val<<5); + val = (val+0xd3a2646c) ^ (val<<9); + val = (val+0xfd7046c5) + (val<<3); + val = (val^0xb55a4f09) ^ (val>>16); + + unsigned char r = (val>>0) & 0xFF; + unsigned char g = (val>>8) & 0xFF; + unsigned char b = (val>>16) & 0xFF; + + unsigned char max = r>g ? (r>b ? r : b) : (g>b ? g : b); + + const int mult = 127; + const int add = 63; + r = (r*mult)/max + add; + g = (g*mult)/max + add; + b = (b*mult)/max + add; + + return ColorA(r, g, b, 255); +} + +ColorA ColorA::fromString( const char * str ) { + return ColorA( std::strtoul( str, NULL, 16 ) ); +} + +ColorA ColorA::fromString( const std::string& str ) { + return ColorA( std::strtoul( str.c_str(), NULL, 16 ) ); +} + +}} diff --git a/src/eepp/ui/uicontrolanim.cpp b/src/eepp/ui/uicontrolanim.cpp index b08d436a0..9c69269e4 100644 --- a/src/eepp/ui/uicontrolanim.cpp +++ b/src/eepp/ui/uicontrolanim.cpp @@ -418,7 +418,7 @@ void UIControlAnim::drawBorder() { } ColorA UIControlAnim::getColor( const ColorA& Col ) { - return ColorA( Col.r(), Col.g(), Col.b(), static_cast( (Float)Col.a() * ( mAlpha / 255.f ) ) ); + return ColorA( Col.r, Col.g, Col.b, static_cast( (Float)Col.a * ( mAlpha / 255.f ) ) ); } void UIControlAnim::updateQuad() { diff --git a/src/eepp/ui/uiimage.cpp b/src/eepp/ui/uiimage.cpp index a1624f5c2..39459aea0 100644 --- a/src/eepp/ui/uiimage.cpp +++ b/src/eepp/ui/uiimage.cpp @@ -121,7 +121,7 @@ void UIImage::drawSubTexture() { void UIImage::setAlpha( const Float& alpha ) { UIControlAnim::setAlpha( alpha ); - mColor.Alpha = (Uint8)alpha; + mColor.a = (Uint8)alpha; } Graphics::SubTexture * UIImage::getSubTexture() const { @@ -134,7 +134,7 @@ const ColorA& UIImage::getColor() const { void UIImage::setColor( const ColorA& col ) { mColor = col; - setAlpha( col.a() ); + setAlpha( col.a ); } const EE_RENDER_MODE& UIImage::getRenderMode() const { diff --git a/src/eepp/ui/uiskincomplex.cpp b/src/eepp/ui/uiskincomplex.cpp index 4a026f6d3..7b7b739eb 100644 --- a/src/eepp/ui/uiskincomplex.cpp +++ b/src/eepp/ui/uiskincomplex.cpp @@ -34,8 +34,8 @@ void UISkinComplex::draw( const Float& X, const Float& Y, const Float& Width, co mTempColor = mColor[ State ]; - if ( mTempColor.Alpha != Alpha ) { - mTempColor.Alpha = (Uint8)( (Float)mTempColor.Alpha * ( (Float)Alpha / 255.f ) ); + if ( mTempColor.a != Alpha ) { + mTempColor.a = (Uint8)( (Float)mTempColor.a * ( (Float)Alpha / 255.f ) ); } SubTexture * tSubTexture = mSubTexture[ State ][ UpLeft ]; diff --git a/src/eepp/ui/uiskinsimple.cpp b/src/eepp/ui/uiskinsimple.cpp index 79b9079df..87e083629 100644 --- a/src/eepp/ui/uiskinsimple.cpp +++ b/src/eepp/ui/uiskinsimple.cpp @@ -25,8 +25,8 @@ void UISkinSimple::draw( const Float& X, const Float& Y, const Float& Width, con if ( NULL != tSubTexture ) { tSubTexture->setDestSize( Sizef( Width, Height ) ); - if ( mTempColor.Alpha != Alpha ) { - mTempColor.Alpha = (Uint8)( (Float)mTempColor.Alpha * ( (Float)Alpha / 255.f ) ); + if ( mTempColor.a != Alpha ) { + mTempColor.a = (Uint8)( (Float)mTempColor.a * ( (Float)Alpha / 255.f ) ); } tSubTexture->draw( X, Y, mTempColor ); diff --git a/src/eepp/ui/uisprite.cpp b/src/eepp/ui/uisprite.cpp index 4f43d6f66..e48dd0eec 100644 --- a/src/eepp/ui/uisprite.cpp +++ b/src/eepp/ui/uisprite.cpp @@ -107,7 +107,7 @@ void UISprite::setColor( const ColorA& color ) { if ( NULL != mSprite ) mSprite->setColor( color ); - setAlpha( color.a() ); + setAlpha( color.a ); } const EE_RENDER_MODE& UISprite::getRenderMode() const { diff --git a/src/eepp/ui/uitextview.cpp b/src/eepp/ui/uitextview.cpp index d02e20bea..ae8cce1b8 100644 --- a/src/eepp/ui/uitextview.cpp +++ b/src/eepp/ui/uitextview.cpp @@ -179,7 +179,7 @@ UITextView * UITextView::setFontColor( const ColorA& color ) { mFontStyleConfig.Color = color; mTextCache->setColor( color ); - setAlpha( color.a() ); + setAlpha( color.a ); return this; } @@ -206,10 +206,10 @@ UITextView * UITextView::setSelectionBackColor( const ColorA& color ) { void UITextView::setAlpha( const Float& alpha ) { UIControlAnim::setAlpha( alpha ); - mFontStyleConfig.Color.Alpha = (Uint8)alpha; - mFontStyleConfig.ShadowColor.Alpha = (Uint8)alpha; + mFontStyleConfig.Color.a = (Uint8)alpha; + mFontStyleConfig.ShadowColor.a = (Uint8)alpha; - mTextCache->setAlpha( mFontStyleConfig.Color.Alpha ); + mTextCache->setAlpha( mFontStyleConfig.Color.a ); } void UITextView::autoShrink() { diff --git a/src/eepp/ui/uitooltip.cpp b/src/eepp/ui/uitooltip.cpp index 7d1fb585b..090536346 100644 --- a/src/eepp/ui/uitooltip.cpp +++ b/src/eepp/ui/uitooltip.cpp @@ -133,7 +133,7 @@ const ColorA& UITooltip::getFontColor() const { void UITooltip::setFontColor( const ColorA& color ) { mStyleConfig.Color = color; mTextCache->setColor( mStyleConfig.Color ); - setAlpha( color.a() ); + setAlpha( color.a ); } const ColorA& UITooltip::getFontShadowColor() const { @@ -142,14 +142,14 @@ const ColorA& UITooltip::getFontShadowColor() const { void UITooltip::setFontShadowColor( const ColorA& color ) { mStyleConfig.ShadowColor = color; - setAlpha( color.a() ); + setAlpha( color.a ); mTextCache->setShadowColor( mStyleConfig.ShadowColor ); } void UITooltip::setAlpha( const Float& alpha ) { UIControlAnim::setAlpha( alpha ); - mStyleConfig.Color.Alpha = (Uint8)alpha; - mStyleConfig.ShadowColor.Alpha = (Uint8)alpha; + mStyleConfig.Color.a = (Uint8)alpha; + mStyleConfig.ShadowColor.a = (Uint8)alpha; mTextCache->setColor( mStyleConfig.Color ); } diff --git a/src/eepp/window/platform/win/cursorwin.cpp b/src/eepp/window/platform/win/cursorwin.cpp index f1ed9a4d1..6cd191438 100644 --- a/src/eepp/window/platform/win/cursorwin.cpp +++ b/src/eepp/window/platform/win/cursorwin.cpp @@ -85,10 +85,10 @@ static BYTE *get_dib_from_bitmap_32(Image *bitmap) { ColorA C = bitmap->getPixel( x, y ); /* BGR */ - dst[0] = C.b(); - dst[1] = C.g(); - dst[2] = C.r(); - dst[3] = C.a(); + dst[0] = C.b; + dst[1] = C.g; + dst[2] = C.r; + dst[3] = C.a; dst += 4; } @@ -178,7 +178,7 @@ void CursorWin::create() { for (x = 0; x < (int)mImage->getWidth(); x++) { ColorA C = mImage->getPixel( x, y ); - if ( C.a() != 0 ) { + if ( C.a != 0 ) { /* Don't touch XOR value */ SetPixel( h_and_dc, x, y, 0 ); } else { diff --git a/src/eepp/window/platform/x11/cursorx11.cpp b/src/eepp/window/platform/x11/cursorx11.cpp index 6811feb23..f3c03814d 100644 --- a/src/eepp/window/platform/x11/cursorx11.cpp +++ b/src/eepp/window/platform/x11/cursorx11.cpp @@ -58,7 +58,7 @@ void CursorX11::create() { for ( ix = 0; ix < mImage->getWidth(); ix++ ) { ColorA C = mImage->getPixel( ix, iy ); - image->pixels[c++] = ( C.a() << 24 ) | ( C.r() << 16 ) | ( C.g() <<8 ) | ( C.b() ); + image->pixels[c++] = ( C.a << 24 ) | ( C.r << 16 ) | ( C.g <<8 ) | ( C.b ); } } diff --git a/src/eepp/window/window.cpp b/src/eepp/window/window.cpp index db28a5450..f45f14fab 100644 --- a/src/eepp/window/window.cpp +++ b/src/eepp/window/window.cpp @@ -172,7 +172,7 @@ const WindowInfo * Window::getWindowInfo() const { void Window::setClearColor( const RGB& Color ) { mWindow.ClearColor = Color; - GLi->clearColor( static_cast( mWindow.ClearColor.r() ) / 255.0f, static_cast( mWindow.ClearColor.g() ) / 255.0f, static_cast( mWindow.ClearColor.b() ) / 255.0f, 255.0f ); + GLi->clearColor( static_cast( mWindow.ClearColor.r ) / 255.0f, static_cast( mWindow.ClearColor.g ) / 255.0f, static_cast( mWindow.ClearColor.b ) / 255.0f, 255.0f ); } RGB Window::getClearColor() const { diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 67709d687..5509e96fc 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -1086,10 +1086,10 @@ void EETest::loadTextures() { for ( x = 0; x < w; x++) { ColorA C = Tex->getPixel(x, y); - if ( C.r() > 200 && C.g() > 200 && C.b() > 200 ) - Tex->setPixel(x, y, ColorA( Math::randi(0, 255), Math::randi(0, 255), Math::randi(0, 255), C.a() ) ); + if ( C.r > 200 && C.g > 200 && C.b > 200 ) + Tex->setPixel(x, y, ColorA( Math::randi(0, 255), Math::randi(0, 255), Math::randi(0, 255), C.a ) ); else - Tex->setPixel(x, y, ColorA( Math::randi(200, 255), Math::randi(200, 255), Math::randi(200, 255), C.a() ) ); + Tex->setPixel(x, y, ColorA( Math::randi(200, 255), Math::randi(200, 255), Math::randi(200, 255), C.a ) ); } } @@ -1404,7 +1404,7 @@ void EETest::render() { mInfoText.setString( mInfo ); - if ( mWindow->getClearColor().r() == 0 ) { + if ( mWindow->getClearColor().r == 0 ) { mInfoText.setColor( ColorA(255,255,255,255) ); mInfoText.setOutlineColor( ColorA(0,0,0,255) ); } else {