TGUI  0.8.9
ColorPicker.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2020 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/Canvas.hpp>
32 #include <TGUI/Widgets/Panel.hpp>
33 #include <TGUI/Renderers/ColorPickerRenderer.hpp>
34 
35 
37 
38 
39 namespace tgui
40 {
44  class TGUI_API ColorPicker : public ChildWindow
45  {
46  public:
47 
48  typedef std::shared_ptr<ColorPicker> Ptr;
49  typedef std::shared_ptr<const ColorPicker> ConstPtr;
50 
51 
53  // Default constructor
55  ColorPicker();
56 
57 
66  static ColorPicker::Ptr create(sf::String title = "", Color color = Color::Black);
67 
68 
72  ColorPicker(const ColorPicker &copy);
73 
74 
79 
80 
85 
86 
91 
92 
102 
103 
109 
110  const ColorPickerRenderer *getSharedRenderer() const;
111 
118 
119  const ColorPickerRenderer *getRenderer() const;
120 
121 
128  void setColor(const Color &color);
129 
130 
137  Color getColor() const;
138 
139 
143  void leftMousePressed(Vector2f pos) override;
144 
148  void leftMouseButtonNoLongerDown() override;
149 
153  void mouseMoved(Vector2f pos) override;
154 
155 
157  protected:
158 
160  // Makes sure all widgets lie within the window and places them on the correct position.
162  void rearrange();
163 
164 
174  Signal &getSignal(std::string signalName) override;
175 
176 
183  void rendererChanged(const std::string &property) override;
184 
185 
189  std::unique_ptr<DataIO::Node> save(SavingRenderersMap &renderers) const override;
190 
191 
195  void load(const std::unique_ptr<DataIO::Node> &node, const LoadingRenderersMap &renderers) override;
196 
197 
199  // Makes a copy of the widget
201  Widget::Ptr clone() const override
202  {
203  return std::make_shared<ColorPicker>(*this);
204  }
205 
206 
208  private:
209 
211  // Figure and connect signals of widgets
213  void identifyButtonsAndConnect();
214 
215 
217  public:
218 
219  SignalColor onColorChange = {"ColorChanged"};
220  SignalColor onOkPressed = {"OkPressed"};
221 
222 
224  protected:
225  std::shared_ptr<sf::Shader> m_HSV;
226 
227  Canvas::Ptr m_canvas = Canvas::create({200, 200});
228 
229  Slider::Ptr m_red = Slider::create(0, 255);
230  Slider::Ptr m_green = Slider::create(0, 255);
231  Slider::Ptr m_blue = Slider::create(0, 255);
232  Slider::Ptr m_alpha = Slider::create(0, 255);
233 
234  Slider::Ptr m_value = Slider::create(0, 100);
235 
236  Panel::Ptr m_last = Panel::create({60, 30});
237  Panel::Ptr m_current = Panel::create({60, 30});
238 
239  bool m_colorRead = false;
240  };
241 
243 }
244 
246 #endif //TGUI_COLOR_PICKER_HPP
static Canvas::Ptr create(Layout2d size={"100%", "100%"})
Creates a new canvas widget.
std::shared_ptr< Canvas > Ptr
Shared widget pointer.
Definition: Canvas.hpp:44
Child window widget.
Definition: ChildWindow.hpp:44
Definition: ColorPickerRenderer.hpp:37
Color picker widget.
Definition: ColorPicker.hpp:45
static ColorPicker::Ptr create(sf::String title="", Color color=Color::Black)
Creates a new color picker widget.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: ColorPicker.hpp:201
ColorPicker & operator=(ColorPicker &&right)
Overload of move assignment operator.
std::shared_ptr< ColorPicker > Ptr
Shared widget pointer.
Definition: ColorPicker.hpp:48
Signal & getSignal(std::string signalName) override
Retrieves a signal based on its name.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
ColorPicker(ColorPicker &&copy)
Move constructor.
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.
Color getColor() const
Returns the picked color.
ColorPickerRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
ColorPickerRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void rendererChanged(const std::string &property) override
Function called when one of the properties of the renderer is changed.
ColorPicker & operator=(const ColorPicker &right)
Overload of copy assignment operator.
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.
std::shared_ptr< const ColorPicker > ConstPtr
Shared constant widget pointer.
Definition: ColorPicker.hpp:49
Wrapper for colors.
Definition: Color.hpp:49
static const Color Black
Black predefined color.
Definition: Color.hpp:206
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:231
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: Vector2f.hpp:39
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:77
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37