some class color improvements

This commit is contained in:
Andre Antunes 2011-08-27 20:16:23 -03:00
parent f019818423
commit aeaa843fae
2 changed files with 33 additions and 17 deletions

View File

@ -37,7 +37,7 @@ void EventDispatcher::scheduleEvent(const SimpleCallback& callback, int delay)
m_scheduledEventList.push(ScheduledEvent(g_platform.getTicks() + delay, callback)); m_scheduledEventList.push(ScheduledEvent(g_platform.getTicks() + delay, callback));
} }
void EventDispatcher::addEvent(const SimpleCallback& callback, bool pushFront) void EventDispatcher::addEvent(const SimpleCallback& callback, bool pushFront /* = false */)
{ {
if(pushFront) if(pushFront)
m_eventList.push_front(callback); m_eventList.push_front(callback);

View File

@ -4,40 +4,56 @@
#include "types.h" #include "types.h"
#include "tools.h" #include "tools.h"
typedef uint32 RGBA; union RGBA
{
bool operator==(const RGBA& otherRgba) const { return rgba == otherRgba.rgba; }
uint32 rgba;
struct{
uint8 r;
uint8 g;
uint8 b;
uint8 a;
};
};
class Color class Color
{ {
public: public:
Color() : color(0x0) { } Color() { color.rgba = 0; }
Color(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) : color(((a & 0xff)<<24) | ((b & 0xff)<<16) | ((g & 0xff)<<8) | (r & 0xff)) { } Color(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) {
setRGBA(r, g, b, a);
}
Color(const Color& other) : color(other.color) { } Color(const Color& other) : color(other.color) { }
Color(RGBA rgba) : color(rgba) { } Color(RGBA rgba) : color(rgba) { }
uint8 a() const { return (color >> 24) & 0xFF; } uint8 a() const { return color.a; }
uint8 b() const { return (color >> 16) & 0xFF; } uint8 b() const { return color.b; }
uint8 g() const { return (color >> 8) & 0xFF; } uint8 g() const { return color.g; }
uint8 r() const { return color & 0xFF; } uint8 r() const { return color.r; }
RGBA rgba() const { return color; } RGBA rgba() const { return color; }
const uint8* rgbaPtr() const { return (const uint8*)&color; } const uint8* rgbaPtr() const { return (const uint8*)&color; }
void setRed(int r) { color = (r & 0xff) | (color & 0xffffff00); } void setRed(int r) { color.r = r; }
void setGreen(int g) { color = ((g & 0xff)<<8) | (color & 0xffff00ff); } void setGreen(int g) { color.g = g; }
void setBlue(int b) { color = ((b & 0xff)<<16) | (color & 0xff00ffff); } void setBlue(int b) { color.b = b; }
void setAlpha(int a) { color = ((a & 0xff)<<24) | (color & 0x00ffffff); } void setAlpha(int a) { color.a = a; }
void setRed(float r) { setRed(int(r*255.0f)); } void setRed(float r) { setRed(int(r*255.0f)); }
void setGreen(float g) { setGreen(int(g*255.0f)); } void setGreen(float g) { setGreen(int(g*255.0f)); }
void setBlue(float b) { setBlue(int(b*255.0f)); } void setBlue(float b) { setBlue(int(b*255.0f)); }
void setAlpha(float a) { setAlpha(int(a*255.0f)); } void setAlpha(float a) { setAlpha(int(a*255.0f)); }
void setRGBA(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) { color = ((a & 0xff)<<24) | ((b & 0xff)<<16) | ((g & 0xff)<<8) | (r & 0xff); } void setRGBA(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) { color.r = r; color.g = g; color.b = b; color.a = a; }
void setABGR(uint32 abgr) { color = ((abgr>>24) & 0xff) | ((abgr>>16) & 0xff) << 8 | ((abgr>>8) & 0xff) << 16 | (abgr & 0xff) << 24; } void setRGBA(uint32 rgba) { color.rgba = rgba; }
void setRGBA(uint32 rgba) { color = rgba; }
Color& operator=(const Color& other) { color = other.color; return *this; } Color& operator=(const Color& other) { color = other.color; return *this; }
bool operator==(const Color& other) const { return other.color == color; } bool operator==(const Color& other) const { return other.color.rgba == color.rgba; }
bool operator!=(const Color& other) const { return other.color != color; } bool operator!=(const Color& other) const { return other.color.rgba != color.rgba; }
static Color white; static Color white;
static Color black; static Color black;