color_picker.h
1 /*************************************************************************/
2 /* color_picker.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef COLOR_PICKER_H
30 #define COLOR_PICKER_H
31 
32 #include "scene/gui/slider.h"
33 #include "scene/gui/line_edit.h"
34 #include "scene/gui/spin_box.h"
35 #include "scene/gui/label.h"
36 #include "scene/gui/button.h"
37 #include "scene/gui/popup.h"
38 #include "scene/gui/box_container.h"
39 #include "scene/gui/texture_frame.h"
40 #include "scene/gui/tool_button.h"
41 #include "scene/gui/check_button.h"
42 #include "scene/resources/material.h"
43 
44 class ColorPicker : public BoxContainer {
45 
46  OBJ_TYPE(ColorPicker,BoxContainer);
47 
48 private:
49 
50  Control *screen;
51  Image last_capture;
52  TextureFrame *uv_edit;
53  TextureFrame *w_edit;
54  TextureFrame *sample;
55  TextureFrame *preset;
56  Button *bt_add_preset;
57  List<Color> presets;
58  ToolButton *btn_pick;
59  CheckButton *btn_mode;
60  Ref<CanvasItemMaterial> uv_material;
61  Ref<CanvasItemMaterial> w_material;
62  HSlider *scroll[4];
63  SpinBox *values[4];
64  Label *labels[4];
65  Button *text_type;
66  LineEdit *c_text;
67  bool edit_alpha;
68  Size2i ms;
69  bool text_is_constructor;
70 
71  Color color;
72  bool raw_mode_enabled;
73  bool updating;
74  bool changing_color;
75  float h,s,v;
76  Color last_hsv;
77 
78  void _html_entered(const String& p_html);
79  void _value_changed(double);
80  void _update_controls();
81  void _update_color();
82  void _update_presets();
83  void _text_type_toggled();
84  void _sample_draw();
85  void _hsv_draw(int p_wich,Control *c);
86 
87  void _uv_input(const InputEvent& p_input);
88  void _w_input(const InputEvent& p_input);
89  void _preset_input(const InputEvent& p_input);
90  void _screen_input(const InputEvent& p_input);
91  void _add_preset_pressed();
92  void _screen_pick_pressed();
93 
94 protected:
95 
96  void _notification(int);
97  static void _bind_methods();
98 public:
99 
100  void set_edit_alpha(bool p_show);
101  bool is_editing_alpha() const;
102 
103  void set_color(const Color& p_color);
104  Color get_color() const;
105 
106  void add_preset(const Color& p_color);
107  void set_raw_mode(bool p_enabled);
108  bool is_raw_mode() const;
109 
110 
111  ColorPicker();
112 };
113 
114 class ColorPickerButton : public Button {
115 
116  OBJ_TYPE(ColorPickerButton,Button);
117 
118  PopupPanel *popup;
119  ColorPicker *picker;
120 
121  void _color_changed(const Color& p_color);
122  virtual void pressed();
123 
124 protected:
125 
126  void _notification(int);
127  static void _bind_methods();
128 public:
129 
130  void set_color(const Color& p_color);
131  Color get_color() const;
132 
133  void set_edit_alpha(bool p_show);
134  bool is_editing_alpha() const;
135 
136  ColorPicker *get_picker();
137 
139 };
140 
141 #endif // COLOR_PICKER_H
Definition: color_picker.h:114
Definition: math_2d.h:369
Definition: check_button.h:37
Definition: color.h:37
Definition: image.h:47
Definition: slider.h:75
Definition: color_picker.h:44
Definition: input_event.h:263
Definition: texture_frame.h:36
Definition: spin_box.h:36
Definition: popup.h:74
Definition: box_container.h:34
Definition: tool_button.h:34
Definition: control.h:47
Definition: ustring.h:64
Definition: button.h:36
Definition: line_edit.h:36
Definition: label.h:36