The Battle for Wesnoth  1.19.1+dev
scrollbar.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004 - 2024
3  by Guillaume Melquiond <guillaume.melquiond@gmail.com>
4  Copyright (C) 2003 by David White <dave@whitevine.net>
5  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY.
13 
14  See the COPYING file for more details.
15 */
16 
17 #pragma once
18 
19 #include "button.hpp"
20 
21 namespace gui {
22 
23 
24 /** Scrollbar */
25 class scrollbar : public widget
26 {
27 public:
28  /**
29  * Create a scrollbar.
30  * @todo FIXME: parameterlist ??
31  */
32  //- @param d the display object
33  //- @param pane the widget where wheel events take place
34  //- @param callback a callback interface for warning that the grip has been moved
35  scrollbar();
36 
37  /**
38  * Determine where the scrollbar is.
39  *
40  * @return the position.
41  * @retval returns 0 if the scrollbar is at the top or (full_size - shown_size) if it is at the bottom.
42  */
43  unsigned get_position() const;
44 
45  unsigned get_max_position() const;
46 
47  /** Manually update the scrollbar. */
48  void set_position(unsigned pos);
49 
50  /** Ensure the viewport contains the position. */
51  void adjust_position(unsigned pos);
52 
53  /** Move the scrollbar. */
54  void move_position(int dep);
55 
56  /** Set the relative size of the grip. */
57  void set_shown_size(unsigned h);
58 
59  /** Set the relative size of the scrollbar. */
60  void set_full_size(unsigned h);
61 
62  /** Set scroll rate. */
63  void set_scroll_rate(unsigned r);
64 
65  /** Scrolls down one step */
66  void scroll_down();
67 
68  /** Scrolls up one step */
69  void scroll_up();
70 
71 protected:
72  virtual void handle_event(const SDL_Event& event);
73  virtual void draw_contents();
74 
75 private:
76  SDL_Rect grip_area() const;
77 
80 
82  // Relative data
85 
86 };
87 
88 } // end namespace gui
Scrollbar.
Definition: scrollbar.hpp:26
SDL_Rect grip_area() const
Definition: scrollbar.cpp:144
scrollbar()
Create a scrollbar.
Definition: scrollbar.cpp:46
void set_shown_size(unsigned h)
Set the relative size of the grip.
Definition: scrollbar.cpp:102
virtual void draw_contents()
Definition: scrollbar.cpp:156
void set_scroll_rate(unsigned r)
Set scroll rate.
Definition: scrollbar.cpp:129
unsigned int grip_position_
Definition: scrollbar.hpp:83
void scroll_up()
Scrolls up one step.
Definition: scrollbar.cpp:139
void move_position(int dep)
Move the scrollbar.
Definition: scrollbar.cpp:93
int minimum_grip_height_
Definition: scrollbar.hpp:81
void set_position(unsigned pos)
Manually update the scrollbar.
Definition: scrollbar.cpp:75
void scroll_down()
Scrolls down one step.
Definition: scrollbar.cpp:134
void set_full_size(unsigned h)
Set the relative size of the scrollbar.
Definition: scrollbar.cpp:116
unsigned get_position() const
Determine where the scrollbar is.
Definition: scrollbar.cpp:65
unsigned int full_height_
Definition: scrollbar.hpp:83
unsigned int grip_height_
Definition: scrollbar.hpp:83
unsigned get_max_position() const
Definition: scrollbar.cpp:70
void adjust_position(unsigned pos)
Ensure the viewport contains the position.
Definition: scrollbar.cpp:85
virtual void handle_event(const SDL_Event &event)
Definition: scrollbar.cpp:219
General purpose widgets.
#define h