Core: Added alpha to Color (only for opengl)

git-svn-id: svn://ultimatepp.org/upp/trunk@6197 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
unodgs 2013-07-17 18:03:35 +00:00
parent 6353856df8
commit a74fd29425
2 changed files with 40 additions and 4 deletions

View file

@ -70,12 +70,19 @@ Color::operator RGBA() const
{
RGBA color;
if(IsNullInstance())
{
Zero(color);
#if defined(flagWINGL) || defined(flagLINUXGL)
color.a = 255;
#endif
}
else {
color.r = GetR();
color.g = GetG();
color.b = GetB();
color.a = 255;
#if defined(flagWINGL) || defined(flagLINUXGL)
color.a = alpha;
#endif
}
return color;
}

View file

@ -31,6 +31,9 @@ const int COLOR_V = 39;
class Color : public ValueType<Color, COLOR_V, Moveable<Color> > {
protected:
dword color;
#if defined(flagWINGL) || defined(flagLINUXGL)
byte alpha;
#endif
dword Get() const;
@ -40,8 +43,15 @@ public:
int GetR() const { return GetRValue(Get()); }
int GetG() const { return GetGValue(Get()); }
int GetB() const { return GetBValue(Get()); }
#if defined(flagWINGL) || defined(flagLINUXGL)
int GetA() const { return alpha; }
#endif
#if defined(flagWINGL) || defined(flagLINUXGL)
void SetNull() { color = 0xffffffff; alpha = 255; }
#else
void SetNull() { color = 0xffffffff; }
#endif
bool IsNullInstance() const { return color == 0xffffffff; }
unsigned GetHashValue() const { return color; }
bool operator==(Color c) const { return color == c.color; }
@ -52,24 +62,43 @@ public:
void Xmlize(XmlIO& xio);
Color() { SetNull(); }
#if defined(flagWINGL) || defined(flagLINUXGL)
Color(int r, int g, int b) { color = RGB(r, g, b); alpha = 255; }
Color(int r, int g, int b, int a) { color = RGB(r, g, b); alpha = (byte) a; }
Color(int n, int) { color = 0x80000000 | n; alpha = 255;}
#else
Color(int r, int g, int b) { color = RGB(r, g, b); }
Color(int n, int) { color = 0x80000000 | n; }
#endif
Color(const Nuller&) { SetNull(); }
operator Value() const { return SvoToValue(*this); }
#if defined(flagWINGL) || defined(flagLINUXGL)
Color(const Value& q) { Color c = q.Get<Color>(); color = c.color; alpha = c.alpha; }
#else
Color(const Value& q) { color = q.Get<Color>().color; }
#endif
operator RGBA() const;
Color(RGBA rgba);
#if defined(flagWINGL) || defined(flagLINUXGL)
Color(Color (*fn)()) { color = (*fn)().color; alpha = 255; }
static Color FromRaw(dword co) { Color c; c.color = co; c.alpha = 255; return c; }
Color& Alpha(byte a) { alpha = a; return *this; }
#else
Color(Color (*fn)()) { color = (*fn)().color; }
static Color FromRaw(dword co) { Color c; c.color = co; return c; }
#endif
#ifdef PLATFORM_WIN32
operator COLORREF() const { return (COLORREF) Get(); }
#if defined(flagWINGL) || defined(flagLINUXGL)
static Color FromCR(COLORREF cr) { Color c; c.color = (dword)cr; c.alpha = 255; return c; }
#else
static Color FromCR(COLORREF cr) { Color c; c.color = (dword)cr; return c; }
#endif
#else
operator dword() const { return Get(); }
#endif