The Battle for Wesnoth  1.17.0-dev
panel.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 
22 
23 namespace gui2
24 {
25 namespace implementation
26 {
27 struct builder_panel;
28 }
29 
30 // ------------ WIDGET -----------{
31 
32 /**
33  * @ingroup GUIWidgetWML
34  *
35  * A panel is a visible container to hold multiple widgets.
36  * The difference between a grid and a panel is that it's possible to define how a panel looks.
37  * A grid in an invisible container to just hold the items.
38  * A panel is always enabled and can't be disabled.
39  * Instead it uses the states as layers to draw on and can draw items beyond the widgets it holds and in front of them.
40  * A panel is always active so some functions return dummy values.
41  *
42  * The widget instance has the following:
43  * Key |Type |Default |Description
44  * -------------|----------------------------|---------|-----------
45  * grid | @ref guivartype_grid "grid"|mandatory|Defines the grid with the widgets to place on the panel.
46  *
47  * The resolution for a panel also contains the following keys:
48  * Key |Type |Default|Description
49  * -------------|------------------------------------|-------|-------------
50  * top_border | @ref guivartype_unsigned "unsigned"|0 |The size which isn't used for the client area.
51  * bottom_border| @ref guivartype_unsigned "unsigned"|0 |The size which isn't used for the client area.
52  * left_border | @ref guivartype_unsigned "unsigned"|0 |The size which isn't used for the client area.
53  * right_border | @ref guivartype_unsigned "unsigned"|0 |The size which isn't used for the client area.
54  * The following layers exist:
55  * * background - the background of the panel.
56  * * foreground - the foreground of the panel.
57  */
58 class panel : public container_base
59 {
60 public:
61  /**
62  * Constructor.
63  */
64  panel(const implementation::builder_styled_widget& builder, const std::string& control_type = "");
65 
66  /** See @ref container_base::get_client_rect. */
67  virtual SDL_Rect get_client_rect() const override;
68 
69  /** See @ref styled_widget::get_active. */
70  virtual bool get_active() const override;
71 
72  /** See @ref styled_widget::get_state. */
73  virtual unsigned get_state() const override;
74 
75 private:
76  /** See @ref widget::impl_draw_background. */
77  virtual void impl_draw_background(surface& frame_buffer,
78  int x_offset,
79  int y_offset) override;
80 
81  /** See @ref widget::impl_draw_foreground. */
82  virtual void impl_draw_foreground(surface& frame_buffer,
83  int x_offset,
84  int y_offset) override;
85 
86 public:
87  /** Static type getter that does not rely on the widget being constructed. */
88  static const std::string& type();
89 
90 private:
91  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
92  virtual const std::string& get_control_type() const override;
93 
94  /** See @ref container_base::border_space. */
95  virtual point border_space() const override;
96 
97  /** See @ref container_base::set_self_active. */
98  virtual void set_self_active(const bool active) override;
99 };
100 
101 // }---------- DEFINITION ---------{
102 
104 {
105  explicit panel_definition(const config& cfg);
106 
108  {
109  explicit resolution(const config& cfg);
110 
111  unsigned top_border;
112  unsigned bottom_border;
113 
114  unsigned left_border;
115  unsigned right_border;
116  };
117 };
118 
119 // }---------- BUILDER -----------{
120 
121 namespace implementation
122 {
123 
125 {
126  explicit builder_panel(const config& cfg);
127 
129 
130  virtual widget* build() const override;
131 
133 };
134 
135 } // namespace implementation
136 
137 // }------------ END --------------
138 
139 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
virtual widget * build() const =0
A panel is a visible container to hold multiple widgets.
Definition: panel.hpp:58
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
A generic container base class.
point resolution()
Definition: general.cpp:393
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
std::shared_ptr< builder_grid > builder_grid_ptr
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.