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
|
#pragma once
#include"Batzer2D.hpp"
namespace b2d
{
class DLL Color
{
public:
//colorvalues red, green, blue, alpha
BYTE r, g, b, a;
//std ctor
Color() : r(255), g(255), b(255), a(255) {}
//assume colorvalues from another Color-object
Color(const Color& c) : r(c.r), g(c.g), b(c.b), a(c.a) {}
//set red, green, blue to the same value; alpha = 255
Color(const BYTE c) : r(c), g(c), b(c), a(255) {}
//set red, green, blue saparatly; alpha = 255
Color(const BYTE r, const BYTE g, const BYTE b) : r(r), g(g), b(b), a(255) {}
//set red, green, blue, alpha saparatly
Color(const BYTE r, const BYTE g, const BYTE b, const BYTE a) : r(r), g(g), b(b), a(a) {}
//casting operators
operator DWORD () const
{
return (static_cast<DWORD>(r) | static_cast<DWORD>(g) | static_cast<DWORD>(b) | static_cast<DWORD>(a));
}
//allocation operators
Color& operator = (const Color& c) { r = c.r; g = c.g; b = c.b; a = c.a; return(*this); }
Color& operator += (const Color& c) { r += c.r; g += c.g; b += c.b; a += c.a; return(*this); }
Color& operator -= (const Color& c) { r -= c.r; g -= c.g; b -= c.b; a -= c.a; return(*this); }
Color& operator *= (const Color& c) { r *= c.r; g *= c.g; b *= c.b; a *= c.a; return(*this); }
Color& operator /= (const Color& c) { r /= c.r; g /= c.g; b /= c.b; a /= c.a; return(*this); }
//comparision operator
bool operator == (const Color& c) const { return(r == c.r && g == c.g && b == c.b && c.a == a); }
bool operator != (const Color& c) const { return(r != c.r || g != c.g || b != c.b || c.a != a); }
//predefined colors
static const Color Black;
static const Color White;
static const Color Red;
static const Color Blue;
static const Color Green;
static const Color Yellow;
static const Color Magenta;
static const Color Cyan;
};
//arithmetic operators
inline Color operator + (const Color& c1, const Color& c2) { return( Color(c1.r+c2.r, c1.g+c2.g, c1.b+c2.b, c1.a+c2.a) ); }
inline Color operator - (const Color& c1, const Color& c2) { return( Color(c1.r-c2.r, c1.g-c2.g, c1.b-c2.b, c1.a-c2.a) ); }
inline Color operator * (const Color& c1, const Color& c2) { return( Color(c1.r*c2.r, c1.g*c2.g, c1.b*c2.b, c1.a*c2.a) ); }
inline Color operator / (const Color& c1, const Color& c2) { return( Color(c1.r/c2.r, c1.g/c2.g, c1.b/c2.b, c1.a/c2.a) ); }
}
|