TGUI  0.8-dev
Knob.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2017 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 
26 #ifndef TGUI_KNOB_HPP
27 #define TGUI_KNOB_HPP
28 
29 
30 #include <TGUI/Widget.hpp>
31 #include <TGUI/Renderers/KnobRenderer.hpp>
32 
34 
35 namespace tgui
36 {
40  class TGUI_API Knob : public Widget
41  {
42  public:
43 
44  typedef std::shared_ptr<Knob> Ptr;
45  typedef std::shared_ptr<const Knob> ConstPtr;
46 
47 
49  // Default constructor
51  Knob();
52 
53 
60  static Knob::Ptr create();
61 
62 
71  static Knob::Ptr copy(Knob::ConstPtr knob);
72 
73 
78  KnobRenderer* getSharedRenderer();
79  const KnobRenderer* getSharedRenderer() const;
80 
86  KnobRenderer* getRenderer();
87  const KnobRenderer* getRenderer() const;
88 
89 
96  void setSize(const Layout2d& size) override;
97  using Widget::setSize;
98 
99 
108  void setStartRotation(float startRotation);
109 
110 
117  float getStartRotation() const;
118 
119 
128  void setEndRotation(float endRotation);
129 
130 
137  float getEndRotation() const;
138 
139 
154  void setMinimum(int minimum);
155 
156 
167  int getMinimum() const;
168 
169 
184  void setMaximum(int maximum);
185 
186 
197  int getMaximum() const;
198 
199 
211  void setValue(int value);
212 
213 
222  int getValue() const;
223 
224 
231  void setClockwiseTurning(bool clockwise);
232 
233 
240  bool getClockwiseTurning() const;
241 
242 
249  bool mouseOnWidget(sf::Vector2f pos) const override;
250 
254  void leftMousePressed(sf::Vector2f pos) override;
255 
259  void leftMouseReleased(sf::Vector2f pos) override;
260 
264  void mouseMoved(sf::Vector2f pos) override;
265 
269  void widgetFocused() override;
270 
271 
279  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
280 
281 
283  protected:
284 
294  Signal& getSignal(std::string signalName) override;
295 
296 
303  void rendererChanged(const std::string& property) override;
304 
305 
307  // Returns the size without the borders
309  sf::Vector2f getInnerSize() const;
310 
311 
313  // Recalculates the rotation of the knob.
315  void recalculateRotation();
316 
317 
319  // Makes a copy of the widget
321  Widget::Ptr clone() const override
322  {
323  return std::make_shared<Knob>(*this);
324  }
325 
326 
328  public:
329 
330  SignalInt onValueChange = {"ValueChanged"};
331 
332 
334  protected:
335 
336  bool m_clockwiseTurning = true; // Does rotating clockwise increment the value?
337  float m_startRotation = 270;
338  float m_endRotation = 270;
339 
340  int m_minimum = 0;
341  int m_value = 0;
342  int m_maximum = 360;
343 
344  float m_angle = 270;
345 
346  Sprite m_spriteBackground;
347  Sprite m_spriteForeground;
348 
349  // Cached renderer properties
350  Borders m_bordersCached;
351  Color m_borderColorCached;
352  Color m_backgroundColorCached;
353  Color m_thumbColorCached;
354  float m_imageRotationCached = 0;
355  };
356 
358 }
359 
361 
362 #endif // TGUI_KNOB_HPP
363 
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:40
Wrapper for colors.
Definition: Color.hpp:46
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Knob.hpp:321
Class to store the position or size of a widget.
Definition: Layout.hpp:243
The parent class for every widget.
Definition: Widget.hpp:62
Knob widget.
Definition: Knob.hpp:40
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:66
Definition: KnobRenderer.hpp:36
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:59
std::shared_ptr< const Knob > ConstPtr
Shared constant widget pointer.
Definition: Knob.hpp:45
std::shared_ptr< Knob > Ptr
Shared widget pointer.
Definition: Knob.hpp:44
Definition: Outline.hpp:38