The Battle for Wesnoth  1.17.0-dev
vertical_scrollbar.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
3  by Mark de Wever <koraq@xs4all.nl>
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 
19 
20 namespace gui2
21 {
22 namespace implementation
23 {
24 struct builder_vertical_scrollbar;
25 }
26 
27 // ------------ WIDGET -----------{
28 
29 /**
30  * @ingroup GUIWidgetWML
31  *
32  * The definition of a vertical scrollbar.
33  * This class is most of the time not used directly.
34  * Instead it's used to build other items with scrollbars.
35  *
36  * The resolution for a vertical scrollbar also contains the following keys:
37  * Key |Type |Default |Description
38  * -------------------------|------------------------------------|---------|-------------
39  * minimum_positioner_length| @ref guivartype_unsigned "unsigned"|mandatory|The minimum size the positioner is allowed to be. The engine needs to know this in order to calculate the best size for the positioner.
40  * maximum_positioner_length| @ref guivartype_unsigned "unsigned"|0 |The maximum size the positioner is allowed to be. If minimum and maximum are the same value the positioner is fixed size. If the maximum is 0 (and the minimum not) there's no maximum.
41  * top_offset | @ref guivartype_unsigned "unsigned"|0 |The number of pixels at the top which can't be used by the positioner.
42  * bottom_offset | @ref guivartype_unsigned "unsigned"|0 |The number of pixels at the bottom which can't be used by the positioner.
43  * The following states exist:
44  * * state_enabled - the vertical scrollbar is enabled.
45  * * state_disabled - the vertical scrollbar is disabled.
46  * * state_pressed - the left mouse button is down on the positioner of the vertical scrollbar.
47  * * state_focussed - the mouse is over the positioner of the vertical scrollbar.
48  */
50 {
52 
53 public:
55 
56 private:
57  /** Inherited from scrollbar_base. */
58  virtual unsigned get_length() const override
59  {
60  return get_height();
61  }
62 
63  /** Inherited from scrollbar_base. */
64  virtual unsigned minimum_positioner_length() const override;
65 
66  /** Inherited from scrollbar_base. */
67  virtual unsigned maximum_positioner_length() const override;
68 
69  /** Inherited from scrollbar_base. */
70  virtual unsigned offset_before() const override;
71 
72  /** Inherited from scrollbar_base. */
73  virtual unsigned offset_after() const override;
74 
75  /** Inherited from scrollbar_base. */
76  virtual bool on_positioner(const point& coordinate) const override;
77 
78  /** Inherited from scrollbar_base. */
79  virtual int on_bar(const point& coordinate) const override;
80 
81  /** Inherited from scrollbar_base. */
82  virtual bool in_orthogonal_range(const point& coordinate) const override;
83 
84  /** Inherited from scrollbar_base. */
85  virtual int get_length_difference(const point& original, const point& current) const override
86  {
87  return current.y - original.y;
88  }
89 
90 public:
91  /** Static type getter that does not rely on the widget being constructed. */
92  static const std::string& type();
93 
94 private:
95  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
96  virtual const std::string& get_control_type() const override;
97 };
98 
99 // }---------- DEFINITION ---------{
100 
102 {
103  explicit vertical_scrollbar_definition(const config& cfg);
104 
106  {
107  explicit resolution(const config& cfg);
108 
111 
112  unsigned top_offset;
113  unsigned bottom_offset;
114  };
115 };
116 
117 // }---------- BUILDER -----------{
118 
119 namespace implementation
120 {
121 
123 {
124  explicit builder_vertical_scrollbar(const config& cfg);
125 
127 
128  virtual widget* build() const override;
129 };
130 
131 } // namespace implementation
132 
133 // }------------ END --------------
134 
135 } // namespace gui2
Base class for a scroll bar.
Definition: scrollbar.hpp:41
Base class of a resolution, contains the common keys for a resolution.
virtual widget * build() const =0
virtual unsigned get_length() const override
Inherited from scrollbar_base.
Base class for all widgets.
Definition: widget.hpp:49
Generic file dialog.
Definition: field-fwd.hpp:23
Holds a 2D point.
Definition: point.hpp:24
virtual int get_length_difference(const point &original, const point &current) const override
Inherited from scrollbar_base.
point resolution()
Definition: general.cpp:393
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
The definition of a vertical scrollbar.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
int y
y coordinate.
Definition: point.hpp:48
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.