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