Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/gui/color_mode.h
9902 views
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
#pragma once
32
33
#include "scene/gui/color_picker.h"
34
35
class GradientTexture2D;
36
37
class ColorMode {
38
public:
39
ColorPicker *color_picker = nullptr;
40
41
virtual String get_name() const = 0;
42
43
virtual int get_slider_count() const { return 3; }
44
virtual float get_slider_step() const = 0;
45
virtual float get_spinbox_arrow_step() const { return get_slider_step(); }
46
virtual String get_slider_label(int idx) const = 0;
47
virtual float get_slider_max(int idx) const = 0;
48
virtual bool get_allow_greater() const { return false; }
49
virtual float get_slider_value(int idx) const = 0;
50
51
virtual float get_alpha_slider_max() const { return 255.0; }
52
virtual float get_alpha_slider_value() const { return color_picker->get_pick_color().a * 255.0; }
53
54
virtual Color get_color() const = 0;
55
56
virtual void _value_changed() {}
57
virtual void _greater_value_inputted() {}
58
59
virtual void slider_draw(int p_which) = 0;
60
61
ColorMode(ColorPicker *p_color_picker);
62
virtual ~ColorMode() {}
63
};
64
65
class ColorModeHSV : public ColorMode {
66
public:
67
String labels[3] = { "H", "S", "V" };
68
float slider_max[3] = { 359, 100, 100 };
69
float cached_hue = 0.0;
70
float cached_saturation = 0.0;
71
72
virtual String get_name() const override { return "HSV"; }
73
74
virtual float get_slider_step() const override { return 1.0; }
75
virtual String get_slider_label(int idx) const override;
76
virtual float get_slider_max(int idx) const override;
77
virtual float get_slider_value(int idx) const override;
78
79
virtual Color get_color() const override;
80
81
virtual void _value_changed() override;
82
83
virtual void slider_draw(int p_which) override;
84
85
ColorModeHSV(ColorPicker *p_color_picker) :
86
ColorMode(p_color_picker) {}
87
};
88
89
class ColorModeRGB : public ColorMode {
90
public:
91
String labels[3] = { "R", "G", "B" };
92
Ref<GradientTexture2D> rgb_texture[3];
93
94
virtual String get_name() const override { return "RGB"; }
95
96
virtual float get_slider_step() const override { return 1; }
97
virtual String get_slider_label(int idx) const override;
98
virtual float get_slider_max(int idx) const override { return 255; }
99
virtual bool get_allow_greater() const override { return true; }
100
virtual float get_slider_value(int idx) const override;
101
102
virtual Color get_color() const override;
103
104
virtual void _greater_value_inputted() override;
105
106
virtual void slider_draw(int p_which) override;
107
108
ColorModeRGB(ColorPicker *p_color_picker) :
109
ColorMode(p_color_picker) {}
110
};
111
112
class ColorModeLinear : public ColorMode {
113
public:
114
String labels[3] = { "R", "G", "B" };
115
float slider_max[3] = { 1, 1, 1 };
116
Ref<GradientTexture2D> rgb_texture[3];
117
118
virtual String get_name() const override { return ETR("Linear"); }
119
120
virtual float get_slider_step() const override { return 0.001; }
121
virtual float get_spinbox_arrow_step() const override { return 0.01; }
122
virtual String get_slider_label(int idx) const override;
123
virtual float get_slider_max(int idx) const override;
124
virtual bool get_allow_greater() const override { return true; }
125
virtual float get_slider_value(int idx) const override;
126
127
virtual float get_alpha_slider_max() const override;
128
virtual float get_alpha_slider_value() const override;
129
130
virtual Color get_color() const override;
131
132
virtual void _greater_value_inputted() override;
133
134
virtual void slider_draw(int p_which) override;
135
136
ColorModeLinear(ColorPicker *p_color_picker) :
137
ColorMode(p_color_picker) {}
138
};
139
140
class ColorModeOKHSL : public ColorMode {
141
public:
142
String labels[3] = { "H", "S", "L" };
143
float slider_max[3] = { 359, 100, 100 };
144
float cached_hue = 0.0;
145
float cached_saturation = 0.0;
146
Ref<GradientTexture2D> hue_texture;
147
148
virtual String get_name() const override { return "OKHSL"; }
149
150
virtual float get_slider_step() const override { return 1.0; }
151
virtual String get_slider_label(int idx) const override;
152
virtual float get_slider_max(int idx) const override;
153
virtual float get_slider_value(int idx) const override;
154
155
virtual Color get_color() const override;
156
157
virtual void _value_changed() override;
158
159
virtual void slider_draw(int p_which) override;
160
161
ColorModeOKHSL(ColorPicker *p_color_picker) :
162
ColorMode(p_color_picker) {}
163
};
164
165