mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-11 17:17:42 +03:00
Refactored color classes.
Added Graphics::Drawable class. --HG-- branch : dev
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
using namespace EE::Math;
|
||||
|
||||
#include <eepp/system/bitop.hpp>
|
||||
#include <eepp/system/colors.hpp>
|
||||
#include <eepp/system/color.hpp>
|
||||
#include <eepp/system/pack.hpp>
|
||||
#include <eepp/system/iostream.hpp>
|
||||
#include <eepp/system/iostreamfile.hpp>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <eepp/math/math.hpp>
|
||||
using namespace EE::Math;
|
||||
|
||||
#include <eepp/system/colors.hpp>
|
||||
#include <eepp/system/color.hpp>
|
||||
#include <eepp/system/bitop.hpp>
|
||||
#include <eepp/system/clock.hpp>
|
||||
#include <eepp/system/singleton.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 );
|
||||
|
||||
|
||||
46
include/eepp/graphics/drawable.hpp
Normal file
46
include/eepp/graphics/drawable.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef EE_GRAPHICS_DRAWABLE_HPP
|
||||
#define EE_GRAPHICS_DRAWABLE_HPP
|
||||
|
||||
#include <eepp/math/size.hpp>
|
||||
#include <eepp/system/color.hpp>
|
||||
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
|
||||
@@ -2,7 +2,7 @@
|
||||
#define EE_GRAPHICS_FONTSTYLECONFIG_HPP
|
||||
|
||||
#include <eepp/config.hpp>
|
||||
#include <eepp/system/colors.hpp>
|
||||
#include <eepp/system/color.hpp>
|
||||
using namespace EE::System;
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <eepp/math/rect.hpp>
|
||||
using namespace EE::Math;
|
||||
|
||||
#include <eepp/system/colors.hpp>
|
||||
#include <eepp/system/color.hpp>
|
||||
using namespace EE::System;
|
||||
|
||||
#include <eepp/graphics/renders.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);
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
#include <eepp/graphics/base.hpp>
|
||||
#include <eepp/graphics/texture.hpp>
|
||||
#include <eepp/math/originpoint.hpp>
|
||||
#include <eepp/graphics/drawable.hpp>
|
||||
|
||||
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;
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
|
||||
#include <eepp/core.hpp>
|
||||
#include <eepp/graphics/image.hpp>
|
||||
#include <eepp/graphics/drawable.hpp>
|
||||
#include <eepp/core/noncopyable.hpp>
|
||||
#include <eepp/math/polygon2.hpp>
|
||||
#include <eepp/math/originpoint.hpp>
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
using namespace EE::Math;
|
||||
|
||||
#include <eepp/core.hpp>
|
||||
#include <eepp/system/colors.hpp>
|
||||
#include <eepp/system/color.hpp>
|
||||
#include <eepp/system/singleton.hpp>
|
||||
using namespace EE::System;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef EEPP_SYSTEM_HPP
|
||||
#define EEPP_SYSTEM_HPP
|
||||
|
||||
#include <eepp/system/colors.hpp>
|
||||
#include <eepp/system/color.hpp>
|
||||
#include <eepp/system/bitop.hpp>
|
||||
#include <eepp/system/sys.hpp>
|
||||
#include <eepp/system/filesystem.hpp>
|
||||
|
||||
254
include/eepp/system/color.hpp
Executable file
254
include/eepp/system/color.hpp
Executable file
@@ -0,0 +1,254 @@
|
||||
#ifndef EE_SYSTEMCCOLORS_H
|
||||
#define EE_SYSTEMCCOLORS_H
|
||||
|
||||
#include <eepp/config.hpp>
|
||||
#include <eepp/system/bitop.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace EE { namespace System {
|
||||
|
||||
/** @brief Template class for a RGB color */
|
||||
template<typename T>
|
||||
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<T>( Col >> 16 );
|
||||
g = static_cast<T>( Col >> 8 );
|
||||
b = static_cast<T>( Col >> 0 );
|
||||
}
|
||||
|
||||
bool operator==( const tColor<T>& Col ) {
|
||||
return ( r == Col.r && g == Col.g && b == Col.b );
|
||||
}
|
||||
|
||||
bool operator!=( const tColor<T>& Col ) {
|
||||
return !( r == Col.r && g == Col.g && b == Col.b );
|
||||
}
|
||||
};
|
||||
|
||||
/** @brief Template class for a RGBA color */
|
||||
template<typename T>
|
||||
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<T>& 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<T>& Col, T a ) :
|
||||
r( Col.r ),
|
||||
g( Col.g ),
|
||||
b( Col.b ),
|
||||
a( a )
|
||||
{
|
||||
}
|
||||
|
||||
tColorA( const tColorA<T>& 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<T>& Col ) {
|
||||
Value = Col.Value;
|
||||
}
|
||||
|
||||
bool operator==( const tColorA<T>& Col ) const {
|
||||
return ( r == Col.r && g == Col.g && b == Col.b && a == Col.a );
|
||||
}
|
||||
|
||||
bool operator!=( const tColorA<T>& Col ) const {
|
||||
return !(*this == Col);
|
||||
}
|
||||
|
||||
tColorA<T> operator+( const tColorA<T>& Col ) const {
|
||||
return tColorA<T>( 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<T> operator-( const tColorA<T>& Col ) const {
|
||||
return tColorA<T>( 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<T> operator*( const tColorA<T>& Col ) const {
|
||||
return tColorA<T>( ( this->r * Col.r / 255 ),
|
||||
( this->g * Col.g / 255 ),
|
||||
( this->b * Col.b / 255 ),
|
||||
( this->a * Col.a / 255 )
|
||||
);
|
||||
}
|
||||
|
||||
tColor<T> toColor() {
|
||||
return tColor<T>( r, g, b );
|
||||
}
|
||||
};
|
||||
|
||||
class EE_API ColorA : public tColorA<Uint8>
|
||||
{
|
||||
public:
|
||||
ColorA();
|
||||
|
||||
ColorA( Uint8 r, Uint8 g, Uint8 b, Uint8 a );
|
||||
|
||||
ColorA( const tColor<Uint8>& Col );
|
||||
|
||||
ColorA( const tColor<Uint8>& Col, Uint8 a );
|
||||
|
||||
ColorA( const tColorA<Uint8>& 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<Float> Colorf;
|
||||
typedef tColorA<Float> ColorAf;
|
||||
typedef tColorA<float> ColorAff;
|
||||
|
||||
//! @brief Small class to help in some color operations
|
||||
class EE_API Color : public tColor<Uint8> {
|
||||
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<Uint8>& 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
|
||||
@@ -1,324 +0,0 @@
|
||||
#ifndef EE_SYSTEMCCOLORS_H
|
||||
#define EE_SYSTEMCCOLORS_H
|
||||
|
||||
#include <eepp/config.hpp>
|
||||
#include <eepp/system/bitop.hpp>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
namespace EE { namespace System {
|
||||
|
||||
/** @brief Template class for a RGB color */
|
||||
template<typename T>
|
||||
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<T>( Col >> 16 );
|
||||
Green = static_cast<T>( Col >> 8 );
|
||||
Blue = static_cast<T>( 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<T>& Col) {
|
||||
return ( Red == Col.r() && Green == Col.g() && Blue == Col.b() );
|
||||
}
|
||||
|
||||
bool operator!=(tColor<T>& Col) {
|
||||
return !( Red == Col.r() && Green == Col.g() && Blue == Col.b() );
|
||||
}
|
||||
};
|
||||
|
||||
/** @brief Template class for a RGBA color */
|
||||
template<typename T>
|
||||
class tColorA {
|
||||
public:
|
||||
static const tColorA<T> Transparent; ///< Transparent predefined color
|
||||
static const tColorA<T> 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<T>& 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<T>& Col, T a ) :
|
||||
Red( Col.Red ),
|
||||
Green( Col.Green ),
|
||||
Blue( Col.Blue ),
|
||||
Alpha( a )
|
||||
{
|
||||
}
|
||||
|
||||
tColorA( const tColorA<T>& 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<T>& Col ) {
|
||||
Value = Col.Value;
|
||||
}
|
||||
|
||||
bool operator==( const tColorA<T>& Col ) const {
|
||||
return ( Red == Col.Red && Green == Col.Green && Blue == Col.Blue && Alpha == Col.Alpha );
|
||||
}
|
||||
|
||||
bool operator!=( const tColorA<T>& Col ) const {
|
||||
return !(*this == Col);
|
||||
}
|
||||
|
||||
tColorA<T> operator+( const tColorA<T>& Col ) const {
|
||||
return tColorA<T>( 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<T> operator-( const tColorA<T>& Col ) const {
|
||||
return tColorA<T>( 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<T> operator*( const tColorA<T>& Col ) const {
|
||||
return tColorA<T>( ( this->Red * Col.Red / 255 ),
|
||||
( this->Green * Col.Green / 255 ),
|
||||
( this->Blue * Col.Blue / 255 ),
|
||||
( this->Alpha * Col.Alpha / 255 )
|
||||
);
|
||||
}
|
||||
|
||||
tColor<T> toColor() {
|
||||
return tColor<T>( Red, Green, Blue );
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
const tColorA<T> tColorA<T>::Transparent = tColorA<T>(0,0,0,0);
|
||||
|
||||
template <typename T>
|
||||
const tColorA<T> tColorA<T>::Black = tColorA<T>(0,0,0,255);
|
||||
|
||||
class tColorAI : public tColorA<Uint8>
|
||||
{
|
||||
public:
|
||||
tColorAI() :
|
||||
tColorA<Uint8>()
|
||||
{}
|
||||
|
||||
tColorAI(Uint8 r, Uint8 g, Uint8 b, Uint8 a) :
|
||||
tColorA<Uint8>(r,g,b,a)
|
||||
{}
|
||||
|
||||
tColorAI( const tColor<Uint8>& Col ) :
|
||||
tColorA<Uint8>( Col )
|
||||
{}
|
||||
|
||||
tColorAI( const tColor<Uint8>& Col, Uint8 a ) :
|
||||
tColorA<Uint8>( Col, a )
|
||||
{}
|
||||
|
||||
tColorAI( const tColorA<Uint8>& Col ) :
|
||||
tColorA<Uint8>( Col.Value )
|
||||
{}
|
||||
|
||||
tColorAI( const Uint32& Col ) :
|
||||
tColorA<Uint8>( 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<Float> Colorf;
|
||||
typedef tColorAI ColorA;
|
||||
typedef tColorA<Float> ColorAf;
|
||||
typedef tColorA<float> ColorAff;
|
||||
|
||||
//! @brief Small class to help in some color operations
|
||||
class Color : public tColor<Uint8> {
|
||||
public:
|
||||
Color() : tColor<Uint8>()
|
||||
{
|
||||
}
|
||||
|
||||
/** 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<Uint8>( r, g, b )
|
||||
{
|
||||
}
|
||||
|
||||
Color( const tColor<Uint8>& color ) :
|
||||
tColor<Uint8>( color.Red, color.Green, color.Blue )
|
||||
{
|
||||
}
|
||||
|
||||
Color( Uint32 Col )
|
||||
{
|
||||
Col = BitOp::swapLE32( Col );
|
||||
Red = static_cast<Uint8>( Col >> 16 );
|
||||
Green = static_cast<Uint8>( Col >> 8 );
|
||||
Blue = static_cast<Uint8>( 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
|
||||
@@ -14,7 +14,7 @@
|
||||
using namespace EE::Math;
|
||||
|
||||
#include <eepp/system/bitop.hpp>
|
||||
#include <eepp/system/colors.hpp>
|
||||
#include <eepp/system/color.hpp>
|
||||
#include <eepp/system/singleton.hpp>
|
||||
#include <eepp/system/sys.hpp>
|
||||
using namespace EE::System;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <eepp/math/vector2.hpp>
|
||||
using namespace EE::Math;
|
||||
|
||||
#include <eepp/system/colors.hpp>
|
||||
#include <eepp/system/color.hpp>
|
||||
#include <eepp/system/bitop.hpp>
|
||||
#include <eepp/system/clock.hpp>
|
||||
#include <eepp/system/singleton.hpp>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ UIMapNew::UIMapNew( UIMap * Map, cb::Callback0<void> 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<void> 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<void> 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() ) );
|
||||
}
|
||||
|
||||
@@ -44,21 +44,21 @@ RGB MapLight::processVertex( const Float& PointX, const Float& PointY, const RGB
|
||||
Uint8 TmpColor;
|
||||
Float LightC;
|
||||
|
||||
LightC = eeabs( static_cast<Float> ( mColor.r() - BaseColor.r() ) ) / mRadius;
|
||||
TmpColor = Uint8( (Float)mColor.r() - (VertexDist * LightC) );
|
||||
TmpRGB.Red = VertexColor.r() + ( TmpColor - VertexColor.r() );
|
||||
LightC = eeabs( static_cast<Float> ( mColor.r - BaseColor.r ) ) / mRadius;
|
||||
TmpColor = Uint8( (Float)mColor.r - (VertexDist * LightC) );
|
||||
TmpRGB.r = VertexColor.r + ( TmpColor - VertexColor.r );
|
||||
|
||||
LightC = eeabs( static_cast<Float> ( mColor.g() - BaseColor.g() ) ) / mRadius;
|
||||
TmpColor = Uint8( (Float)mColor.g() - (VertexDist * LightC) );
|
||||
TmpRGB.Green = VertexColor.g() + ( TmpColor - VertexColor.g() );
|
||||
LightC = eeabs( static_cast<Float> ( mColor.g - BaseColor.g ) ) / mRadius;
|
||||
TmpColor = Uint8( (Float)mColor.g - (VertexDist * LightC) );
|
||||
TmpRGB.g = VertexColor.g + ( TmpColor - VertexColor.g );
|
||||
|
||||
LightC = eeabs( static_cast<Float> ( mColor.b() - BaseColor.b() ) ) / mRadius;
|
||||
TmpColor = Uint8( (Float)mColor.b() - (VertexDist * LightC) );
|
||||
TmpRGB.Blue = VertexColor.b() + ( TmpColor - VertexColor.b() );
|
||||
LightC = eeabs( static_cast<Float> ( 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<Float> ( mColor.r() - BaseColor.r() ) ) / mRadius;
|
||||
TmpColor = Uint8( (Float)mColor.r() - (VertexDist * LightC) );
|
||||
TmpRGB.Red = VertexColor.r() + ( TmpColor - VertexColor.r() );
|
||||
LightC = eeabs( static_cast<Float> ( mColor.r - BaseColor.r ) ) / mRadius;
|
||||
TmpColor = Uint8( (Float)mColor.r - (VertexDist * LightC) );
|
||||
TmpRGB.r = VertexColor.r + ( TmpColor - VertexColor.r );
|
||||
|
||||
LightC = eeabs( static_cast<Float> ( mColor.g() - BaseColor.g() ) ) / mRadius;
|
||||
TmpColor = Uint8( (Float)mColor.g() - (VertexDist * LightC) );
|
||||
TmpRGB.Green = VertexColor.g() + ( TmpColor - VertexColor.g() );
|
||||
LightC = eeabs( static_cast<Float> ( mColor.g - BaseColor.g ) ) / mRadius;
|
||||
TmpColor = Uint8( (Float)mColor.g - (VertexDist * LightC) );
|
||||
TmpRGB.g = VertexColor.g + ( TmpColor - VertexColor.g );
|
||||
|
||||
LightC = eeabs( static_cast<Float> ( mColor.b() - BaseColor.b() ) ) / mRadius;
|
||||
TmpColor = Uint8( (Float)mColor.b() - (VertexDist * LightC) );
|
||||
TmpRGB.Blue = VertexColor.b() + ( TmpColor - VertexColor.b() );
|
||||
LightC = eeabs( static_cast<Float> ( 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -220,9 +220,9 @@ void TileMap::draw() {
|
||||
if ( getDrawBackground() ) {
|
||||
Primitives P;
|
||||
|
||||
Uint8 Alpha = static_cast<Uint8>( (Float)mBackColor.a() * ( (Float)mBackAlpha / 255.f ) );
|
||||
Uint8 Alpha = static_cast<Uint8>( (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 );
|
||||
}
|
||||
|
||||
@@ -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<Uint8>(mA) ) );
|
||||
mPri.setColor( ColorA( mConColor.r, mConColor.g, mConColor.b, static_cast<Uint8>(mA) ) );
|
||||
mPri.drawRectangle( Rectf( Vector2f( 0.0f, 0.0f ), Sizef( mWidth, mY ) ) );
|
||||
} else {
|
||||
ColorA C( mConColor.r(), mConColor.g(), mConColor.b(), static_cast<Uint8>(mA) );
|
||||
ColorA C( mConColor.r, mConColor.g, mConColor.b, static_cast<Uint8>(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<Uint8>(mA) ) );
|
||||
mPri.setColor( ColorA( mConLineColor.r, mConLineColor.g, mConLineColor.b, static_cast<Uint8>(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<Uint8>(mA) ) );
|
||||
text.setColor( ColorA ( mFontStyleConfig.Color.r, mFontStyleConfig.Color.g, mFontStyleConfig.Color.b, static_cast<Uint8>(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<Uint8>(mA) ) );
|
||||
text.setColor( ColorA( mFontLineColor.r, mFontLineColor.g, mFontLineColor.b, static_cast<Uint8>(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<Uint8>(mCurAlpha) ) );
|
||||
text2.setColor( ColorA ( mFontLineColor.r, mFontLineColor.g, mFontLineColor.b, static_cast<Uint8>(mCurAlpha) ) );
|
||||
|
||||
if ( (unsigned int)mTBuf->getCursorPos() == mTBuf->getBuffer().size() ) {
|
||||
Uint32 width = text.getTextWidth();
|
||||
|
||||
60
src/eepp/graphics/drawable.cpp
Normal file
60
src/eepp/graphics/drawable.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <eepp/graphics/drawable.hpp>
|
||||
|
||||
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() {
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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() );
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -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 ) {
|
||||
|
||||
@@ -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() )
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 ) {
|
||||
|
||||
135
src/eepp/system/color.cpp
Normal file
135
src/eepp/system/color.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
#include <eepp/system/color.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
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<Uint8>()
|
||||
{
|
||||
}
|
||||
|
||||
/** 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<Uint8>( r, g, b )
|
||||
{
|
||||
}
|
||||
|
||||
Color::Color( const tColor<Uint8>& color ) :
|
||||
tColor<Uint8>( color.r, color.g, color.b )
|
||||
{
|
||||
}
|
||||
|
||||
Color::Color( Uint32 Col )
|
||||
{
|
||||
Col = BitOp::swapLE32( Col );
|
||||
r = static_cast<Uint8>( Col >> 16 );
|
||||
g = static_cast<Uint8>( Col >> 8 );
|
||||
b = static_cast<Uint8>( 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<Uint8>()
|
||||
{}
|
||||
|
||||
ColorA::ColorA(Uint8 r, Uint8 g, Uint8 b, Uint8 a) :
|
||||
tColorA<Uint8>(r,g,b,a)
|
||||
{}
|
||||
|
||||
ColorA::ColorA( const tColor<Uint8>& Col ) :
|
||||
tColorA<Uint8>( Col )
|
||||
{}
|
||||
|
||||
ColorA::ColorA( const tColor<Uint8>& Col, Uint8 a ) :
|
||||
tColorA<Uint8>( Col, a )
|
||||
{}
|
||||
|
||||
ColorA::ColorA( const tColorA<Uint8>& Col ) :
|
||||
tColorA<Uint8>( Col.Value )
|
||||
{}
|
||||
|
||||
ColorA::ColorA( const Uint32& Col ) :
|
||||
tColorA<Uint8>( 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 ) );
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -418,7 +418,7 @@ void UIControlAnim::drawBorder() {
|
||||
}
|
||||
|
||||
ColorA UIControlAnim::getColor( const ColorA& Col ) {
|
||||
return ColorA( Col.r(), Col.g(), Col.b(), static_cast<Uint8>( (Float)Col.a() * ( mAlpha / 255.f ) ) );
|
||||
return ColorA( Col.r, Col.g, Col.b, static_cast<Uint8>( (Float)Col.a * ( mAlpha / 255.f ) ) );
|
||||
}
|
||||
|
||||
void UIControlAnim::updateQuad() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 ];
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ const WindowInfo * Window::getWindowInfo() const {
|
||||
|
||||
void Window::setClearColor( const RGB& Color ) {
|
||||
mWindow.ClearColor = Color;
|
||||
GLi->clearColor( static_cast<Float>( mWindow.ClearColor.r() ) / 255.0f, static_cast<Float>( mWindow.ClearColor.g() ) / 255.0f, static_cast<Float>( mWindow.ClearColor.b() ) / 255.0f, 255.0f );
|
||||
GLi->clearColor( static_cast<Float>( mWindow.ClearColor.r ) / 255.0f, static_cast<Float>( mWindow.ClearColor.g ) / 255.0f, static_cast<Float>( mWindow.ClearColor.b ) / 255.0f, 255.0f );
|
||||
}
|
||||
|
||||
RGB Window::getClearColor() const {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user