The Battle for Wesnoth  1.17.0-dev
scrollbar.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 by David White <dave@whitevine.net>
3  2004 - 2015 by Guillaume Melquiond <guillaume.melquiond@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "button.hpp"
19 
20 namespace gui {
21 
22 class scrollarea;
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
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;
78 
81 
83  // Relative data
86 
87 };
88 
89 } // end namespace gui
Scrollbar.
Definition: scrollbar.hpp:25
unsigned get_position() const
Determine where the scrollbar is.
Definition: scrollbar.cpp:65
virtual void handle_event(const SDL_Event &event)
Definition: scrollbar.cpp:223
Definition: video.hpp:31
surface groove_scaled_
Definition: scrollbar.hpp:77
int minimum_grip_height_
Definition: scrollbar.hpp:82
unsigned int full_height_
Definition: scrollbar.hpp:84
unsigned get_max_position() const
Definition: scrollbar.cpp:70
General purpose widgets.
SDL_Rect grip_area() const
Definition: scrollbar.cpp:144
#define h
void scroll_down()
Scrolls down one step.
Definition: scrollbar.cpp:134
void set_position(unsigned pos)
Manually update the scrollbar.
Definition: scrollbar.cpp:75
unsigned int grip_height_
Definition: scrollbar.hpp:84
void adjust_position(unsigned pos)
Ensure the viewport contains the position.
Definition: scrollbar.cpp:85
virtual void draw_contents()
Definition: scrollbar.cpp:156
void scroll_up()
Scrolls up one step.
Definition: scrollbar.cpp:139
CVideo & video() const
Definition: widget.hpp:83
void set_shown_size(unsigned h)
Set the relative size of the grip.
Definition: scrollbar.cpp:102
surface mid_scaled_
Definition: scrollbar.hpp:77
scrollbar(CVideo &video)
Create a scrollbar.
Definition: scrollbar.cpp:44
void set_full_size(unsigned h)
Set the relative size of the scrollbar.
Definition: scrollbar.cpp:116
void set_scroll_rate(unsigned r)
Set scroll rate.
Definition: scrollbar.cpp:129
unsigned int grip_position_
Definition: scrollbar.hpp:84
void move_position(int dep)
Move the scrollbar.
Definition: scrollbar.cpp:93