The Battle for Wesnoth  1.17.0-dev
scrollbar.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004 - 2021
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 class scrollarea;
24 
25 /** Scrollbar */
26 class scrollbar : public widget
27 {
28 public:
29  /**
30  * Create a scrollbar.
31  * @todo FIXME: parameterlist ??
32  */
33  //- @param d the display object
34  //- @param pane the widget where wheel events take place
35  //- @param callback a callback interface for warning that the grip has been moved
37 
38  /**
39  * Determine where the scrollbar is.
40  *
41  * @return the position.
42  * @retval returns 0 if the scrollbar is at the top or (full_size - shown_size) if it is at the bottom.
43  */
44  unsigned get_position() const;
45 
46  unsigned get_max_position() const;
47 
48  /** Manually update the scrollbar. */
49  void set_position(unsigned pos);
50 
51  /** Ensure the viewport contains the position. */
52  void adjust_position(unsigned pos);
53 
54  /** Move the scrollbar. */
55  void move_position(int dep);
56 
57  /** Set the relative size of the grip. */
58  void set_shown_size(unsigned h);
59 
60  /** Set the relative size of the scrollbar. */
61  void set_full_size(unsigned h);
62 
63  /** Set scroll rate. */
64  void set_scroll_rate(unsigned r);
65 
66  /** Scrolls down one step */
67  void scroll_down();
68 
69  /** Scrolls up one step */
70  void scroll_up();
71 
72 protected:
73  virtual void handle_event(const SDL_Event& event);
74  virtual void draw_contents();
75 
76 private:
77  SDL_Rect grip_area() const;
79 
82 
84  // Relative data
87 
88 };
89 
90 } // end namespace gui
Scrollbar.
Definition: scrollbar.hpp:26
unsigned get_position() const
Determine where the scrollbar is.
Definition: scrollbar.cpp:66
virtual void handle_event(const SDL_Event &event)
Definition: scrollbar.cpp:224
Definition: video.hpp:32
surface groove_scaled_
Definition: scrollbar.hpp:78
int minimum_grip_height_
Definition: scrollbar.hpp:83
unsigned int full_height_
Definition: scrollbar.hpp:85
unsigned get_max_position() const
Definition: scrollbar.cpp:71
General purpose widgets.
SDL_Rect grip_area() const
Definition: scrollbar.cpp:145
#define h
void scroll_down()
Scrolls down one step.
Definition: scrollbar.cpp:135
void set_position(unsigned pos)
Manually update the scrollbar.
Definition: scrollbar.cpp:76
unsigned int grip_height_
Definition: scrollbar.hpp:85
void adjust_position(unsigned pos)
Ensure the viewport contains the position.
Definition: scrollbar.cpp:86
virtual void draw_contents()
Definition: scrollbar.cpp:157
void scroll_up()
Scrolls up one step.
Definition: scrollbar.cpp:140
CVideo & video() const
Definition: widget.hpp:84
void set_shown_size(unsigned h)
Set the relative size of the grip.
Definition: scrollbar.cpp:103
surface mid_scaled_
Definition: scrollbar.hpp:78
scrollbar(CVideo &video)
Create a scrollbar.
Definition: scrollbar.cpp:45
void set_full_size(unsigned h)
Set the relative size of the scrollbar.
Definition: scrollbar.cpp:117
void set_scroll_rate(unsigned r)
Set scroll rate.
Definition: scrollbar.cpp:130
unsigned int grip_position_
Definition: scrollbar.hpp:85
void move_position(int dep)
Move the scrollbar.
Definition: scrollbar.cpp:94