The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
spacer.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
17 #include "gui/widgets/spacer.hpp"
18 
20 #include "gui/widgets/settings.hpp"
21 
22 #include "utils/functional.hpp"
23 
24 namespace gui2
25 {
26 
27 // ------------ WIDGET -----------{
28 
29 REGISTER_WIDGET(spacer)
30 
31 tpoint tspacer::calculate_best_size() const
32 {
33  return best_size_ != tpoint(0, 0) ? best_size_
35 }
36 
37 void tspacer::set_active(const bool /*active*/)
38 {
39  /* DO NOTHING */
40 }
41 
42 bool tspacer::get_active() const
43 {
44  return true;
45 }
46 
47 unsigned tspacer::get_state() const
48 {
49  return 0;
50 }
51 
53 {
54  return false;
55 }
56 
57 void tspacer::impl_draw_background(surface& /*frame_buffer*/
58  ,
59  int /*x_offset*/
60  ,
61  int /*y_offset*/)
62 {
63  /* DO NOTHING */
64 }
65 
67 {
68  static const std::string type = "spacer";
69  return type;
70 }
71 
72 // }---------- DEFINITION ---------{
73 
75  : tcontrol_definition(cfg)
76 {
77  DBG_GUI_P << "Parsing spacer " << id << '\n';
78 
79  load_resolutions<tresolution>(cfg);
80 }
81 
82 /*WIKI
83  * @page = GUIWidgetDefinitionWML
84  * @order = 1_spacer
85  *
86  * == Spacer ==
87  *
88  * @macro = spacer_description
89  *
90  * A spacer has no states so nothing to load.
91  * @begin{parent}{name="gui/"}
92  * @begin{tag}{name="spacer_definition"}{min=0}{max=-1}{super="generic/widget_definition"}
93  * @end{tag}{name="spacer_definition"}
94  * @end{parent}{name="gui/"}
95  */
98 {
99 }
100 
101 // }---------- BUILDER -----------{
102 
103 /*WIKI_MACRO
104  * @begin{macro}{spacer_description}
105  *
106  * A spacer is a dummy item to either fill in a widget since no empty
107  * items are allowed or to reserve a fixed space.
108  * @end{macro}
109  */
110 
111 
112 /*WIKI
113  * @page = GUIWidgetInstanceWML
114  * @order = 2_spacer
115  * @begin{parent}{name="gui/window/resolution/grid/row/column/"}
116  * @begin{tag}{name="spacer"}{min=0}{max=-1}{super="generic/widget_instance"}
117  * == Spacer ==
118  *
119  * @macro = spacer_description
120  *
121  * If either the width or the height is non-zero the spacer functions as a
122  * fixed size spacer.
123  *
124  * @begin{table}{config}
125  * width & f_unsigned & 0 & The width of the spacer. $
126  * height & f_unsigned & 0 & The height of the spacer. $
127  * @end{table}
128  *
129  * The variable available are the same as for the window resolution see
130  * http://www.wesnoth.org/wiki/GUIToolkitWML#Resolution_2 for the list of
131  * items.
132  * @end{tag}{name="spacer"}
133  * @end{parent}{name="gui/window/resolution/grid/row/column/"}
134  */
135 
136 namespace implementation
137 {
138 
139 tbuilder_spacer::tbuilder_spacer(const config& cfg)
140  : tbuilder_control(cfg), width_(cfg["width"]), height_(cfg["height"])
141 {
142 }
143 
145 {
146  tspacer* widget = new tspacer();
147 
148  init_control(widget);
149 
151 
152  const unsigned width = width_(size);
153  const unsigned height = height_(size);
154 
155  if(width || height) {
156  widget->set_best_size(tpoint(width, height));
157  }
158 
159  DBG_GUI_G << "Window builder: placed spacer '" << id
160  << "' with definition '" << definition << "'.\n";
161 
162  return widget;
163 }
164 
165 } // namespace implementation
166 
167 // }------------ END --------------
168 
169 } // namespace gui2
#define DBG_GUI_P
Definition: log.hpp:69
virtual unsigned get_state() const override
See tcontrol::get_state.
Definition: spacer.cpp:47
bool disable_click_dismiss() const override
See twidget::disable_click_dismiss.
Definition: spacer.cpp:52
tformula< unsigned > height_
Definition: spacer.hpp:113
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: spacer.cpp:37
tresolution(const config &cfg)
Definition: spacer.cpp:96
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
void set_best_size(const tpoint &best_size)
Definition: spacer.hpp:68
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
Definition: spacer.cpp:66
Base class of a resolution, contains the common keys for a resolution.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
void init_control(tcontrol *control) const
Definition: control.cpp:675
std::string definition
Parameters for the control.
Definition: control.hpp:530
tspacer_definition(const config &cfg)
Definition: spacer.cpp:74
This file contains the settings handling of the widget library.
An empty widget.
Definition: spacer.hpp:38
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
Holds a 2D point.
Definition: point.hpp:24
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1220
GLsizeiptr size
Definition: glew.h:1649
virtual bool get_active() const override
See tcontrol::get_active.
Definition: spacer.cpp:42
Base class for all widgets.
Definition: widget.hpp:49
virtual void impl_draw_background(surface &frame_buffer, int x_offset, int y_offset) override
See twidget::impl_draw_background.
Definition: spacer.cpp:57
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1220
void get_screen_size_variables(game_logic::map_formula_callable &variable)
Gets a formula object with the screen size.
Definition: helper.cpp:132
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
#define DBG_GUI_G
Definition: log.hpp:41
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Contains the implementation details for lexical_cast and shouldn't be used directly.
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
Definition: control.cpp:229