The Battle for Wesnoth  1.17.0-dev
scrollarea.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004 - 2021
3  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 "scrollbar.hpp"
19 
20 namespace gui {
21 
22 class scrollarea : public widget
23 {
24 public:
25  /**
26  * Create a zone with automatic handling of scrollbar.
27  * @todo FIXME: parameterlist ??
28  */
29  //- \param d the display object
30  //- \param pane the widget where wheel events take place
31  scrollarea(CVideo &video, bool auto_join=true);
32 
33  virtual void hide(bool value = true);
34 
35 protected:
37  virtual void update_location(const SDL_Rect& rect);
38  virtual void handle_event(const SDL_Event& event);
39  virtual void process_event();
40  virtual void scroll(unsigned int pos) = 0;
41  virtual void set_inner_location(const SDL_Rect& rect) = 0;
42 
43  SDL_Rect inner_location() const;
44  unsigned scrollbar_width() const;
45 
46  unsigned get_position() const;
47  unsigned get_max_position() const;
48  void set_position(unsigned pos);
49  void adjust_position(unsigned pos);
50  void move_position(int dep);
51  void set_shown_size(unsigned h);
52  void set_full_size(unsigned h);
53  void set_scroll_rate(unsigned r);
54  bool has_scrollbar() const;
55 
56 private:
60  unsigned shown_size_;
61  unsigned full_size_;
62  int swipe_dy_;
63  struct {
64  int x;
65  int y;
66  } swipe_origin_;
67 
68  void test_scrollbar();
69 };
70 
71 } // end namespace gui
Scrollbar.
Definition: scrollbar.hpp:26
virtual void set_inner_location(const SDL_Rect &rect)=0
void set_shown_size(unsigned h)
Definition: scrollarea.cpp:108
void adjust_position(unsigned pos)
Definition: scrollarea.cpp:98
std::vector< events::sdl_handler * > sdl_handler_vector
Definition: events.hpp:190
unsigned scrollbar_width() const
Definition: scrollarea.cpp:144
virtual sdl_handler_vector handler_members()
Definition: scrollarea.cpp:38
Definition: video.hpp:32
struct gui::scrollarea::@28 swipe_origin_
General purpose widgets.
virtual void update_location(const SDL_Rect &rect)
Definition: scrollarea.cpp:45
#define h
void set_scroll_rate(unsigned r)
Definition: scrollarea.cpp:122
void test_scrollbar()
Definition: scrollarea.cpp:63
void move_position(int dep)
Definition: scrollarea.cpp:103
virtual void scroll(unsigned int pos)=0
void set_full_size(unsigned h)
Definition: scrollarea.cpp:115
bool has_scrollbar() const
Definition: scrollarea.cpp:33
void set_position(unsigned pos)
Definition: scrollarea.cpp:93
unsigned full_size_
Definition: scrollarea.hpp:61
scrollbar scrollbar_
Definition: scrollarea.hpp:57
virtual void handle_event(const SDL_Event &event)
Definition: scrollarea.cpp:149
SDL_Rect inner_location() const
Definition: scrollarea.cpp:136
unsigned get_max_position() const
Definition: scrollarea.cpp:88
virtual void hide(bool value=true)
Definition: scrollarea.cpp:76
CVideo & video() const
Definition: widget.hpp:84
unsigned shown_size_
Definition: scrollarea.hpp:60
scrollarea(CVideo &video, bool auto_join=true)
Create a zone with automatic handling of scrollbar.
Definition: scrollarea.cpp:25
virtual void process_event()
Definition: scrollarea.cpp:127
unsigned get_position() const
Definition: scrollarea.cpp:83