The Battle for Wesnoth  1.15.1+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 /** @file */
17 
18 #pragma once
19 
20 #include "button.hpp"
21 
22 namespace gui {
23 
24 class scrollarea;
25 
26 /** Scrollbar */
27 class scrollbar : public widget
28 {
29 public:
30  /**
31  * Create a scrollbar.
32  * @todo FIXME: parameterlist ??
33  */
34  //- @param d the display object
35  //- @param pane the widget where wheel events take place
36  //- @param callback a callback interface for warning that the grip has been moved
38 
39  virtual void hide(bool value = true);
40 
41  /**
42  * Determine where the scrollbar is.
43  *
44  * @return the position.
45  * @retval returns 0 if the scrollbar is at the top,
46  * @retval returns (full_size - shown_size) if it is at the bottom.
47  */
48  unsigned get_position() const;
49 
50  unsigned get_max_position() const;
51 
52  /** Manually update the scrollbar. */
53  void set_position(unsigned pos);
54 
55  /** Ensure the viewport contains the position. */
56  void adjust_position(unsigned pos);
57 
58  /** Move the scrollbar. */
59  void move_position(int dep);
60 
61  /** Set the relative size of the grip. */
62  void set_shown_size(unsigned h);
63 
64  /** Set the relative size of the scrollbar. */
65  void set_full_size(unsigned h);
66 
67  /** Set scroll rate. */
68  void set_scroll_rate(unsigned r);
69 
70  /** Return true if the scrollbar has a valid size. */
71  bool is_valid_height(int height) const;
72 
73  /** Scrolls down one step */
74  void scroll_down();
75 
76  /** Scrolls up one step */
77  void scroll_up();
78 
79 protected:
81  virtual void update_location(const SDL_Rect& rect);
82  virtual void handle_event(const SDL_Event& event);
83  virtual void process_event();
84  virtual void draw_contents();
85 
86 private:
87  SDL_Rect grip_area() const;
88  SDL_Rect groove_area() const;
90 
92 
95 
97  // Relative data
100 
101 };
102 
103 } // end namespace gui
Scrollbar.
Definition: scrollbar.hpp:27
std::vector< events::sdl_handler * > sdl_handler_vector
Definition: events.hpp:189
unsigned get_position() const
Determine where the scrollbar is.
Definition: scrollbar.cpp:105
virtual void handle_event(const SDL_Event &event)
Definition: scrollbar.cpp:318
Definition: video.hpp:31
button downarrow_
Definition: scrollbar.hpp:91
surface groove_scaled_
Definition: scrollbar.hpp:89
int minimum_grip_height_
Definition: scrollbar.hpp:96
unsigned int full_height_
Definition: scrollbar.hpp:98
unsigned get_max_position() const
Definition: scrollbar.cpp:110
General purpose widgets.
SDL_Rect grip_area() const
Definition: scrollbar.cpp:221
virtual void process_event()
Definition: scrollbar.cpp:198
#define h
button uparrow_
Definition: scrollbar.hpp:91
void scroll_down()
Scrolls down one step.
Definition: scrollbar.cpp:188
virtual void update_location(const SDL_Rect &rect)
Definition: scrollbar.cpp:84
virtual void hide(bool value=true)
Definition: scrollbar.cpp:98
void set_position(unsigned pos)
Manually update the scrollbar.
Definition: scrollbar.cpp:115
unsigned int grip_height_
Definition: scrollbar.hpp:98
void adjust_position(unsigned pos)
Ensure the viewport contains the position.
Definition: scrollbar.cpp:127
SDL_Rect groove_area() const
Definition: scrollbar.cpp:207
virtual void draw_contents()
Definition: scrollbar.cpp:233
int height() const
Definition: widget.cpp:129
virtual sdl_handler_vector handler_members()
Definition: scrollbar.cpp:76
void scroll_up()
Scrolls up one step.
Definition: scrollbar.cpp:193
CVideo & video() const
Definition: widget.hpp:83
void set_shown_size(unsigned h)
Set the relative size of the grip.
Definition: scrollbar.cpp:144
surface mid_scaled_
Definition: scrollbar.hpp:89
bool is_valid_height(int height) const
Return true if the scrollbar has a valid size.
Definition: scrollbar.cpp:177
scrollbar(CVideo &video)
Create a scrollbar.
Definition: scrollbar.cpp:48
void set_full_size(unsigned h)
Set the relative size of the scrollbar.
Definition: scrollbar.cpp:158
void set_scroll_rate(unsigned r)
Set scroll rate.
Definition: scrollbar.cpp:172
unsigned int grip_position_
Definition: scrollbar.hpp:98
void move_position(int dep)
Move the scrollbar.
Definition: scrollbar.cpp:135