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