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