The Battle for Wesnoth  1.15.12+dev
vertical_scrollbar.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
18 
19 namespace gui2
20 {
21 namespace implementation
22 {
23 struct builder_vertical_scrollbar;
24 }
25 
26 // ------------ WIDGET -----------{
27 
28 /**
29  * @ingroup GUIWidgetWML
30  *
31  * The definition of a vertical scrollbar.
32  * This class is most of the time not used directly.
33  * Instead it's used to build other items with scrollbars.
34  *
35  * The resolution for a vertical scrollbar also contains the following keys:
36  * Key |Type |Default |Description
37  * -------------------------|------------------------------------|---------|-------------
38  * 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.
39  * 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.
40  * top_offset | @ref guivartype_unsigned "unsigned"|0 |The number of pixels at the top which can't be used by the positioner.
41  * bottom_offset | @ref guivartype_unsigned "unsigned"|0 |The number of pixels at the bottom which can't be used by the positioner.
42  * The following states exist:
43  * * state_enabled - the vertical scrollbar is enabled.
44  * * state_disabled - the vertical scrollbar is disabled.
45  * * state_pressed - the left mouse button is down on the positioner of the vertical scrollbar.
46  * * state_focussed - the mouse is over the positioner of the vertical scrollbar.
47  */
49 {
51 
52 public:
54 
55 private:
56  /** Inherited from scrollbar_base. */
57  virtual unsigned get_length() const override
58  {
59  return get_height();
60  }
61 
62  /** Inherited from scrollbar_base. */
63  virtual unsigned minimum_positioner_length() const override;
64 
65  /** Inherited from scrollbar_base. */
66  virtual unsigned maximum_positioner_length() const override;
67 
68  /** Inherited from scrollbar_base. */
69  virtual unsigned offset_before() const override;
70 
71  /** Inherited from scrollbar_base. */
72  virtual unsigned offset_after() const override;
73 
74  /** Inherited from scrollbar_base. */
75  virtual bool on_positioner(const point& coordinate) const override;
76 
77  /** Inherited from scrollbar_base. */
78  virtual int on_bar(const point& coordinate) const override;
79 
80  /** Inherited from scrollbar_base. */
81  virtual bool in_orthogonal_range(const point& coordinate) const override;
82 
83  /** Inherited from scrollbar_base. */
84  virtual int get_length_difference(const point& original, const point& current) const override
85  {
86  return current.y - original.y;
87  }
88 
89 public:
90  /** Static type getter that does not rely on the widget being constructed. */
91  static const std::string& type();
92 
93 private:
94  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
95  virtual const std::string& get_control_type() const override;
96 };
97 
98 // }---------- DEFINITION ---------{
99 
101 {
102  explicit vertical_scrollbar_definition(const config& cfg);
103 
105  {
106  explicit resolution(const config& cfg);
107 
110 
111  unsigned top_offset;
112  unsigned bottom_offset;
113  };
114 };
115 
116 // }---------- BUILDER -----------{
117 
118 namespace implementation
119 {
120 
122 {
123  explicit builder_vertical_scrollbar(const config& cfg);
124 
126 
127  virtual widget* build() const override;
128 };
129 
130 } // namespace implementation
131 
132 // }------------ END --------------
133 
134 } // namespace gui2
Base class for a scroll bar.
Definition: scrollbar.hpp:40
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:22
Holds a 2D point.
Definition: point.hpp:23
virtual int get_length_difference(const point &original, const point &current) const override
Inherited from scrollbar_base.
point resolution()
Definition: general.cpp:387
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:59
int y
y coordinate.
Definition: point.hpp:47
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.