TGUI  1.6.1
Loading...
Searching...
No Matches
ColorPicker.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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/Widgets/ChildWindow.hpp>
29#include <TGUI/Widgets/Slider.hpp>
30#include <TGUI/Widgets/Panel.hpp>
31#include <TGUI/Renderers/ColorPickerRenderer.hpp>
32
34
35TGUI_MODULE_EXPORT namespace tgui
36{
40 class TGUI_API ColorPicker : public ChildWindow
41 {
42 public:
43
44 using Ptr = std::shared_ptr<ColorPicker>;
45 using ConstPtr = std::shared_ptr<const ColorPicker>;
46
47 static constexpr const char StaticWidgetType[] = "ColorPicker";
48
56 ColorPicker(const char* typeName = StaticWidgetType, bool initRenderer = true);
57
66 TGUI_NODISCARD static ColorPicker::Ptr create(const String& title = "", Color color = Color::Black);
67
72
76 ColorPicker(ColorPicker&& copy) noexcept;
77
82
86 ColorPicker& operator=(ColorPicker&& right) noexcept;
87
95 TGUI_NODISCARD static ColorPicker::Ptr copy(const ColorPicker::ConstPtr& colorPicker);
96
101 TGUI_NODISCARD ColorPickerRenderer* getSharedRenderer() override;
102 TGUI_NODISCARD const ColorPickerRenderer* getSharedRenderer() const override;
103
109 TGUI_NODISCARD ColorPickerRenderer* getRenderer() override;
110
116 void setColor(const Color& color);
117
123 TGUI_NODISCARD Color getColor() const;
124
128 bool leftMousePressed(Vector2f pos) override;
129
133 void leftMouseButtonNoLongerDown() override;
134
138 void mouseMoved(Vector2f pos) override;
139
146 void draw(BackendRenderTarget& target, RenderStates states) const override;
147
149 protected:
150
152 // Makes sure all widgets lie within the window and places them on the correct position.
154 void rearrange();
155
165 TGUI_NODISCARD Signal& getSignal(String signalName) override;
166
172 void rendererChanged(const String& property) override;
173
177 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
178
182 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
183
185 // Makes a copy of the widget
187 TGUI_NODISCARD Widget::Ptr clone() const override;
188
190 private:
191
193 // Figure and connect signals of widgets
195 void identifyButtonsAndConnect();
196
198 public:
199
200 SignalColor onColorChange = {"ColorChanged"};
201 SignalColor onOkPress = {"OkPressed"};
202
204 protected:
205
206 Texture m_colorWheelTexture;
207 Sprite m_colorWheelSprite;
208
209 Slider::Ptr m_red = Slider::create(0, 255);
210 Slider::Ptr m_green = Slider::create(0, 255);
211 Slider::Ptr m_blue = Slider::create(0, 255);
212 Slider::Ptr m_alpha = Slider::create(0, 255);
213
214 Slider::Ptr m_value = Slider::create(0, 100);
215
216 Panel::Ptr m_last = Panel::create({60, 30});
217 Panel::Ptr m_current = Panel::create({60, 30});
218
219 bool m_colorRead = false;
220 };
221
223}
224
226#endif //TGUI_COLOR_PICKER_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Child window widget.
Definition ChildWindow.hpp:45
Definition ColorPickerRenderer.hpp:35
Color picker widget.
Definition ColorPicker.hpp:41
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.
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.
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.
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:44
Color getColor() const
Returns the picked color.
std::shared_ptr< const ColorPicker > ConstPtr
Shared constant widget pointer.
Definition ColorPicker.hpp:45
ColorPicker & operator=(ColorPicker &&right) 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.
ColorPicker(ColorPicker &&copy) noexcept
Move constructor.
ColorPicker(const ColorPicker &copy)
Copy constructor.
void setColor(const Color &color)
Changes the color of Color Picker.
ColorPicker & operator=(const ColorPicker &right)
Overload of copy assignment operator.
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.
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.
Wrapper for colors.
Definition Color.hpp:73
std::shared_ptr< Panel > Ptr
Shared widget pointer.
Definition Panel.hpp:42
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition Slider.hpp:42
Definition Sprite.hpp:47
Wrapper class to store strings.
Definition String.hpp:96
Texture wrapper that internally reuses resources when multiple Texture objects are loaded from the sa...
Definition Texture.hpp:57
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:86
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
States used for drawing.
Definition RenderStates.hpp:38