TGUI  0.9-beta
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 #if TGUI_BUILD_WITH_SFML
36 
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(String title = "", Color color = Color::Black);
67 
68 
72  ColorPicker(const ColorPicker &copy);
73 
74 
78  ColorPicker(ColorPicker &&copy);
79 
80 
84  ColorPicker &operator=(const ColorPicker &right);
85 
86 
90  ColorPicker &operator=(ColorPicker &&right);
91 
92 
101  static ColorPicker::Ptr copy(ColorPicker::ConstPtr colorPicker);
102 
103 
108  ColorPickerRenderer* getSharedRenderer();
109  const ColorPickerRenderer* getSharedRenderer() const;
110 
116  ColorPickerRenderer* getRenderer();
117  const ColorPickerRenderer* getRenderer() const;
118 
119 
125  void setColor(const Color &color);
126 
127 
133  Color getColor() const;
134 
135 
139  void leftMousePressed(Vector2f pos) override;
140 
144  void leftMouseButtonNoLongerDown() override;
145 
149  void mouseMoved(Vector2f pos) override;
150 
151 
153  protected:
154 
156  // Makes sure all widgets lie within the window and places them on the correct position.
158  void rearrange();
159 
160 
170  Signal& getSignal(String signalName) override;
171 
172 
179  void rendererChanged(const String& property) override;
180 
181 
185  std::unique_ptr<DataIO::Node> save(SavingRenderersMap &renderers) const override;
186 
187 
191  void load(const std::unique_ptr<DataIO::Node> &node, const LoadingRenderersMap &renderers) override;
192 
193 
195  // Makes a copy of the widget
197  Widget::Ptr clone() const override
198  {
199  return std::make_shared<ColorPicker>(*this);
200  }
201 
202 
204  private:
205 
207  // Figure and connect signals of widgets
209  void identifyButtonsAndConnect();
210 
211 
213  public:
214 
215  SignalColor onColorChange = {"ColorChanged"};
216  SignalColor onOkPress = {"OkPress"};
217 
218 
220  protected:
221  std::shared_ptr<sf::Shader> m_HSV;
222 
223  Canvas::Ptr m_canvas = Canvas::create({200, 200});
224 
225  Slider::Ptr m_red = Slider::create(0, 255);
226  Slider::Ptr m_green = Slider::create(0, 255);
227  Slider::Ptr m_blue = Slider::create(0, 255);
228  Slider::Ptr m_alpha = Slider::create(0, 255);
229 
230  Slider::Ptr m_value = Slider::create(0, 100);
231 
232  Panel::Ptr m_last = Panel::create({60, 30});
233  Panel::Ptr m_current = Panel::create({60, 30});
234 
235  bool m_colorRead = false;
236  };
237 
239 }
240 
241 #endif // TGUI_BUILD_WITH_SFML
242 
244 #endif //TGUI_COLOR_PICKER_HPP
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
static Panel::Ptr create(Layout2d size={"100%", "100%"})
Creates a new panel widget.
SignalTyped< Color > SignalColor
Signal with one "Color" as optional unbound parameter.
Definition: Signal.hpp:451
static Slider::Ptr create(float minimum=0, float maximum=10)
Creates a new slider widget.
std::shared_ptr< Slider > Ptr
Shared widget pointer.
Definition: Slider.hpp:44
std::shared_ptr< Panel > Ptr
Shared widget pointer.
Definition: Panel.hpp:44
static const Color Black
Black predefined color.
Definition: Color.hpp:236