TGUI  v0.6.10
Knob.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2015 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 
33 
34 namespace tgui
35 {
37 
38  class TGUI_API Knob : public Widget
39  {
40  public:
41 
42  typedef SharedWidgetPtr<Knob> Ptr;
43 
44 
49  Knob();
50 
51 
58  Knob(const Knob& copy);
59 
60 
65  virtual ~Knob();
66 
67 
76  Knob& operator= (const Knob& right);
77 
78 
81  // Makes a copy of the widget by calling the copy constructor.
82  // This function calls new and if you use this function then you are responsible for calling delete.
84  virtual Knob* clone();
85 
86 
96  bool load(const std::string& configFileFilename, const std::string& sectionName = "Knob");
97 
98 
106  const std::string& getLoadedConfigFile() const;
107 
108 
122  virtual void setPosition(float x, float y);
124 
125 
133  virtual void setSize(float width, float height);
134 
135 
142  virtual sf::Vector2f getSize() const;
143 
144 
153  void setStartRotation(float startRotation);
154 
155 
164  void setEndRotation(float endRotation);
165 
166 
181  virtual void setMinimum(int minimum);
182 
183 
198  virtual void setMaximum(int maximum);
199 
200 
212  virtual void setValue(int value);
213 
214 
225  int getMinimum() const;
226 
227 
238  int getMaximum() const;
239 
240 
249  int getValue() const;
250 
251 
258  void setClockwiseTurning(bool clockwise);
259 
260 
267  bool getClockwiseTurning();
268 
269 
280  virtual void setTransparency(unsigned char transparency);
281 
282 
286  virtual bool mouseOnWidget(float x, float y);
287 
291  virtual void leftMousePressed(float x, float y);
292 
296  virtual void leftMouseReleased(float x, float y);
297 
301  virtual void mouseMoved(float x, float y);
302 
306  virtual void widgetFocused();
307 
308 
311  // This function is a (slow) way to set properties on the widget, no matter what type it is.
312  // When the requested property doesn't exist in the widget then the functions will return false.
314  virtual bool setProperty(std::string property, const std::string& value);
315 
318  // This function is a (slow) way to get properties of the widget, no matter what type it is.
319  // When the requested property doesn't exist in the widget then the functions will return false.
321  virtual bool getProperty(std::string property, std::string& value) const;
322 
323 
326  // Returns a list of all properties that can be used in setProperty and getProperty.
327  // The second value in the pair is the type of the property (e.g. int, uint, string, ...).
329  virtual std::list< std::pair<std::string, std::string> > getPropertyList() const;
330 
331 
333  protected:
334 
336  // Recalculates the rotation of the knob.
338  void recalculateRotation();
339 
340 
342  // Draws the widget on the render target.
344  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
345 
346 
348  public:
349 
354  {
355  ValueChanged = WidgetCallbacksCount * 1,
356  AllKnobCallbacks = WidgetCallbacksCount * 2 - 1,
357  KnobCallbacksCount = WidgetCallbacksCount * 2
358  };
359 
360 
362  protected:
363 
364  std::string m_loadedConfigFile;
365 
366  Texture m_backgroundTexture;
367  Texture m_foregroundTexture;
368 
369  sf::Vector2f m_size;
370 
371  bool m_clockwiseTurning; // Does rotating clockwise increment the value?
372  float m_imageRotation;
373  float m_startRotation;
374  float m_endRotation;
375 
376  int m_minimum;
377  int m_value;
378  int m_maximum;
379  };
380 
382 }
383 
385 
386 #endif // TGUI_KNOB_HPP
387 
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
virtual void setPosition(float x, float y)
Set the position of the widget.
The parent class for every widget.
Definition: Widget.hpp:45
Definition: TextureManager.hpp:52
Definition: Knob.hpp:38
KnobCallbacks
Defines specific triggers to Knob.
Definition: Knob.hpp:353
Definition: SharedWidgetPtr.hpp:44