My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
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
#ifdef PLATFORM_WIN32
struct RGBA : Moveable<RGBA> {
byte b, g, r, a;
};
#endif

#ifdef PLATFORM_POSIX
#ifdef CPU_BE
struct RGBA : Moveable<RGBA> {
byte a, r, g, b;
};
#else
struct RGBA : Moveable<RGBA> {
byte b, g, r, a;
};
#endif
#endif

#ifndef PLATFORM_WIN32
inline int GetRValue(dword c) { return (byte)(c >> 0); }
inline int GetGValue(dword c) { return (byte)(c >> 8); }
inline int GetBValue(dword c) { return (byte)(c >> 16); }
inline dword RGB(byte r, byte g, byte b) { return r | (g << 8) | (b << 16); }
#endif

const int COLOR_V = 39;

class Color : public ValueType<Color, COLOR_V, Moveable<Color> > {
protected:
dword color;

dword Get() const;

public:
dword GetRaw() const { return color; }

int GetR() const { return GetRValue(Get()); }
int GetG() const { return GetGValue(Get()); }
int GetB() const { return GetBValue(Get()); }

void SetNull() { color = 0xffffffff; }
bool IsNullInstance() const { return color == 0xffffffff; }
unsigned GetHashValue() const { return color; }
bool operator==(Color c) const { return color == c.color; }
bool operator!=(Color c) const { return color != c.color; }

void Serialize(Stream& s) { s % color; }
void Jsonize(JsonIO& jio);
void Xmlize(XmlIO& xio);

Color() { SetNull(); }
Color(int r, int g, int b) { color = RGB(r, g, b); }
Color(int n, int) { color = 0x80000000 | n; }

Color(const Nuller&) { SetNull(); }

#ifdef SVO_VALUE
operator Value() const { return SvoToValue(*this); }
Color(const Value& q) { color = q.Get<Color>().color; }
#else
operator Value() const { return RichValue<Color>(*this); }
Color(const Value& q) { color = RichValue<Color>::Extract(q).color; }
#endif

operator RGBA() const;
Color(RGBA rgba);

Color(Color (*fn)()) { color = (*fn)().color; }

static Color FromRaw(dword co) { Color c; c.color = co; return c; }

#ifdef PLATFORM_WIN32
operator COLORREF() const { return (COLORREF) Get(); }
static Color FromCR(COLORREF cr) { Color c; c.color = (dword)cr; return c; }
#else
operator dword() const { return Get(); }
#endif
};

RGBA operator*(int alpha, Color c);

inline Color StraightColor(RGBA rgba) { return Color(rgba.r, rgba.g, rgba.b); }

typedef Color (*ColorF)();

inline unsigned GetHashValue(Color c) { return c.GetHashValue(); }
inline Color Nvl(Color a, Color b) { return IsNull(a) ? b : a; }

template<>
String AsString(const Color& c);


inline Color GrayColor(int a = 128) { return Color(a, a, a); }

inline Color Black() { return Color(0, 0, 0); }
inline Color Gray() { return Color(128, 128, 128); }
inline Color LtGray() { return Color(192, 192, 192); }
inline Color WhiteGray() { return Color(224, 224, 224); }
inline Color White() { return Color(255, 255, 255); }

inline Color Red() { return Color(128, 0, 0); }
inline Color Green() { return Color(0, 128, 0); }
inline Color Brown() { return Color(128, 128, 0); }
inline Color Blue() { return Color(0, 0, 128); }
inline Color Magenta() { return Color(128, 0, 255); }
inline Color Cyan() { return Color(0, 128, 128); }
inline Color Yellow() { return Color(255, 255, 0); }
inline Color LtRed() { return Color(255, 0, 0); }
inline Color LtGreen() { return Color(0, 255, 0); }
inline Color LtYellow() { return Color(255, 255, 192); }
inline Color LtBlue() { return Color(0, 0, 255); }
inline Color LtMagenta() { return Color(255, 0, 255); }
inline Color LtCyan() { return Color(0, 255, 255); }

void RGBtoHSV(double r, double g, double b, double& h, double& s, double& v);
void HSVtoRGB(double h, double s, double v, double& r, double& g, double& b);

Color HsvColorf(double h, double s, double v);

Color Blend(Color c1, Color c2, int alpha = 128);

String ColorToHtml(Color color);

int Grayscale(const Color& c);
bool IsDark(Color c);


inline bool operator==(const Value& v, Color x) { return v == x.operator Value(); }
inline bool operator==(Color x, const Value& v) { return v == x.operator Value(); }
inline bool operator!=(const Value& v, Color x) { return v != x.operator Value(); }
inline bool operator!=(Color x, const Value& v) { return v != x.operator Value(); }

inline bool operator==(const Value& v, Color (*x)()) { return v == (*x)(); }
inline bool operator==(Color (*x)(), const Value& v) { return v == (*x)(); }
inline bool operator!=(const Value& v, Color (*x)()) { return v != (*x)(); }
inline bool operator!=(Color (*x)(), const Value& v) { return v != (*x)(); }

inline bool operator==(Color c, Color (*x)()) { return c == (*x)(); }
inline bool operator==(Color (*x)(), Color c) { return c == (*x)(); }
inline bool operator!=(Color c, Color (*x)()) { return c != (*x)(); }
inline bool operator!=(Color (*x)(), Color c) { return c != (*x)(); }

Change log

r4950 by cxl on May 14, 2012   Diff
Draw: Font, Drawing, Painting, Image now
support Xmlize and Jsonize
Go to: 
Project members, sign in to write a code review

Older revisions

r4674 by cxl on Mar 10, 2012   Diff
Core: some Xmlization moved to rich
Value types
r4654 by cxl on Mar 3, 2012   Diff
Core: Jsonize finished
r4647 by cxl on Mar 3, 2012   Diff
.developing SvoValue
All revisions of this file

File info

Size: 5163 bytes, 141 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting