1 | /**************************************************************************/ |
2 | /* color_mode.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #ifndef COLOR_MODE_H |
32 | #define COLOR_MODE_H |
33 | |
34 | #include "scene/gui/color_picker.h" |
35 | |
36 | struct Color; |
37 | |
38 | class ColorMode { |
39 | public: |
40 | ColorPicker *color_picker = nullptr; |
41 | |
42 | virtual String get_name() const = 0; |
43 | |
44 | virtual int get_slider_count() const { return 3; }; |
45 | virtual float get_slider_step() const = 0; |
46 | virtual String get_slider_label(int idx) const = 0; |
47 | virtual float get_slider_max(int idx) const = 0; |
48 | virtual float get_slider_value(int idx) const = 0; |
49 | |
50 | virtual Color get_color() const = 0; |
51 | |
52 | virtual void _value_changed(){}; |
53 | |
54 | virtual void slider_draw(int p_which) = 0; |
55 | virtual bool apply_theme() const { return false; } |
56 | virtual ColorPicker::PickerShapeType get_shape_override() const { return ColorPicker::SHAPE_MAX; } |
57 | |
58 | ColorMode(ColorPicker *p_color_picker); |
59 | virtual ~ColorMode(){}; |
60 | }; |
61 | |
62 | class ColorModeHSV : public ColorMode { |
63 | public: |
64 | String labels[3] = { "H" , "S" , "V" }; |
65 | float slider_max[4] = { 359, 100, 100, 255 }; |
66 | float cached_hue = 0.0; |
67 | float cached_saturation = 0.0; |
68 | |
69 | virtual String get_name() const override { return "HSV" ; } |
70 | |
71 | virtual float get_slider_step() const override { return 1.0; } |
72 | virtual String get_slider_label(int idx) const override; |
73 | virtual float get_slider_max(int idx) const override; |
74 | virtual float get_slider_value(int idx) const override; |
75 | |
76 | virtual Color get_color() const override; |
77 | |
78 | virtual void _value_changed() override; |
79 | |
80 | virtual void slider_draw(int p_which) override; |
81 | |
82 | ColorModeHSV(ColorPicker *p_color_picker) : |
83 | ColorMode(p_color_picker){}; |
84 | }; |
85 | |
86 | class ColorModeRGB : public ColorMode { |
87 | public: |
88 | String labels[3] = { "R" , "G" , "B" }; |
89 | |
90 | virtual String get_name() const override { return "RGB" ; } |
91 | |
92 | virtual float get_slider_step() const override { return 1; } |
93 | virtual String get_slider_label(int idx) const override; |
94 | virtual float get_slider_max(int idx) const override; |
95 | virtual float get_slider_value(int idx) const override; |
96 | |
97 | virtual Color get_color() const override; |
98 | |
99 | virtual void slider_draw(int p_which) override; |
100 | |
101 | ColorModeRGB(ColorPicker *p_color_picker) : |
102 | ColorMode(p_color_picker){}; |
103 | }; |
104 | |
105 | class ColorModeRAW : public ColorMode { |
106 | public: |
107 | String labels[3] = { "R" , "G" , "B" }; |
108 | float slider_max[4] = { 100, 100, 100, 1 }; |
109 | |
110 | virtual String get_name() const override { return "RAW" ; } |
111 | |
112 | virtual float get_slider_step() const override { return 0.01; } |
113 | virtual String get_slider_label(int idx) const override; |
114 | virtual float get_slider_max(int idx) const override; |
115 | virtual float get_slider_value(int idx) const override; |
116 | |
117 | virtual Color get_color() const override; |
118 | |
119 | virtual void slider_draw(int p_which) override; |
120 | virtual bool apply_theme() const override; |
121 | |
122 | ColorModeRAW(ColorPicker *p_color_picker) : |
123 | ColorMode(p_color_picker){}; |
124 | }; |
125 | |
126 | class ColorModeOKHSL : public ColorMode { |
127 | public: |
128 | String labels[3] = { "H" , "S" , "L" }; |
129 | float slider_max[4] = { 359, 100, 100, 255 }; |
130 | float cached_hue = 0.0; |
131 | float cached_saturation = 0.0; |
132 | |
133 | virtual String get_name() const override { return "OKHSL" ; } |
134 | |
135 | virtual float get_slider_step() const override { return 1.0; } |
136 | virtual String get_slider_label(int idx) const override; |
137 | virtual float get_slider_max(int idx) const override; |
138 | virtual float get_slider_value(int idx) const override; |
139 | |
140 | virtual Color get_color() const override; |
141 | |
142 | virtual void _value_changed() override; |
143 | |
144 | virtual void slider_draw(int p_which) override; |
145 | virtual ColorPicker::PickerShapeType get_shape_override() const override { return ColorPicker::SHAPE_OKHSL_CIRCLE; } |
146 | |
147 | ColorModeOKHSL(ColorPicker *p_color_picker) : |
148 | ColorMode(p_color_picker){}; |
149 | |
150 | ~ColorModeOKHSL(){}; |
151 | }; |
152 | |
153 | #endif // COLOR_MODE_H |
154 | |