TGUI 1.13
Loading...
Searching...
No Matches
ColorPicker.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef TGUI_COLOR_PICKER_HPP
26#define TGUI_COLOR_PICKER_HPP
27
28#include <TGUI/Renderers/ColorPickerRenderer.hpp>
29#include <TGUI/Widgets/ChildWindow.hpp>
30#include <TGUI/Widgets/Panel.hpp>
31#include <TGUI/Widgets/Slider.hpp>
32
34
35namespace tgui
36{
40 class TGUI_API ColorPicker : public ChildWindow
41 {
42 public:
43 using Ptr = std::shared_ptr<ColorPicker>;
44 using ConstPtr = std::shared_ptr<const ColorPicker>;
45
46 static constexpr char StaticWidgetType[] = "ColorPicker";
47
55 explicit ColorPicker(const char* typeName = StaticWidgetType, bool initRenderer = true);
56
65 [[nodiscard]] static ColorPicker::Ptr create(const String& title = "", Color color = Color::Black);
66
70 ColorPicker(const ColorPicker& other);
71
75 ColorPicker(ColorPicker&& other) noexcept;
76
80 ColorPicker& operator=(const ColorPicker& other);
81
85 ColorPicker& operator=(ColorPicker&& other) noexcept;
86
94 [[nodiscard]] static ColorPicker::Ptr copy(const ColorPicker::ConstPtr& colorPicker);
95
100 [[nodiscard]] ColorPickerRenderer* getSharedRenderer() override;
101 [[nodiscard]] const ColorPickerRenderer* getSharedRenderer() const override;
102
108 [[nodiscard]] ColorPickerRenderer* getRenderer() override;
109
115 void setColor(const Color& color);
116
122 [[nodiscard]] Color getColor() const;
123
127 bool leftMousePressed(Vector2f pos) override;
128
132 void leftMouseButtonNoLongerDown() override;
133
137 void mouseMoved(Vector2f pos) override;
138
145 void draw(BackendRenderTarget& target, RenderStates states) const override;
146
148
149 protected:
151 // Makes sure all widgets lie within the window and places them on the correct position.
153 void rearrange();
154
164 [[nodiscard]] Signal& getSignal(String signalName) override;
165
171 void rendererChanged(const String& property) override;
172
176 [[nodiscard]] std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
177
181 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
182
184 // Makes a copy of the widget
186 [[nodiscard]] Widget::Ptr clone() const override;
187
189
190 private:
192 // Figure and connect signals of widgets
194 void identifyButtonsAndConnect();
195
197
198 public:
199 SignalColor onColorChange = {"ColorChanged"};
200 SignalColor onOkPress = {"OkPressed"};
201
203
204 protected:
205 Texture m_colorWheelTexture;
206 Sprite m_colorWheelSprite;
207
208 Slider::Ptr m_red = Slider::create(0, 255);
209 Slider::Ptr m_green = Slider::create(0, 255);
210 Slider::Ptr m_blue = Slider::create(0, 255);
211 Slider::Ptr m_alpha = Slider::create(0, 255);
212
213 Slider::Ptr m_value = Slider::create(0, 100);
214
215 Panel::Ptr m_last = Panel::create({60, 30});
216 Panel::Ptr m_current = Panel::create({60, 30});
217
218 bool m_colorRead = false;
219 };
220} // namespace tgui
221
222#endif //TGUI_COLOR_PICKER_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Definition ColorPickerRenderer.hpp:35
ColorPicker(ColorPicker &&other) noexcept
Move constructor.
static ColorPicker::Ptr copy(const ColorPicker::ConstPtr &colorPicker)
Makes a copy of another color picker.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
ColorPicker & operator=(const ColorPicker &other)
Overload of copy assignment operator.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
ColorPickerRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
SignalColor onColorChange
Color was changed.
Definition ColorPicker.hpp:199
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
ColorPicker(const ColorPicker &other)
Copy constructor.
static ColorPicker::Ptr create(const String &title="", Color color=Color::Black)
Creates a new color picker widget.
std::shared_ptr< ColorPicker > Ptr
Shared widget pointer.
Definition ColorPicker.hpp:43
Color getColor() const
Returns the picked color.
std::shared_ptr< const ColorPicker > ConstPtr
Shared constant widget pointer.
Definition ColorPicker.hpp:44
ColorPicker & operator=(ColorPicker &&other) noexcept
Overload of move assignment operator.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
void setColor(const Color &color)
Changes the color of Color Picker.
ColorPickerRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
static constexpr char StaticWidgetType[]
Type name of the widget.
Definition ColorPicker.hpp:46
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
SignalColor onOkPress
Ok button was pressed.
Definition ColorPicker.hpp:200
Wrapper for colors.
Definition Color.hpp:63
static const Color Black
Black predefined color.
Definition Color.hpp:244
std::shared_ptr< Panel > Ptr
Shared widget pointer.
Definition Panel.hpp:41
static Panel::Ptr create(const Layout2d &size={"100%", "100%"})
Creates a new panel widget.
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:59
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition Slider.hpp:41
static Slider::Ptr create(float minimum=0, float maximum=10)
Creates a new slider widget.
Definition Sprite.hpp:45
Wrapper class to store strings.
Definition String.hpp:94
Texture wrapper that internally reuses resources when multiple Texture objects are loaded from the sa...
Definition Texture.hpp:53
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:85
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
SignalTyped< Color > SignalColor
Signal with one "Color" as optional unbound parameter.
Definition Signal.hpp:412
States used for drawing.
Definition RenderStates.hpp:38