The Battle for Wesnoth  1.15.9+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  virtual void hide(bool value = true);
38 
39  /**
40  * Determine where the scrollbar is.
41  *
42  * @return the position.
43  * @retval returns 0 if the scrollbar is at the top or (full_size - shown_size) if it is at the bottom.
44  */
45  unsigned get_position() const;
46 
47  unsigned get_max_position() const;
48 
49  /** Manually update the scrollbar. */
50  void set_position(unsigned pos);
51 
52  /** Ensure the viewport contains the position. */
53  void adjust_position(unsigned pos);
54 
55  /** Move the scrollbar. */
56  void move_position(int dep);
57 
58  /** Set the relative size of the grip. */
59  void set_shown_size(unsigned h);
60 
61  /** Set the relative size of the scrollbar. */
62  void set_full_size(unsigned h);
63 
64  /** Set scroll rate. */
65  void set_scroll_rate(unsigned r);
66 
67  /** Return true if the scrollbar has a valid size. */
68  bool is_valid_height(int height) const;
69 
70  /** Scrolls down one step */
71  void scroll_down();
72 
73  /** Scrolls up one step */
74  void scroll_up();
75 
76 protected:
78  virtual void update_location(const SDL_Rect& rect);
79  virtual void handle_event(const SDL_Event& event);
80  virtual void process_event();
81  virtual void draw_contents();
82 
83 private:
84  SDL_Rect grip_area() const;
85  SDL_Rect groove_area() const;
87 
89 
92 
94  // Relative data
97 
98 };
99 
100 } // end namespace gui
Scrollbar.
Definition: scrollbar.hpp:25
std::vector< events::sdl_handler * > sdl_handler_vector
Definition: events.hpp:189
unsigned get_position() const
Determine where the scrollbar is.
Definition: scrollbar.cpp:103
virtual void handle_event(const SDL_Event &event)
Definition: scrollbar.cpp:316
Definition: video.hpp:31
button downarrow_
Definition: scrollbar.hpp:88
surface groove_scaled_
Definition: scrollbar.hpp:86
int minimum_grip_height_
Definition: scrollbar.hpp:93
unsigned int full_height_
Definition: scrollbar.hpp:95
unsigned get_max_position() const
Definition: scrollbar.cpp:108
General purpose widgets.
SDL_Rect grip_area() const
Definition: scrollbar.cpp:219
virtual void process_event()
Definition: scrollbar.cpp:196
#define h
button uparrow_
Definition: scrollbar.hpp:88
void scroll_down()
Scrolls down one step.
Definition: scrollbar.cpp:186
virtual void update_location(const SDL_Rect &rect)
Definition: scrollbar.cpp:82
virtual void hide(bool value=true)
Definition: scrollbar.cpp:96
void set_position(unsigned pos)
Manually update the scrollbar.
Definition: scrollbar.cpp:113
unsigned int grip_height_
Definition: scrollbar.hpp:95
void adjust_position(unsigned pos)
Ensure the viewport contains the position.
Definition: scrollbar.cpp:125
A button is a control that can be pushed to start an action or close a dialog.
Definition: button.hpp:49
SDL_Rect groove_area() const
Definition: scrollbar.cpp:205
virtual void draw_contents()
Definition: scrollbar.cpp:231
int height() const
Definition: widget.cpp:129
virtual sdl_handler_vector handler_members()
Definition: scrollbar.cpp:74
void scroll_up()
Scrolls up one step.
Definition: scrollbar.cpp:191
CVideo & video() const
Definition: widget.hpp:83
void set_shown_size(unsigned h)
Set the relative size of the grip.
Definition: scrollbar.cpp:142
surface mid_scaled_
Definition: scrollbar.hpp:86
bool is_valid_height(int height) const
Return true if the scrollbar has a valid size.
Definition: scrollbar.cpp:175
scrollbar(CVideo &video)
Create a scrollbar.
Definition: scrollbar.cpp:46
void set_full_size(unsigned h)
Set the relative size of the scrollbar.
Definition: scrollbar.cpp:156
void set_scroll_rate(unsigned r)
Set scroll rate.
Definition: scrollbar.cpp:170
unsigned int grip_position_
Definition: scrollbar.hpp:95
void move_position(int dep)
Move the scrollbar.
Definition: scrollbar.cpp:133