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
|
#include "color.hpp"
namespace graphics
{
Color::Color(unsigned char r1, unsigned char g1, unsigned char b1, unsigned char a1)
: r(r1), g(g1), b(b1), a(a1)
{}
Color::Color() : r(0), g(0), b(0), a(0)
{}
Color::Color(Color const & c)
{
r = c.r;
g = c.g;
b = c.b;
a = c.a;
}
Color const & Color::operator=(Color const & c)
{
if (&c != this)
{
r = c.r;
g = c.g;
b = c.b;
a = c.a;
}
return *this;
}
Color const Color::fromXRGB(uint32_t _c, unsigned char _a)
{
return Color(
redFromARGB(_c),
greenFromARGB(_c),
blueFromARGB(_c),
_a);
}
Color const Color::fromARGB(uint32_t _c)
{
return Color(
redFromARGB(_c),
greenFromARGB(_c),
blueFromARGB(_c),
alphaFromARGB(_c));
}
Color const & Color::operator /= (unsigned k)
{
r /= k;
g /= k;
b /= k;
a /= k;
return *this;
}
bool operator < (Color const & l, Color const & r)
{
if (l.r != r.r) return l.r < r.r;
if (l.g != r.g) return l.g < r.g;
if (l.b != r.b) return l.b < r.b;
if (l.a != r.a) return l.a < r.a;
return false;
}
bool operator > (Color const & l, Color const & r)
{
if (l.r != r.r) return l.r > r.r;
if (l.g != r.g) return l.g > r.g;
if (l.b != r.b) return l.b > r.b;
if (l.a != r.a) return l.a > r.a;
return false;
}
bool operator != (Color const & l, Color const & r)
{
return (l.r != r.r) || (l.g != r.g) || (l.b != r.b) || (l.a != r.a);
}
bool operator == (Color const & l, Color const & r)
{
return !(l != r);
}
Color Color::Black()
{
return Color(0, 0, 0, 255);
}
Color Color::White()
{
return Color(255, 255, 255, 255);
}
}
|