GG: ColorDlg.h Source File

GG

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

ColorDlg.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /* GG is a GUI for SDL and OpenGL.
3 Copyright (C) 2003-2008 T. Zachary Laine
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License
7 as published by the Free Software Foundation; either version 2.1
8 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA
19
20 If you do not wish to comply with the terms of the LGPL please
21 contact the author as other terms are available for a fee.
22
23 Zach Laine
24 whatwasthataddress@gmail.com */
25
29 #ifndef _GG_ColorDlg_h_
30 #define _GG_ColorDlg_h_
31
32 #include <GG/Button.h>
33 #include <GG/ClrConstants.h>
34
35
36 namespace GG {
37
38 class Font;
39 template <class T>
40 class Slider;
41
45 struct GG_API HSVClr
46 {
47 HSVClr();
48 HSVClr(double h_, double s_, double v_, GLubyte a_ = 255);
49 double h;
50 double s;
51 double v;
52 GLubyte a;
53 };
54
58 class GG_API HueSaturationPicker : public Control
59 {
60 public:
62 typedef boost::signal<void (double, double)> ChangedSignalType;
63
64
66 HueSaturationPicker(X x, Y y, X w, Y h);
67
68
70 virtual void Render();
71 virtual void LButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
72 virtual void LDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
73
74 void SetHueSaturation(double hue, double saturation);
75
76
77 mutable ChangedSignalType ChangedSignal;
78
79 protected:
81 HueSaturationPicker();
82
83
84 private:
85 void SetHueSaturationFromPt(Pt pt);
86
87 double m_hue;
88 double m_saturation;
89 std::vector<std::vector<std::pair<double, double> > > m_vertices;
90 std::vector<std::vector<Clr> > m_colors;
91 };
92
93
96 class GG_API ValuePicker : public Control
97 {
98 public:
100 typedef boost::signal<void (double)> ChangedSignalType;
101
102
104 ValuePicker(X x, Y y, X w, Y h, Clr arrow_color);
105
106
108 virtual void Render();
109 virtual void LButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
110 virtual void LDrag(const Pt& pt, const Pt& move, Flags<ModKey> mod_keys);
111
114 void SetHueSaturation(double hue, double saturation);
115 void SetValue(double value);
116
117
118 mutable ChangedSignalType ChangedSignal;
119
120 protected:
122 ValuePicker();
123
124
125 private:
126 void SetValueFromPt(Pt pt);
127
128 double m_hue;
129 double m_saturation;
130 double m_value;
131
132 Clr m_arrow_color;
133 };
134
135
143 class GG_API ColorDlg : public Wnd
144 {
145 public:
147 class GG_API ColorButton : public Button
148 {
149 public:
151 ColorButton(const Clr& color);
153
155
156 Clr RepresentedColor() const;
158
160
161 void SetRepresentedColor(const Clr& color);
163
164 protected:
166 ColorButton();
167
168
170 virtual void RenderUnpressed();
171 virtual void RenderPressed();
172 virtual void RenderRollover();
174
175 private:
176 Clr m_represented_color;
177 };
178
185 class GG_API ColorDisplay : public Control
186 {
187 public:
189 ColorDisplay(Clr color);
190
191
193 virtual void Render();
195
196 protected:
198 ColorDisplay();
199
200 };
201
203
204 ColorDlg(X x, Y y, const boost::shared_ptr<Font>& font,
205 Clr dialog_color, Clr border_color, Clr text_color = CLR_BLACK);
206
208 ColorDlg(X x, Y y, Clr original_color, const boost::shared_ptr<Font>& font,
209 Clr dialog_color, Clr border_color, Clr text_color = CLR_BLACK);
211
213
216 bool ColorWasSelected() const;
217
219 Clr Result() const;
220
221 const std::string& NewString(const std::string& str) const;
222 const std::string& OldString(const std::string& str) const;
223 const std::string& RedString(const std::string& str) const;
224 const std::string& GreenString(const std::string& str) const;
225 const std::string& BlueString(const std::string& str) const;
226 const std::string& HueString(const std::string& str) const;
227 const std::string& SaturationString(const std::string& str) const;
228 const std::string& ValueString(const std::string& str) const;
229 const std::string& AlphaString(const std::string& str) const;
230 const std::string& OkString(const std::string& str) const;
231 const std::string& CancelString(const std::string& str) const;
232
233
235 void SetNewString(const std::string& str);
236 void SetOldString(const std::string& str);
237 void SetRedString(const std::string& str);
238 void SetGreenString(const std::string& str);
239 void SetBlueString(const std::string& str);
240 void SetHueString(const std::string& str);
241 void SetSaturationString(const std::string& str);
242 void SetValueString(const std::string& str);
243 void SetAlphaString(const std::string& str);
244 void SetOkString(const std::string& str);
245 void SetCancelString(const std::string& str);
246
247 virtual void Render();
248 virtual void KeyPress(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
250
251 static const std::size_t INVALID_COLOR_BUTTON;
252
253 protected:
255 ColorDlg();
256
257
258 private:
259 struct ColorButtonClickFunctor
260 {
261 ColorButtonClickFunctor(std::size_t id, ColorDlg* picker_);
262 void operator()();
263 const std::size_t button_id;
264 ColorDlg* picker;
265 };
266
267 enum {R, G, B, A, H, S, V};
268
269 void Init(const boost::shared_ptr<Font>& font);
270 void ConnectSignals();
271 void ColorChanged(HSVClr color);
272 void HueSaturationPickerChanged(double hue, double saturation);
273 void ValuePickerChanged(double value);
274 void UpdateRGBSliders();
275 void UpdateHSVSliders();
276 void ColorChangeFromRGBSlider();
277 void ColorButtonClicked(std::size_t i);
278 void RedSliderChanged(int value, int low, int high);
279 void GreenSliderChanged(int value, int low, int high);
280 void BlueSliderChanged(int value, int low, int high);
281 void AlphaSliderChanged(int value, int low, int high);
282 void HueSliderChanged(int value, int low, int high);
283 void SaturationSliderChanged(int value, int low, int high);
284 void ValueSliderChanged(int value, int low, int high);
285 void OkClicked();
286 void CancelClicked();
287
288 HSVClr m_current_color;
289 Clr m_original_color;
290 bool m_original_color_specified;
291 bool m_color_was_picked;
292
293 std::string m_new_str;
294 std::string m_old_str;
295 std::string m_red_str;
296 std::string m_green_str;
297 std::string m_blue_str;
298 std::string m_hue_str;
299 std::string m_saturation_str;
300 std::string m_value_str;
301 std::string m_alpha_str;
302 std::string m_ok_str;
303 std::string m_cancel_str;
304
305 HueSaturationPicker* m_hue_saturation_picker;
306 ValuePicker* m_value_picker;
307 Layout* m_pickers_layout;
308 ColorDisplay* m_new_color_square;
309 ColorDisplay* m_old_color_square;
310 TextControl* m_new_color_square_text;
311 TextControl* m_old_color_square_text;
312 Layout* m_color_squares_layout;
313 std::vector<ColorButton*> m_color_buttons;
314 Layout* m_color_buttons_layout;
315 std::size_t m_current_color_button;
316 std::vector<TextControl*> m_slider_labels;
317 std::vector<TextControl*> m_slider_values;
318 std::vector<Slider<int>*> m_sliders;
319 Button* m_ok;
320 Button* m_cancel;
321 Layout* m_sliders_ok_cancel_layout;
322
323 Clr m_color;
324 Clr m_border_color;
325 Clr m_text_color;
326
327 static std::vector<Clr> s_custom_colors;
328
329 friend struct ColorButtonClickFunctor;
330 };
331
332 } // namespace GG
333
334 #endif