The Battle for Wesnoth  1.17.0-dev
drawing.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 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 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
18 #include "gui/widgets/drawing.hpp"
19 
22 
24 #include "gui/widgets/settings.hpp"
25 
26 #include <functional>
27 
28 namespace gui2
29 {
30 
31 // ------------ WIDGET -----------{
32 
33 REGISTER_WIDGET(drawing)
34 
35 drawing::drawing(const implementation::builder_drawing& builder)
36  : styled_widget(builder, type())
37  , best_size_(0, 0)
38 {
39 }
40 
42 {
43  return best_size_ != point() ? best_size_
45 }
46 
47 void drawing::request_reduce_width(const unsigned maximum_width)
48 {
49  if(best_size_ != point()) {
50  // This drawing is of fixed size, do nothing.
51  } else {
53  }
54 }
55 
56 void drawing::request_reduce_height(const unsigned maximum_height)
57 {
58  if(best_size_ != point()) {
59  // This drawing is of fixed size, do nothing.
60  } else {
62  }
63 }
64 
65 void drawing::set_active(const bool /*active*/)
66 {
67  /* DO NOTHING */
68 }
69 
70 bool drawing::get_active() const
71 {
72  return true;
73 }
74 
75 unsigned drawing::get_state() const
76 {
77  return 0;
78 }
79 
81 {
82  return false;
83 }
84 
85 // }---------- DEFINITION ---------{
86 
89 {
90  DBG_GUI_P << "Parsing drawing " << id << '\n';
91 
92  load_resolutions<resolution>(cfg);
93 }
94 
97 {
98  /*
99  * Note the order should be the same as the enum state_t in drawing.hpp.
100  * Normally the [draw] section is in the config, but for this widget the
101  * original draw section is ignored, so send a dummy.
102  */
103  static const config dummy("draw");
104  state.emplace_back(dummy);
105 }
106 
107 // }---------- BUILDER -----------{
108 
109 namespace implementation
110 {
111 
112 builder_drawing::builder_drawing(const config& cfg)
113  : builder_styled_widget(cfg)
114  , width(cfg["width"])
115  , height(cfg["height"])
116  , draw(cfg.child("draw"))
117 {
118  assert(!draw.empty());
119 }
120 
122 {
123  drawing* widget = new drawing(*this);
124 
126 
127  const unsigned w = width(size);
128  const unsigned h = height(size);
129 
130  if(w || h) {
131  widget->set_best_size(point(w, h));
132  }
133 
134  widget->set_drawing_data(draw);
135 
136  DBG_GUI_G << "Window builder: placed drawing '" << id
137  << "' with definition '" << definition << "'.\n";
138 
139  return widget;
140 }
141 
142 } // namespace implementation
143 
144 // }------------ END --------------
145 
146 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
#define DBG_GUI_P
Definition: log.hpp:66
std::vector< state_definition > state
int dummy
Definition: lstrlib.cpp:1347
void set_drawing_data(const ::config &cfg)
Definition: drawing.hpp:62
Base class for all widgets.
Definition: widget.hpp:49
point best_size_
When we&#39;re used as a fixed size item, this holds the best size.
Definition: drawing.hpp:118
A drawing is widget with a fixed size and gives access to the canvas of the widget in the window inst...
Definition: drawing.hpp:52
#define h
virtual point calculate_best_size() const override
See widget::calculate_best_size.
Definition: drawing.cpp:41
virtual point calculate_best_size() const override
See widget::calculate_best_size.
void set_best_size(const point &best_size)
Definition: drawing.hpp:101
void get_screen_size_variables(wfl::map_formula_callable &variable)
Gets a formula object with the screen size.
Definition: helper.cpp:100
Generic file dialog.
Definition: field-fwd.hpp:23
std::string definition
Parameters for the styled_widget.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:87
This file contains the settings handling of the widget library.
virtual void request_reduce_height(const unsigned maximum_height) override
See widget::request_reduce_height.
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
Definition: drawing.cpp:47
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
typed_formula< unsigned > height
The height of the widget.
Definition: drawing.hpp:158
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: drawing.cpp:65
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
Definition: drawing.cpp:80
Holds a 2D point.
Definition: point.hpp:24
int w
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
Base class for all visible items.
virtual bool get_active() const override
See styled_widget::get_active.
Definition: drawing.cpp:70
virtual unsigned get_state() const override
See styled_widget::get_state.
Definition: drawing.cpp:75
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
virtual void request_reduce_height(const unsigned maximum_height) override
See widget::request_reduce_height.
Definition: drawing.cpp:56
virtual widget * build() const override
Definition: drawing.cpp:121
#define DBG_GUI_G
Definition: log.hpp:41
drawing_definition(const config &cfg)
Definition: drawing.cpp:87
bool empty() const
Definition: config.cpp:941
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.
config draw
Config containing what to draw on the widgets canvas.
Definition: drawing.hpp:161
typed_formula< unsigned > width
The width of the widget.
Definition: drawing.hpp:155