TGUI  v0.6.10
Slider.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_SLIDER_HPP
27 #define TGUI_SLIDER_HPP
28 
29 
30 #include <TGUI/Widget.hpp>
31 
33 
34 namespace tgui
35 {
37 
38  class TGUI_API Slider : public Widget
39  {
40  public:
41 
43 
44 
49  Slider();
50 
51 
58  Slider(const Slider& copy);
59 
60 
65  virtual ~Slider();
66 
67 
76  Slider& operator= (const Slider& right);
77 
78 
80  // Makes a copy of the widget by calling the copy constructor.
81  // This function calls new and if you use this function then you are responsible for calling delete.
83  virtual Slider* clone();
84 
85 
95  virtual bool load(const std::string& configFileFilename, const std::string& sectionName = "Slider");
96 
97 
105  const std::string& getLoadedConfigFile() const;
106 
107 
121  virtual void setPosition(float x, float y);
123 
124 
132  void setSize(float width, float height);
133 
134 
141  virtual sf::Vector2f getSize() const;
142 
143 
154  virtual void setMinimum(unsigned int minimum);
155 
156 
167  virtual void setMaximum(unsigned int maximum);
168 
169 
179  virtual void setValue(unsigned int value);
180 
181 
188  void setVerticalScroll(bool verticallScroll);
189 
190 
199  unsigned int getMinimum() const;
200 
201 
210  unsigned int getMaximum() const;
211 
212 
221  unsigned int getValue() const;
222 
223 
230  bool getVerticalScroll() const;
231 
232 
243  virtual void setTransparency(unsigned char transparency);
244 
245 
249  virtual bool mouseOnWidget(float x, float y);
250 
254  virtual void leftMousePressed(float x, float y);
255 
259  virtual void leftMouseReleased(float x, float y);
260 
264  virtual void mouseMoved(float x, float y);
265 
269  virtual void mouseWheelMoved(int delta, int x, int y);
270 
274  virtual void widgetFocused();
275 
276 
279  // This function is a (slow) way to set properties on the widget, no matter what type it is.
280  // When the requested property doesn't exist in the widget then the functions will return false.
282  virtual bool setProperty(std::string property, const std::string& value);
283 
286  // This function is a (slow) way to get properties of the widget, no matter what type it is.
287  // When the requested property doesn't exist in the widget then the functions will return false.
289  virtual bool getProperty(std::string property, std::string& value) const;
290 
291 
294  // Returns a list of all properties that can be used in setProperty and getProperty.
295  // The second value in the pair is the type of the property (e.g. int, uint, string, ...).
297  virtual std::list< std::pair<std::string, std::string> > getPropertyList() const;
298 
299 
301  protected:
302 
304  // Draws the widget on the render target.
306  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
307 
308 
310  public:
311 
316  {
317  ValueChanged = WidgetCallbacksCount * 1,
318  AllSliderCallbacks = WidgetCallbacksCount * 2 - 1,
319  SliderCallbacksCount = WidgetCallbacksCount * 2
320  };
321 
322 
324  protected:
325 
326  std::string m_LoadedConfigFile;
327 
328  // When the mouse went down, did it go down on top of the thumb? If so, where?
329  bool m_MouseDownOnThumb;
330  sf::Vector2f m_MouseDownOnThumbPos;
331  sf::Vector2f m_lastMousePos;
332 
333  unsigned int m_Minimum;
334  unsigned int m_Maximum;
335  unsigned int m_Value;
336 
337  // Is the slider draw vertically?
338  bool m_VerticalScroll;
339 
340  // Does the image lie vertically?
341  bool m_VerticalImage;
342 
343  // If this is true then the L, M and R images will be used.
344  // If it is false then the slider is just one big image that will be stored in the M image.
345  bool m_SplitImage;
346 
347  // Is there a separate hover image, or is it a semi-transparent image that is drawn on top of the others?
348  bool m_SeparateHoverImage;
349 
350  // The size of the slider and its thumb
351  sf::Vector2f m_Size;
352  sf::Vector2f m_ThumbSize;
353 
354  Texture m_TextureTrackNormal_L;
355  Texture m_TextureTrackHover_L;
356  Texture m_TextureTrackNormal_M;
357  Texture m_TextureTrackHover_M;
358  Texture m_TextureTrackNormal_R;
359  Texture m_TextureTrackHover_R;
360  Texture m_TextureThumbNormal;
361  Texture m_TextureThumbHover;
362  };
363 
365 }
366 
368 
369 #endif // TGUI_SLIDER_HPP
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: Slider.hpp:38
Definition: SharedWidgetPtr.hpp:44
SliderCallbacks
Defines specific triggers to Slider.
Definition: Slider.hpp:315