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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#ifndef __CtrlLib_DlgColor__
#define __CtrlLib_DlgColor__

class WheelRampCtrl : public Ctrl
{
public:
WheelRampCtrl(bool ramp);
~WheelRampCtrl();

virtual void Layout();
virtual void Paint(Draw& draw);
virtual void SetData(const Value& value);
virtual Value GetData() const { return color; }

virtual void LeftDown(Point pt, dword keyflags);
virtual void LeftUp(Point pt, dword keyflags);
virtual void LeftDouble(Point pt, dword keyflags);
virtual void MouseMove(Point pt, dword keyflags);

Callback WhenLeftDouble;

private:
void SetColor(Color color, bool set_norm, bool set_hsv);

Image PaintRamp(Size size);
Image PaintWheel(Size size);
void PaintColumn(Draw& draw);

int ClientToLevel(int y) const;
int LevelToClient(int l) const;

private:
// double gamma;
bool ramp;
Color color;
Color normalized_color;
int h16, s16, v16;
int round_step;
int wheel_style;
enum STYLE { S_WHEEL, S_RECT, S_HEXAGON };
STYLE style;
Image cache;
int cache_level;
Image wheel_cache;
Rect wheel_rect;
Rect column_rect;

int firstclick;

struct WheelBuff
{
int arg;
int l;
};
};

struct ColorWheelCtrl : public WheelRampCtrl {
ColorWheelCtrl() : WheelRampCtrl(false) {}
};

struct ColorRampCtrl : public WheelRampCtrl {
ColorRampCtrl() : WheelRampCtrl(true) {}
};

class ColorSelector : public Ctrl
{
public:
ColorSelector(bool not_null = true);

ColorSelector& NotNull(bool nn = true) { impl->NotNull(nn); return *this; }
ColorSelector& NoNotNull() { return NotNull(false); }
bool IsNotNull() const { return impl->IsNotNull(); }

Color Get() const { return impl->Get(); }
void Set(Color c) { impl->Set(c); }

Vector<Color> GetPalette() const { return impl->GetPalette(); }
void SetPalette(const Vector<Color>& palette) { impl->SetPalette(palette); }

void SerializeConfig(Stream& stream) { impl->SerializeConfig(stream); }

virtual void SetData(const Value& color) { Set(color); }
virtual Value GetData() const { return Get(); }

Ctrl& GetImplCtrl() { return impl->GetCtrl(); }

public:
Callback WhenSetColor;

public:
class Impl
{
public:
virtual ~Impl() {}

virtual void Set(Color c) = 0;
virtual Color Get() const = 0;
virtual void NotNull(bool nn) = 0;
virtual bool IsNotNull() const = 0;
virtual Vector<Color> GetPalette() const = 0;
virtual void SetPalette(const Vector<Color>& pal) = 0;
virtual void SerializeConfig(Stream& stream) = 0;
virtual Ctrl& GetCtrl() = 0;

protected:
Impl() {}
};

protected:
One<Impl> impl;
};

class ColorCtrl : public DataPusher
{
public:
typedef ColorCtrl CLASSNAME;
ColorCtrl(bool not_null = true);
virtual ~ColorCtrl();

ColorCtrl& NotNull(bool _nn = true) { empty.Show(!_nn); return *this; }
ColorCtrl& NoNotNull() { return NotNull(false); }
bool IsNotNull() const { return !empty.IsVisible(); }

protected:
virtual void DoAction();
void OnClear() { SetDataAction(Null); }

protected:
FrameRight<Button> empty;
};

Color RunDlgSelectColor(Color init_color = Black, bool not_null = true, const char *title = 0, bool *ok = 0);
const Display& StdColorDisplayNull();

class ColorPopUp : public Ctrl {
public:
virtual void Paint(Draw& w);
virtual void LeftUp(Point p, dword);
virtual void LeftDown(Point p, dword);
virtual void MouseMove(Point p, dword);
virtual void MouseLeave();
virtual bool Key(dword key, int count);

private:
void PopupDeactivate();

struct Popup : Ctrl {
ColorPopUp *color;

virtual void Deactivate() { color->PopupDeactivate(); }
};

int Get(Point p);
int GetCy();
void Setup(Color c);
void Finish();
void Ramp();
void Wheel();
int GetColorCount() const;
Color GetColor(int i) const;
void Select();

void DrawFilledFrame(Draw &w, int x, int y, int cx, int cy, Color fcol, Color bcol);
void DrawFilledFrame(Draw &w, Rect &r, Color fcol, Color bcol);

int colori;
bool notnull;
bool scolors;
bool norampwheel;
bool animating;
bool hints;
bool open;
String nulltext;
Color color;

ColorRampCtrl ramp;
ColorWheelCtrl wheel;
One<Popup> popup;

static Color hint[18];

friend void ColorPopUp_InitHint();

public:
Callback WhenCancel;
Callback WhenSelect;

static void Hint(Color c);

typedef ColorPopUp CLASSNAME;

void PopUp(Ctrl *owner, Color c = White);
Color Get() const;

ColorPopUp& NotNull(bool b = true) { notnull = b; return *this; }
ColorPopUp& SColors(bool b = true) { scolors = b; return *this; }//Deprecated
ColorPopUp& NullText(const char *s) { nulltext = s; Refresh(); return *this; }
ColorPopUp& NoRampWheel(bool b = true) { norampwheel = b; return *this; }
ColorPopUp& Hints(bool b = true) { hints = b; return *this; }

ColorPopUp();
virtual ~ColorPopUp();
};

class ColorPusher : public Ctrl {
public:
virtual void Paint(Draw& w);
virtual void LeftDown(Point p, dword);
virtual bool Key(dword key, int);
virtual void GotFocus() { Refresh(); }
virtual void LostFocus() { Refresh(); }
virtual void SetData(const Value& v);
virtual Value GetData() const;

protected:
bool push;
bool withtext;
bool track;
Color color, saved_color;
ColorPopUp colors;
String nulltext;

void AcceptColors();
void CloseColors();
void NewColor();
void Drop();

public:
typedef ColorPusher CLASSNAME;

ColorPusher& NullText(const char *s) { nulltext = s; colors.NullText(s); Refresh(); return *this; }
ColorPusher& NotNull(bool b = true) { colors.NotNull(b); return *this; }
ColorPusher& SColors(bool b = true) { colors.SColors(b); return *this; }
ColorPusher& WithText() { withtext = true; return *this; }
ColorPusher& Track(bool b = true) { track = b; return *this; }
ColorPusher& NoTrack() { return Track(false); }
ColorPusher& NoRampWheel(bool b = true) { colors.NoRampWheel(b); return *this; }

ColorPusher();
virtual ~ColorPusher();
};

class ColorButton : public ColorPusher {
public:
virtual void Paint(Draw& w);
virtual void MouseEnter(Point p, dword keyflags);
virtual void MouseLeave();
virtual Size GetMinSize() const;

protected:
Image image, nullimage, staticimage;
const ToolButton::Style *style;

public:
ColorButton& ColorImage(const Image& img) { image = img; Refresh(); return *this; }
ColorButton& NullImage(const Image& img) { nullimage = img; Refresh(); return *this; }
ColorButton& StaticImage(const Image& img) { staticimage = img; Refresh(); return *this; }
ColorButton& SetStyle(const ToolButton::Style& s) { style = &s; Refresh(); return *this; }

ColorButton();
virtual ~ColorButton();
};

String FormatColor(Color c);
Color ReadColor(CParser& p);
Color ColorFromText(const char *s);

#endif//__TCtrlLib_DlgColor__

Change log

r4307 by cxl on Dec 16, 2011   Diff
*CtrlLib: Fixed ColorPopUp issue in X11
Go to: 
Project members, sign in to write a code review

Older revisions

r3971 by cxl on Oct 8, 2011   Diff
CtrlLib: ColorPusher now supports hint
colors, based on colors previous set
to all instances of ColorPusher, also
if clipboard contains text with color
specification (either 3 decimal
...
r3815 by cxl on Sep 4, 2011   Diff
*ColorPopup: Fixed crashing in Linux
r3223 by cxl on Feb 18, 2011   Diff
CtrlLib: Improved ColorPopup animation
All revisions of this file

File info

Size: 7516 bytes, 268 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting