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 {
48  class TGUI_API Knob : public Widget
49  {
50  public:
51 
52  typedef std::shared_ptr<Knob> Ptr;
53  typedef std::shared_ptr<const Knob> ConstPtr;
54 
55 
57  // Default constructor
59  Knob();
60 
61 
68  static Knob::Ptr create();
69 
70 
79  static Knob::Ptr copy(Knob::ConstPtr knob);
80 
81 
89  {
90  return aurora::downcast<KnobRenderer*>(m_renderer.get());
91  }
92 
93 
100  virtual void setSize(const Layout2d& size) override;
102 
103 
112  void setStartRotation(float startRotation);
113 
114 
121  float getStartRotation() const;
122 
123 
132  void setEndRotation(float endRotation);
133 
134 
141  float getEndRotation() const;
142 
143 
158  virtual void setMinimum(int minimum);
159 
160 
171  int getMinimum() const;
172 
173 
188  virtual void setMaximum(int maximum);
189 
190 
201  int getMaximum() const;
202 
203 
215  virtual void setValue(int value);
216 
217 
226  int getValue() const;
227 
228 
235  void setClockwiseTurning(bool clockwise);
236 
237 
244  bool getClockwiseTurning() const;
245 
246 
250  virtual bool mouseOnWidget(sf::Vector2f pos) const override;
251 
255  virtual void leftMousePressed(sf::Vector2f pos) override;
256 
260  virtual void leftMouseReleased(sf::Vector2f pos) override;
261 
265  virtual void mouseMoved(sf::Vector2f pos) override;
266 
270  virtual void widgetFocused() override;
271 
272 
280  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
281 
282 
284  protected:
285 
292  virtual void rendererChanged(const std::string& property) override;
293 
294 
296  // Returns the size without the borders
298  sf::Vector2f getInnerSize() const;
299 
300 
302  // Recalculates the rotation of the knob.
304  void recalculateRotation();
305 
306 
308  // Makes a copy of the widget
310  virtual Widget::Ptr clone() const override
311  {
312  return std::make_shared<Knob>(*this);
313  }
314 
315 
317  protected:
318 
319  bool m_clockwiseTurning = true; // Does rotating clockwise increment the value?
320  float m_startRotation = 270;
321  float m_endRotation = 270;
322 
323  int m_minimum = 0;
324  int m_value = 0;
325  int m_maximum = 360;
326 
327  float m_angle = 270;
328 
329  Sprite m_spriteBackground;
330  Sprite m_spriteForeground;
331 
332  // Cached renderer properties
333  Borders m_bordersCached;
334  Color m_borderColorCached;
335  Color m_backgroundColorCached;
336  Color m_thumbColorCached;
337  float m_imageRotationCached = 0;
338  };
339 
341 }
342 
344 
345 #endif // TGUI_KNOB_HPP
346 
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Definition: Sprite.hpp:40
Wrapper for colors.
Definition: Color.hpp:46
Class to store the position or size of a widget.
Definition: Layout.hpp:263
The parent class for every widget.
Definition: Widget.hpp:72
Knob widget.
Definition: Knob.hpp:48
KnobRenderer * getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed...
Definition: Knob.hpp:88
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:76
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Knob.hpp:310
Definition: KnobRenderer.hpp:36
std::shared_ptr< const Knob > ConstPtr
Shared constant widget pointer.
Definition: Knob.hpp:53
std::shared_ptr< Knob > Ptr
Shared widget pointer.
Definition: Knob.hpp:52
Definition: Outline.hpp:37