TGUI  1.0-alpha
ColorPicker.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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
29#include <TGUI/Widgets/ChildWindow.hpp>
30#include <TGUI/Widgets/Slider.hpp>
31#include <TGUI/Widgets/Panel.hpp>
32#include <TGUI/Renderers/ColorPickerRenderer.hpp>
33
35
36namespace tgui
37{
41 class TGUI_API ColorPicker : public ChildWindow
42 {
43 public:
44
45 typedef std::shared_ptr<ColorPicker> Ptr;
46 typedef std::shared_ptr<const ColorPicker> ConstPtr;
47
48
56 ColorPicker(const char* typeName = "ColorPicker", bool initRenderer = true);
57
58
67 static ColorPicker::Ptr create(String title = "", Color color = Color::Black);
68
69
74
75
80
81
86
87
92
93
103
104
110 const ColorPickerRenderer* getSharedRenderer() const;
111
118
119
125 void setColor(const Color &color);
126
127
134
135
139 void leftMousePressed(Vector2f pos) override;
140
144 void leftMouseButtonNoLongerDown() override;
145
149 void mouseMoved(Vector2f pos) override;
150
151
158 void draw(BackendRenderTarget& target, RenderStates states) const override;
159
160
162 protected:
163
165 // Makes sure all widgets lie within the window and places them on the correct position.
167 void rearrange();
168
169
179 Signal& getSignal(String signalName) override;
180
181
188 void rendererChanged(const String& property) override;
189
190
194 std::unique_ptr<DataIO::Node> save(SavingRenderersMap &renderers) const override;
195
196
200 void load(const std::unique_ptr<DataIO::Node> &node, const LoadingRenderersMap &renderers) override;
201
202
204 // Makes a copy of the widget
206 Widget::Ptr clone() const override;
207
208
210 private:
211
213 // Figure and connect signals of widgets
215 void identifyButtonsAndConnect();
216
217
219 public:
220
221 SignalColor onColorChange = {"ColorChanged"};
222 SignalColor onOkPress = {"OkPress"};
223
224
226 protected:
227
228 Texture m_colorWheelTexture;
229 Sprite m_colorWheelSprite;
230
231 Slider::Ptr m_red = Slider::create(0, 255);
232 Slider::Ptr m_green = Slider::create(0, 255);
233 Slider::Ptr m_blue = Slider::create(0, 255);
234 Slider::Ptr m_alpha = Slider::create(0, 255);
235
236 Slider::Ptr m_value = Slider::create(0, 100);
237
238 Panel::Ptr m_last = Panel::create({60, 30});
239 Panel::Ptr m_current = Panel::create({60, 30});
240
241 bool m_colorRead = false;
242 };
243
245}
246
248#endif //TGUI_COLOR_PICKER_HPP
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Child window widget.
Definition: ChildWindow.hpp:44
Definition: ColorPickerRenderer.hpp:37
Color picker widget.
Definition: ColorPicker.hpp:42
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
ColorPicker & operator=(ColorPicker &&right)
Overload of move assignment operator.
ColorPickerRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
std::shared_ptr< ColorPicker > Ptr
Shared widget pointer.
Definition: ColorPicker.hpp:45
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
ColorPicker(ColorPicker &&copy)
Move constructor.
ColorPickerRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
static ColorPicker::Ptr create(String title="", Color color=Color::Black)
Creates a new color picker widget.
Color getColor() const
Returns the picked color.
static ColorPicker::Ptr copy(ColorPicker::ConstPtr colorPicker)
Makes a copy of another color picker.
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.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
std::shared_ptr< const ColorPicker > ConstPtr
Shared constant widget pointer.
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.
Wrapper for colors.
Definition: Color.hpp:63
static const Color Black
Black predefined color.
Definition: Color.hpp:259
std::shared_ptr< Panel > Ptr
Shared widget pointer.
Definition: Panel.hpp:44
static Panel::Ptr create(Layout2d size={"100%", "100%"})
Creates a new panel widget.
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition: Slider.hpp:44
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:79
Definition: Texture.hpp:52
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
States used for drawing.
Definition: RenderStates.hpp:39