TGUI  v0.6.10
Scrollbar.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_SCROLLBAR_HPP
27 #define TGUI_SCROLLBAR_HPP
28 
29 
30 #include <TGUI/Slider.hpp>
31 
33 
34 namespace tgui
35 {
37 
38  class TGUI_API Scrollbar : public Widget
39  {
40  public:
41 
43 
44 
49  Scrollbar();
50 
51 
58  Scrollbar(const Scrollbar& copy);
59 
60 
65  virtual ~Scrollbar();
66 
67 
76  Scrollbar& operator= (const Scrollbar& 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 Scrollbar* clone();
84 
85 
95  bool load(const std::string& configFileFilename, const std::string& sectionName = "Scrollbar");
96 
97 
105  const std::string& getLoadedConfigFile() const;
106 
107 
115  void setSize(float width, float height);
116 
117 
124  virtual sf::Vector2f getSize() const;
125 
126 
136  void setMaximum(unsigned int maximum);
137 
138 
147  void setValue(unsigned int value);
148 
149 
161  void setLowValue(unsigned int lowValue);
162 
163 
170  void setVerticalScroll(bool verticallScroll);
171 
172 
181  unsigned int getMaximum() const;
182 
183 
192  unsigned int getValue() const;
193 
194 
201  unsigned int getLowValue() const;
202 
203 
210  bool getVerticalScroll() const;
211 
212 
219  void setArrowScrollAmount(unsigned int scrollAmount);
220 
221 
228  unsigned int getArrowScrollAmount();
229 
230 
239  void setAutoHide(bool autoHide);
240 
241 
249  bool getAutoHide() const;
250 
251 
262  virtual void setTransparency(unsigned char transparency);
263 
264 
268  virtual bool mouseOnWidget(float x, float y);
269 
273  virtual void leftMousePressed(float x, float y);
274 
278  virtual void leftMouseReleased(float x, float y);
279 
283  virtual void mouseMoved(float x, float y);
284 
288  virtual void mouseWheelMoved(int delta, int x, int y);
289 
293  virtual void widgetFocused();
294 
295 
298  // This function is a (slow) way to set properties on the widget, no matter what type it is.
299  // When the requested property doesn't exist in the widget then the functions will return false.
301  virtual bool setProperty(std::string property, const std::string& value);
302 
305  // This function is a (slow) way to get properties of the widget, no matter what type it is.
306  // When the requested property doesn't exist in the widget then the functions will return false.
308  virtual bool getProperty(std::string property, std::string& value) const;
309 
310 
313  // Returns a list of all properties that can be used in setProperty and getProperty.
314  // The second value in the pair is the type of the property (e.g. int, uint, string, ...).
316  virtual std::list< std::pair<std::string, std::string> > getPropertyList() const;
317 
318 
320  private:
321 
323  // Returns the position and size of the thumb
325  sf::FloatRect getThumbRect() const;
326 
327 
329  protected:
330 
332  // Draws the widget on the render target.
334  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
335 
336 
338  public:
339 
344  {
345  ValueChanged = WidgetCallbacksCount * 1,
346  AllScrollbarCallbacks = WidgetCallbacksCount * 2 - 1,
347  ScrollbarCallbacksCount = WidgetCallbacksCount * 2
348  };
349 
350 
352  protected:
353 
354  std::string m_LoadedConfigFile;
355 
356  // When the mouse went down, did it go down on top of the thumb? If so, where?
357  bool m_MouseDownOnThumb;
358  sf::Vector2f m_MouseDownOnThumbPos;
359  sf::Vector2f m_lastMousePos;
360 
361  unsigned int m_Maximum;
362  unsigned int m_Value;
363 
364  // Maximum should be above this value before the scrollbar is needed
365  unsigned int m_LowValue;
366 
367  // Is the scrollbar draw vertically?
368  bool m_VerticalScroll;
369 
370  // Does the image lie vertically?
371  bool m_VerticalImage;
372 
373  // How far should the value change when pressing one of the arrows?
374  unsigned int m_ScrollAmount;
375 
376  // When no scrollbar is needed, should the scrollbar be drawn or stay hidden?
377  bool m_AutoHide;
378 
379  // Did the mouse went down on one of the arrows?
380  bool m_MouseDownOnArrow;
381 
382  // If this is true then the L, M and R images will be used.
383  // If it is false then the scrollbar is just one big image that will be stored in the M image.
384  bool m_SplitImage;
385 
386  // Is there a separate hover image, or is it a semi-transparent image that is drawn on top of the others?
387  bool m_SeparateHoverImage;
388 
389  // The size of the scrollbar and its thumb
390  sf::Vector2f m_Size;
391  sf::Vector2f m_ThumbSize;
392 
393  Texture m_TextureTrackNormal_L;
394  Texture m_TextureTrackHover_L;
395  Texture m_TextureTrackNormal_M;
396  Texture m_TextureTrackHover_M;
397  Texture m_TextureTrackNormal_R;
398  Texture m_TextureTrackHover_R;
399 
400  Texture m_TextureThumbNormal;
401  Texture m_TextureThumbHover;
402 
403  Texture m_TextureArrowUpNormal;
404  Texture m_TextureArrowUpHover;
405 
406  Texture m_TextureArrowDownNormal;
407  Texture m_TextureArrowDownHover;
408 
409  // ListBox, ComboBox and TextBox can access the scrollbar directly
410  friend class ListBox;
411  friend class ComboBox;
412  friend class TextBox;
413  friend class ChatBox;
414 
416 
417  };
418 
420 }
421 
423 
424 #endif // TGUI_SCROLLBAR_HPP
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
The parent class for every widget.
Definition: Widget.hpp:45
Definition: ComboBox.hpp:38
Definition: TextureManager.hpp:52
Definition: TextBox.hpp:40
Definition: ListBox.hpp:40
ScrollbarCallbacks
Defines specific triggers to Scrollbar.
Definition: Scrollbar.hpp:343
Definition: Scrollbar.hpp:38
Definition: SharedWidgetPtr.hpp:44
Definition: ChatBox.hpp:41