Go to the documentation of this file.
26 #include "../stdext/types.h"
27 #include "../stdext/cast.h"
28 #include "../stdext/string.h"
35 Color() : m_r(1.0f), m_g(1.0f), m_b(1.0f), m_a(1.0f) { }
38 Color(
int r,
int g,
int b,
int a = 0xFF) : m_r(
r/255.0f), m_g(
g/255.0f), m_b(
b/255.0f), m_a(
a/255.0f) { }
39 Color(
float r,
float g,
float b,
float a = 1.0f) : m_r(
r), m_g(
g), m_b(
b), m_a(
a) { }
40 Color(
const std::string& coltext);
44 uint8 a()
const {
return m_a*255.0f; }
45 uint8 b()
const {
return m_b*255.0f; }
46 uint8 g()
const {
return m_g*255.0f; }
47 uint8 r()
const {
return m_r*255.0f; }
49 float aF()
const {
return m_a; }
50 float bF()
const {
return m_b; }
51 float gF()
const {
return m_g; }
52 float rF()
const {
return m_r; }
69 Color operator+(
const Color& other)
const {
return Color(m_r + other.m_r, m_g + other.m_g, m_b + other.m_b, m_a + other.m_a); }
70 Color operator-(
const Color& other)
const {
return Color(m_r - other.m_r, m_g - other.m_g, m_b - other.m_b, m_a - other.m_a); }
78 Color&
operator=(
const Color& other) { m_r = other.m_r; m_g = other.m_g; m_b = other.m_b; m_a = other.m_a;
return *
this; }
84 c += (color.
r() / 51) * 36;
85 c += (color.
g() / 51) * 6;
86 c += (color.
b() / 51);
91 if(color >= 216 || color <= 0)
92 return Color(0, 0, 0);
94 int r = int(color / 36) % 6 * 51;
95 int g = int(color / 6) % 6 * 51;
96 int b = color % 6 * 51;
130 out <<
"#" << hex << setfill(
'0')
131 << setw(2) << (int)color.
r()
132 << setw(2) << (int)color.
g()
133 << setw(2) << (int)color.
b()
134 << setw(2) << (int)color.
a();
135 out << dec << setfill(
' ');
144 if(in.get() ==
'#') {
147 if(tmp.length() == 6 || tmp.length() == 8) {
151 if(tmp.length() == 8)
156 in.seekg(-(std::istream::streampos)tmp.length()-1, ios_base::cur);
163 }
else if(tmp ==
"black") {
165 }
else if(tmp ==
"white") {
167 }
else if(tmp ==
"red") {
169 }
else if(tmp ==
"darkRed") {
171 }
else if(tmp ==
"green") {
173 }
else if(tmp ==
"darkGreen") {
175 }
else if(tmp ==
"blue") {
177 }
else if(tmp ==
"darkBlue") {
179 }
else if(tmp ==
"pink") {
181 }
else if(tmp ==
"darkPink") {
183 }
else if(tmp ==
"yellow") {
185 }
else if(tmp ==
"darkYellow") {
187 }
else if(tmp ==
"teal") {
189 }
else if(tmp ==
"darkTeal") {
191 }
else if(tmp ==
"gray") {
193 }
else if(tmp ==
"darkGray") {
195 }
else if(tmp ==
"lightGray") {
197 }
else if(tmp ==
"orange") {
200 in.seekg(-tmp.length(), ios_base::cur);
static const Color lightGray
Color & operator=(uint32_t rgba)
bool operator!=(const Color &other) const
void setRGBA(uint8 r, uint8 g, uint8 b, uint8 a=0xFF)
Color operator+(const Color &other) const
void setRGBA(uint32 rgba)
std::istream & operator>>(std::istream &in, Color &color)
Color(float r, float g, float b, float a=1.0f)
static const Color darkRed
static const Color orange
static const Color darkPink
static const Color darkGreen
static const Color darkBlue
Color(uint8 r, uint8 g, uint8 b, uint8 a=0xFF)
static const Color darkGray
uint64_t hex_to_dec(const std::string &str)
Color(int r, int g, int b, int a=0xFF)
Color operator/(float v) const
static const Color darkYellow
static const Color darkTeal
bool operator==(const Color &other) const
static Color from8bit(int color)
static uint8 to8bit(const Color &color)
Color operator*(float v) const
bool operator==(uint32_t rgba) const
std::ostream & operator<<(std::ostream &out, const Color &color)
static const Color yellow
Color & operator=(const Color &other)
Color operator-(const Color &other) const