The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
drawing.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 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/drawing.hpp"
18 
21 
23 #include "gui/widgets/settings.hpp"
24 
25 #include "utils/functional.hpp"
26 
27 namespace gui2
28 {
29 
30 // ------------ WIDGET -----------{
31 
32 REGISTER_WIDGET(drawing)
33 
34 tpoint tdrawing::calculate_best_size() const
35 {
36  return best_size_ != tpoint(0, 0) ? best_size_
38 }
39 
40 void tdrawing::set_active(const bool /*active*/)
41 {
42  /* DO NOTHING */
43 }
44 
46 {
47  return true;
48 }
49 
50 unsigned tdrawing::get_state() const
51 {
52  return 0;
53 }
54 
56 {
57  return false;
58 }
59 
61 {
62  static const std::string type = "drawing";
63  return type;
64 }
65 
66 // }---------- DEFINITION ---------{
67 
69  : tcontrol_definition(cfg)
70 {
71  DBG_GUI_P << "Parsing drawing " << id << '\n';
72 
73  load_resolutions<tresolution>(cfg);
74 }
75 
76 /*WIKI
77  * @page = GUIWidgetDefinitionWML
78  * @order = 1_drawing
79  *
80  * == Drawing ==
81  *
82  * @macro = drawing_description
83  *
84  * The definition of a drawing. The widget normally has no event interaction
85  * so only one state is defined.
86  *
87  * The following states exist:
88  * * state_enabled
89  * the drawing is enabled. The state is a dummy since the
90  * things really drawn are placed in the window instance.
91  * @begin{parent}{name="gui/"}
92  * @begin{tag}{name="drawing_definition"}{min=0}{max=-1}{super="generic/widget_definition"}
93  * @begin{tag}{name="resolution"}{min=0}{max=-1}{super="generic/widget_definition/resolution"}
94  * @begin{tag}{name="state_enabled"}{min=0}{max=1}{super="generic/state"}
95  * @end{tag}{name="state_enabled"}
96  * @end{tag}{name="resolution"}
97  * @end{tag}{name="drawing_definition"}
98  * @end{parent}{name="gui/"}
99  */
102 {
103  /*
104  * Note the order should be the same as the enum tstate in drawing.hpp.
105  * Normally the [draw] section is in the config, but for this widget the
106  * original draw section is ignored, so send a dummy.
107  */
108  static const config dummy("draw");
109  state.push_back(tstate_definition(dummy));
110 }
111 
112 // }---------- BUILDER -----------{
113 
114 /*WIKI_MACRO
115  * @begin{macro}{drawing_description}
116  *
117  * A drawing is widget with a fixed size and gives access to the
118  * canvas of the widget in the window instance. This allows special
119  * display only widgets.
120  * @end{macro}
121  */
122 
123 /*WIKI
124  * @page = GUIWidgetInstanceWML
125  * @order = 2_drawing
126  *
127  * == Spacer ==
128  * @begin{parent}{name="gui/window/resolution/grid/row/column/"}
129  * @begin{tag}{name="drawing"}{min=0}{max=-1}{super="generic/widget_instance"}
130  * @macro = drawing_description
131  *
132  * If either the width or the height is not zero the drawing functions as a
133  * fixed size drawing.
134  *
135  * @begin{table}{config}
136  * width & f_unsigned & 0 & The width of the drawing. $
137  * height & f_unsigned & 0 & The height of the drawing. $
138  * draw & config & & The config containing the drawing. $
139  * @end{table}
140  * @allow{link}{name="generic/state/draw"}
141  * @end{tag}{name="drawing"}
142  * @end{parent}{name="gui/window/resolution/grid/row/column/"}
143  * The variable available are the same as for the window resolution see
144  * http://www.wesnoth.org/wiki/GUIToolkitWML#Resolution_2 for the list of
145  * items.
146  */
147 
148 namespace implementation
149 {
150 
151 tbuilder_drawing::tbuilder_drawing(const config& cfg)
152  : tbuilder_control(cfg)
153  , width(cfg["width"])
154  , height(cfg["height"])
155  , draw(cfg.child("draw"))
156 {
157  assert(!draw.empty());
158 }
159 
161 {
162  tdrawing* widget = new tdrawing();
163 
164  init_control(widget);
165 
167 
168  const unsigned w = width(size);
169  const unsigned h = height(size);
170 
171  if(w || h) {
172  widget->set_best_size(tpoint(w, h));
173  }
174 
175  widget->canvas().front().set_cfg(draw);
176 
177  DBG_GUI_G << "Window builder: placed drawing '" << id
178  << "' with definition '" << definition << "'.\n";
179 
180  return widget;
181 }
182 
183 } // namespace implementation
184 
185 // }------------ END --------------
186 
187 } // namespace gui2
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
Definition: drawing.cpp:60
#define DBG_GUI_P
Definition: log.hpp:69
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
virtual bool get_active() const override
See tcontrol::get_active.
Definition: drawing.cpp:45
A widget to draw upon.
Definition: drawing.hpp:34
void set_best_size(const tpoint &best_size)
Definition: drawing.hpp:64
bool empty() const
Definition: config.cpp:1105
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
This file contains the settings handling of the widget library.
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1858
config draw
Config containing what to draw on the widgets canvas.
Definition: drawing.hpp:120
void draw(surface screen)
virtual void set_active(const bool active) override
See tcontrol::set_active.
Definition: drawing.cpp:40
Contains the state info for a resolution.
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
virtual unsigned get_state() const override
See tcontrol::get_state.
Definition: drawing.cpp:50
tformula< unsigned > height
The height of the widget.
Definition: drawing.hpp:117
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:5910
Holds a 2D point.
Definition: point.hpp:24
std::vector< tcanvas > & canvas()
Definition: control.hpp:282
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1220
GLsizeiptr size
Definition: glew.h:1649
tformula< unsigned > width
The width of the widget.
Definition: drawing.hpp:114
std::vector< tstate_definition > state
Base class for all widgets.
Definition: widget.hpp:49
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
tdrawing_definition(const config &cfg)
Definition: drawing.cpp:68
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
bool disable_click_dismiss() const override
See twidget::disable_click_dismiss.
Definition: drawing.cpp:55
#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