1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
#include "Color.h"
using namespace Sexy;
Color Color::Black(0, 0, 0);
Color Color::White(255, 255, 255);
Color::Color() :
mRed(0),
mGreen(0),
mBlue(0),
mAlpha(255)
{
}
Color::Color(int theColor) :
mAlpha((theColor >> 24) & 0xFF),
mRed((theColor >> 16) & 0xFF),
mGreen((theColor >> 8 ) & 0xFF),
mBlue((theColor ) & 0xFF)
{
if(mAlpha==0)
mAlpha = 0xff;
}
Color::Color(int theColor, int theAlpha) :
mRed((theColor >> 16) & 0xFF),
mGreen((theColor >> 8 ) & 0xFF),
mBlue((theColor ) & 0xFF),
mAlpha(theAlpha)
{
}
Color::Color(int theRed, int theGreen, int theBlue) :
mRed(theRed),
mGreen(theGreen),
mBlue(theBlue),
mAlpha(0xFF)
{
}
Color::Color(int theRed, int theGreen, int theBlue, int theAlpha) :
mRed(theRed),
mGreen(theGreen),
mBlue(theBlue),
mAlpha(theAlpha)
{
}
Color::Color(const SexyRGBA &theColor) :
mRed(theColor.r),
mGreen(theColor.g),
mBlue(theColor.b),
mAlpha(theColor.a)
{
}
Color::Color(const uchar* theElements) :
mRed(theElements[0]),
mGreen(theElements[1]),
mBlue(theElements[2]),
mAlpha(0xFF)
{
}
Color::Color(const int* theElements) :
mRed(theElements[0]),
mGreen(theElements[1]),
mBlue(theElements[2]),
mAlpha(0xFF)
{
}
int Color::GetRed() const
{
return mRed;
}
int Color::GetGreen() const
{
return mGreen;
}
int Color::GetBlue() const
{
return mBlue;
}
int Color::GetAlpha() const
{
return mAlpha;
}
int& Color::operator[](int theIdx)
{
static int aJunk = 0;
switch (theIdx)
{
case 0:
return mRed;
case 1:
return mGreen;
case 2:
return mBlue;
case 3:
return mAlpha;
default:
return aJunk;
}
}
int Color::operator[](int theIdx) const
{
switch (theIdx)
{
case 0:
return mRed;
case 1:
return mGreen;
case 2:
return mBlue;
case 3:
return mAlpha;
default:
return 0;
}
}
uint32_t Color::ToInt() const
{
return (mAlpha << 24) | (mRed << 16) | (mGreen << 8) | (mBlue);
}
SexyRGBA Color::ToRGBA() const
{
SexyRGBA anRGBA;
anRGBA.r = mRed;
anRGBA.g = mGreen;
anRGBA.b = mBlue;
anRGBA.a = mAlpha;
return anRGBA;
}
bool Sexy::operator==(const Color& theColor1, const Color& theColor2)
{
return
(theColor1.mRed == theColor2.mRed) &&
(theColor1.mGreen == theColor2.mGreen) &&
(theColor1.mBlue == theColor2.mBlue) &&
(theColor1.mAlpha == theColor2.mAlpha);
}
bool Sexy::operator!=(const Color& theColor1, const Color& theColor2)
{
return
(theColor1.mRed != theColor2.mRed) ||
(theColor1.mGreen != theColor2.mGreen) ||
(theColor1.mBlue != theColor2.mBlue) ||
(theColor1.mAlpha != theColor2.mAlpha);
}
|