Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IGUIScrollBar.h
Go to the documentation of this file.
1 /* Copyright (C) 2009 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19 A GUI ScrollBar
20 
21 --Overview--
22 
23  A GUI Scrollbar, this class doesn't present all functionality
24  to the scrollbar, it just controls the drawing and a wrapper
25  for interaction with it.
26 
27 --Usage--
28 
29  Used in everywhere scrollbars are needed, like in a combobox for instance.
30 
31 --More info--
32 
33  Check GUI.h
34 
35 */
36 
37 #ifndef INCLUDED_IGUISCROLLBAR
38 #define INCLUDED_IGUISCROLLBAR
39 
40 //--------------------------------------------------------
41 // Includes / Compiler directives
42 //--------------------------------------------------------
43 #include "GUI.h"
44 
45 //--------------------------------------------------------
46 // Declarations
47 //--------------------------------------------------------
48 
49 /**
50  * The GUI Scroll-bar style. Tells us how scroll-bars look and feel.
51  *
52  * A scroll-bar style can choose whether to support horizontal, vertical
53  * or both.
54  *
55  * @see IGUIScrollBar
56  */
58 {
59  //--------------------------------------------------------
60  /** @name General Settings */
61  //--------------------------------------------------------
62  //@{
63 
64  /**
65  * Width of bar, also both sides of the edge buttons.
66  */
67  float m_Width;
68 
69  /**
70  * Scrollable with the wheel.
71  */
73 
74  /**
75  * How much (in percent, 0.1f = 10%) to scroll each time
76  * the wheel is admitted, or the buttons are pressed.
77  */
79 
80  /**
81  * Whether or not the edge buttons should appear or not. Sometimes
82  * you actually don't want them, like perhaps in a combo box.
83  */
85 
86  /**
87  * Sometimes there is *a lot* to scroll, but to prevent the scroll "bar"
88  * from being almost invisible (or ugly), you can set a minimum in pixel
89  * size.
90  */
92 
93  /**
94  * Sometimes you would like your scroll bar to have a fixed maximum size
95  * so that the texture does not get too stretched, you can set a maximum
96  * in pixels.
97  */
99 
100  //@}
101  //--------------------------------------------------------
102  /** @name Horizontal Sprites */
103  //--------------------------------------------------------
104  //@{
105 
110 
115 
119 
121 
122  //@}
123  //--------------------------------------------------------
124  /** @name Vertical Sprites */
125  //--------------------------------------------------------
126  //@{
127 
131 
135 
138 
139  //@}
140 };
141 
142 
143 /**
144  * The GUI Scroll-bar, used everywhere there is a scroll-bar in the game.
145  *
146  * To include a scroll-bar to an object, inherent the object from
147  * IGUIScrollBarOwner and call AddScrollBar() to add the scroll-bars.
148  *
149  * It's also important that the scrollbar is located within the parent
150  * object's mouse over area. Otherwise the input won't be sent to the
151  * scroll-bar.
152  *
153  * The class does not provide all functionality to the scroll-bar, many
154  * things the parent of the scroll-bar, must provide. Like a combo-box.
155  */
157 {
158 public:
159  IGUIScrollBar();
160  virtual ~IGUIScrollBar();
161 
162 public:
163  /**
164  * Draw the scroll-bar
165  */
166  virtual void Draw()=0;
167 
168  /**
169  * If an object that contains a scrollbar has got messages, send
170  * them to the scroll-bar and it will see if the message regarded
171  * itself.
172  *
173  * @see IGUIObject#HandleMessage()
174  */
175  virtual void HandleMessage(SGUIMessage &Message)=0;
176 
177  /**
178  * Set m_Pos with g_mouse_x/y input, i.e. when draggin.
179  */
180  virtual void SetPosFromMousePos(const CPos &mouse)=0;
181 
182  /**
183  * Hovering the scroll minus button
184  *
185  * @param mouse current mouse position
186  * @return True if mouse positions are hovering the button
187  */
188  virtual bool HoveringButtonMinus(const CPos& UNUSED(mouse)) { return false; }
189 
190  /**
191  * Hovering the scroll plus button
192  *
193  * @param mouse current mouse position
194  * @return True if mouse positions are hovering the button
195  */
196  virtual bool HoveringButtonPlus(const CPos& UNUSED(mouse)) { return false; }
197 
198  /**
199  * Get scroll-position
200  */
201  float GetPos() const { return m_Pos; }
202 
203  /**
204  * Set scroll-position by hand
205  */
206  virtual void SetPos(float f) { m_Pos = f; UpdatePosBoundaries(); }
207 
208  /**
209  * Get the value of m_Pos that corresponds to the bottom of the scrollable region
210  */
211  float GetMaxPos() const { return std::max(1.f, m_ScrollRange - m_ScrollSpace); }
212 
213  /**
214  * Increase scroll one step
215  */
216  virtual void ScrollPlus() { m_Pos += 30.f; UpdatePosBoundaries(); }
217 
218  /**
219  * Decrease scroll one step
220  */
221  virtual void ScrollMinus() { m_Pos -= 30.f; UpdatePosBoundaries(); }
222 
223  /**
224  * Increase scroll three steps
225  */
226  virtual void ScrollPlusPlenty() { m_Pos += 90.f; UpdatePosBoundaries(); }
227 
228  /**
229  * Decrease scroll three steps
230  */
231  virtual void ScrollMinusPlenty() { m_Pos -= 90.f; UpdatePosBoundaries(); }
232 
233  /**
234  * Set host object, must be done almost at creation of scroll bar.
235  * @param pOwner Pointer to host object.
236  */
237  void SetHostObject(IGUIScrollBarOwner * pOwner) { m_pHostObject = pOwner; }
238 
239  /**
240  * Get GUI pointer
241  * @return CGUI pointer
242  */
243  CGUI *GetGUI() const;
244 
245  /**
246  * Set GUI pointer
247  * @param pGUI pointer to CGUI object.
248  */
249  void SetGUI(CGUI *pGUI) { m_pGUI = pGUI; }
250 
251  /**
252  * Set Width
253  * @param width Width
254  */
255  void SetWidth(float width) { m_Width = width; }
256 
257  /**
258  * Set X Position
259  * @param x Position in this axis
260  */
261  void SetX(float x) { m_X = x; }
262 
263  /**
264  * Set Y Position
265  * @param y Position in this axis
266  */
267  void SetY(float y) { m_Y = y; }
268 
269  /**
270  * Set Z Position
271  * @param z Position in this axis
272  */
273  void SetZ(float z) { m_Z = z; }
274 
275  /**
276  * Set Length of scroll bar
277  * @param length Length
278  */
279  void SetLength(float length) { m_Length = length; }
280 
281  /**
282  * Set content length
283  * @param range Maximum scrollable range
284  */
285  void SetScrollRange(float range) { m_ScrollRange = std::max(range, 1.f); SetupBarSize(); UpdatePosBoundaries(); }
286 
287  /**
288  * Set space that is visible in the scrollable control.
289  * @param space Visible area in the scrollable control.
290  */
291  void SetScrollSpace(float space) { m_ScrollSpace = space; SetupBarSize(); UpdatePosBoundaries(); }
292 
293  /**
294  * Set bar pressed
295  * @param b True if bar is pressed
296  */
297  void SetBarPressed(bool b) { m_BarPressed = b; }
298 
299  /**
300  * Set use edge buttons
301  * @param b True if edge buttons should be used
302  */
303  void SetUseEdgeButtons(bool b) { m_UseEdgeButtons = b; }
304 
305  /**
306  * Set Scroll bar style string
307  * @param style String with scroll bar style reference name
308  */
309  void SetScrollBarStyle(const CStr& style) { m_ScrollBarStyle = style; }
310 
311  /**
312  * Get style used by the scrollbar
313  * @return Scroll bar style struct.
314  */
315  const SGUIScrollBarStyle * GetStyle() const;
316 
317  /**
318  * Get the rectangle of the actual BAR. not the whole scroll-bar.
319  * @return Rectangle, CRect
320  */
321  virtual CRect GetBarRect() const = 0;
322 
323  /**
324  * Get the rectangle of the outline of the scrollbar, every component of the
325  * scroll-bar should be inside this area.
326  * @return Rectangle, CRect
327  */
328  virtual CRect GetOuterRect() const = 0;
329 
330 protected:
331  /**
332  * Sets up bar size
333  */
334  void SetupBarSize();
335 
336  /**
337  * Call every time m_Pos has been updated.
338  */
339  void UpdatePosBoundaries();
340 
341 protected:
342  //@}
343  //--------------------------------------------------------
344  /** @name Settings */
345  //--------------------------------------------------------
346  //@{
347 
348  /**
349  * True if you want edge buttons, i.e. buttons that can be pressed in order
350  * to scroll.
351  */
353 
354  /**
355  * Width of the scroll bar
356  */
357  float m_Width;
358 
359  /**
360  * Absolute X Position
361  */
362  float m_X;
363 
364  /**
365  * Absolute Y Position
366  */
367  float m_Y;
368 
369  /**
370  * Absolute Z Position
371  */
372  float m_Z;
373 
374  /**
375  * Total length of scrollbar, including edge buttons.
376  */
377  float m_Length;
378 
379  /**
380  * Content that can be scrolled, in pixels
381  */
383 
384  /**
385  * Content that can be viewed at a time, in pixels
386  */
388 
389  /**
390  * Use input from the scroll-wheel? True or false.
391  */
392  float m_BarSize;
393 
394  /**
395  * Scroll bar style reference name
396  */
398 
399  /**
400  * Pointer to scroll bar style used.
401  */
403 
404  /**
405  * Host object, prerequisite!
406  */
408 
409  /**
410  * Reference to CGUI object, these cannot work stand-alone
411  */
413 
414  /**
415  * Mouse position when bar was pressed
416  */
418 
419  //@}
420  //--------------------------------------------------------
421  /** @name States */
422  //--------------------------------------------------------
423  //@{
424 
425  /**
426  * If the bar is currently being pressed and dragged.
427  */
429 
430  /**
431  * Bar being hovered or not
432  */
434 
435  /**
436  * Scroll buttons hovered
437  */
439 
440  /**
441  * Scroll buttons pressed
442  */
444 
445  /**
446  * Position of scroll bar, 0 means scrolled all the way to one side.
447  * It is measured in pixels, it is up to the host to make it actually
448  * apply in pixels.
449  */
450  float m_Pos;
451 
452  /**
453  * Position from 0.f to 1.f it had when the bar was pressed.
454  */
456 
457  //@}
458 };
459 
460 #endif
virtual CRect GetBarRect() const =0
Get the rectangle of the actual BAR.
float m_MinimumBarSize
Sometimes there is a lot to scroll, but to prevent the scroll &quot;bar&quot; from being almost invisible (or u...
Definition: IGUIScrollBar.h:91
void SetScrollRange(float range)
Set content length.
void SetUseEdgeButtons(bool b)
Set use edge buttons.
virtual void SetPosFromMousePos(const CPos &mouse)=0
Set m_Pos with g_mouse_x/y input, i.e.
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
CGUISpriteInstance m_SpriteButtonRightDisabled
void SetZ(float z)
Set Z Position.
float m_X
Absolute X Position.
float m_Width
Width of bar, also both sides of the edge buttons.
Definition: IGUIScrollBar.h:67
The GUI Scroll-bar style.
Definition: IGUIScrollBar.h:57
void SetY(float y)
Set Y Position.
virtual void Draw()=0
Draw the scroll-bar.
virtual void HandleMessage(SGUIMessage &Message)=0
If an object that contains a scrollbar has got messages, send them to the scroll-bar and it will see ...
CGUISpriteInstance m_SpriteButtonBottomDisabled
CGUISpriteInstance m_SpriteButtonRightPressed
void SetGUI(CGUI *pGUI)
Set GUI pointer.
void SetLength(float length)
Set Length of scroll bar.
CGUISpriteInstance m_SpriteButtonLeftDisabled
bool m_ButtonMinusHovered
Scroll buttons hovered.
CGUISpriteInstance m_SpriteButtonTop
The main object that represents a whole GUI page.
Definition: CGUI.h:97
bool m_BarHovered
Bar being hovered or not.
IGUIScrollBarOwner * m_pHostObject
Host object, prerequisite!
virtual bool HoveringButtonMinus(const CPos &mouse)
Hovering the scroll minus button.
CGUISpriteInstance m_SpriteButtonTopPressed
CGUI * m_pGUI
Reference to CGUI object, these cannot work stand-alone.
CPos m_BarPressedAtPos
Mouse position when bar was pressed.
CGUISpriteInstance m_SpriteButtonTopDisabled
void SetX(float x)
Set X Position.
virtual void ScrollPlus()
Increase scroll one step.
float m_MaximumBarSize
Sometimes you would like your scroll bar to have a fixed maximum size so that the texture does not ge...
Definition: IGUIScrollBar.h:98
float m_PosWhenPressed
Position from 0.f to 1.f it had when the bar was pressed.
void SetBarPressed(bool b)
Set bar pressed.
bool m_ButtonPlusHovered
CGUISpriteInstance m_SpriteButtonTopOver
virtual void ScrollMinus()
Decrease scroll one step.
void SetupBarSize()
Sets up bar size.
void SetWidth(float width)
Set Width.
void UpdatePosBoundaries()
Call every time m_Pos has been updated.
float m_Z
Absolute Z Position.
float m_Y
Absolute Y Position.
virtual bool HoveringButtonPlus(const CPos &mouse)
Hovering the scroll plus button.
void SetScrollBarStyle(const CStr &style)
Set Scroll bar style string.
bool m_ButtonPlusPressed
SGUIScrollBarStyle * m_pStyle
Pointer to scroll bar style used.
CGUI * GetGUI() const
Get GUI pointer.
void SetHostObject(IGUIScrollBarOwner *pOwner)
Set host object, must be done almost at creation of scroll bar.
CGUISpriteInstance m_SpriteButtonBottomOver
float m_ScrollRange
Content that can be scrolled, in pixels.
float m_ScrollSpace
Content that can be viewed at a time, in pixels.
Made to represent screen positions and delta values.
Definition: Overlay.h:167
void SetScrollSpace(float space)
Set space that is visible in the scrollable control.
bool m_BarPressed
If the bar is currently being pressed and dragged.
CGUISpriteInstance m_SpriteBarVertical
CGUISpriteInstance m_SpriteBarVerticalPressed
float m_Pos
Position of scroll bar, 0 means scrolled all the way to one side.
float GetPos() const
Get scroll-position.
bool m_ButtonMinusPressed
Scroll buttons pressed.
CGUISpriteInstance m_SpriteBarVerticalOver
virtual void ScrollMinusPlenty()
Decrease scroll three steps.
CGUISpriteInstance m_SpriteButtonRight
virtual ~IGUIScrollBar()
CGUISpriteInstance m_SpriteButtonBottomPressed
CGUISpriteInstance m_SpriteButtonLeft
bool m_UseEdgeButtons
True if you want edge buttons, i.e.
virtual void SetPos(float f)
Set scroll-position by hand.
virtual CRect GetOuterRect() const =0
Get the rectangle of the outline of the scrollbar, every component of the scroll-bar should be inside...
The GUI Scroll-bar, used everywhere there is a scroll-bar in the game.
CGUISpriteInstance m_SpriteButtonLeftPressed
const SGUIScrollBarStyle * GetStyle() const
Get style used by the scrollbar.
virtual void ScrollPlusPlenty()
Increase scroll three steps.
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: GUIbase.h:106
CGUISpriteInstance m_SpriteButtonBottom
Base-class this if you want an object to contain one, or several, scroll-bars.
bool m_ScrollWheel
Scrollable with the wheel.
Definition: IGUIScrollBar.h:72
CGUISpriteInstance m_SpriteBackVertical
float GetMaxPos() const
Get the value of m_Pos that corresponds to the bottom of the scrollable region.
float m_ScrollSpeed
How much (in percent, 0.1f = 10%) to scroll each time the wheel is admitted, or the buttons are press...
Definition: IGUIScrollBar.h:78
CGUISpriteInstance m_SpriteBackHorizontal
float m_BarSize
Use input from the scroll-wheel? True or false.
CStr m_ScrollBarStyle
Scroll bar style reference name.
float m_Width
Width of the scroll bar.
CGUISpriteInstance m_SpriteBarHorizontal
Rectangle class used for screen rectangles.
Definition: Overlay.h:71
bool m_ScrollButtons
Whether or not the edge buttons should appear or not.
Definition: IGUIScrollBar.h:84
float m_Length
Total length of scrollbar, including edge buttons.