-
-
Notifications
You must be signed in to change notification settings - Fork 991
/
drawing.cpp
203 lines (166 loc) · 5.08 KB
/
drawing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
Copyright (C) 2010 - 2017 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/widgets/drawing.hpp"
#include "gui/core/widget_definition.hpp"
#include "gui/core/window_builder.hpp"
#include "gui/core/register_widget.hpp"
#include "gui/widgets/settings.hpp"
#include "utils/functional.hpp"
namespace gui2
{
// ------------ WIDGET -----------{
REGISTER_WIDGET(drawing)
drawing::drawing(const implementation::builder_drawing& builder)
: styled_widget(builder, get_control_type())
, best_size_(0, 0)
{
}
point drawing::calculate_best_size() const
{
return best_size_ != point() ? best_size_
: styled_widget::calculate_best_size();
}
void drawing::request_reduce_width(const unsigned maximum_width)
{
if(best_size_ != point()) {
// This drawing is of fixed size, do nothing.
} else {
styled_widget::request_reduce_width(maximum_width);
}
}
void drawing::request_reduce_height(const unsigned maximum_height)
{
if(best_size_ != point()) {
// This drawing is of fixed size, do nothing.
} else {
styled_widget::request_reduce_height(maximum_height);
}
}
void drawing::set_active(const bool /*active*/)
{
/* DO NOTHING */
}
bool drawing::get_active() const
{
return true;
}
unsigned drawing::get_state() const
{
return 0;
}
bool drawing::disable_click_dismiss() const
{
return false;
}
// }---------- DEFINITION ---------{
drawing_definition::drawing_definition(const config& cfg)
: styled_widget_definition(cfg)
{
DBG_GUI_P << "Parsing drawing " << id << '\n';
load_resolutions<resolution>(cfg);
}
/*WIKI
* @page = GUIWidgetDefinitionWML
* @order = 1_drawing
*
* == Drawing ==
*
* @macro = drawing_description
*
* The definition of a drawing. The widget normally has no event interaction
* so only one state is defined.
*
* The following states exist:
* * state_enabled
* the drawing is enabled. The state is a dummy since the
* things really drawn are placed in the window instance.
* @begin{parent}{name="gui/"}
* @begin{tag}{name="drawing_definition"}{min=0}{max=-1}{super="generic/widget_definition"}
* @begin{tag}{name="resolution"}{min=0}{max=-1}{super="generic/widget_definition/resolution"}
* @begin{tag}{name="state_enabled"}{min=0}{max=1}{super="generic/state"}
* @end{tag}{name="state_enabled"}
* @end{tag}{name="resolution"}
* @end{tag}{name="drawing_definition"}
* @end{parent}{name="gui/"}
*/
drawing_definition::resolution::resolution(const config& cfg)
: resolution_definition(cfg)
{
/*
* Note the order should be the same as the enum state_t in drawing.hpp.
* Normally the [draw] section is in the config, but for this widget the
* original draw section is ignored, so send a dummy.
*/
static const config dummy("draw");
state.emplace_back(dummy);
}
// }---------- BUILDER -----------{
/*WIKI_MACRO
* @begin{macro}{drawing_description}
*
* A drawing is widget with a fixed size and gives access to the
* canvas of the widget in the window instance. This allows special
* display only widgets.
* @end{macro}
*/
/*WIKI
* @page = GUIWidgetInstanceWML
* @order = 2_drawing
*
* == Spacer ==
* @begin{parent}{name="gui/window/resolution/grid/row/column/"}
* @begin{tag}{name="drawing"}{min=0}{max=-1}{super="generic/widget_instance"}
* @macro = drawing_description
*
* If either the width or the height is not zero the drawing functions as a
* fixed size drawing.
*
* @begin{table}{config}
* width & f_unsigned & 0 & The width of the drawing. $
* height & f_unsigned & 0 & The height of the drawing. $
* draw & config & & The config containing the drawing. $
* @end{table}
* @allow{link}{name="generic/state/draw"}
* @end{tag}{name="drawing"}
* @end{parent}{name="gui/window/resolution/grid/row/column/"}
* The variable available are the same as for the window resolution see
* http://www.wesnoth.org/wiki/GUIToolkitWML#Resolution_2 for the list of
* items.
*/
namespace implementation
{
builder_drawing::builder_drawing(const config& cfg)
: builder_styled_widget(cfg)
, width(cfg["width"])
, height(cfg["height"])
, draw(cfg.child("draw"))
{
assert(!draw.empty());
}
widget* builder_drawing::build() const
{
drawing* widget = new drawing(*this);
const wfl::map_formula_callable& size = get_screen_size_variables();
const unsigned w = width(size);
const unsigned h = height(size);
if(w || h) {
widget->set_best_size(point(w, h));
}
widget->set_drawing_data(draw);
DBG_GUI_G << "Window builder: placed drawing '" << id
<< "' with definition '" << definition << "'.\n";
return widget;
}
} // namespace implementation
// }------------ END --------------
} // namespace gui2