The Battle for Wesnoth  1.17.0-dev
drawing.hpp
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 #pragma once
17 
19 
22 
23 class config;
24 
25 namespace gui2
26 {
27 namespace implementation
28 {
29  struct builder_drawing;
30 }
31 // ------------ WIDGET -----------{
32 
33 /**
34  * @ingroup GUIWidgetWML
35  *
36  * A drawing is widget with a fixed size and gives access to the canvas of the widget in the window instance.
37  * It has a fixed size like the spacer, but allows the user to manually draw items.
38  * This widget is display only.
39  *
40  * The widget normally has no event interaction so only one state is defined:
41  * * state_enabled - the drawing is enabled. The state is a dummy since the things really drawn are placed in the window instance.
42  *
43  * If either the width or the height is not zero the drawing functions as a fixed size drawing.
44  * Key |Type |Default |Description
45  * -------------|----------------------------------------|---------|-----------
46  * width | @ref guivartype_f_unsigned "f_unsigned"|0 |The width of the drawing.
47  * height | @ref guivartype_f_unsigned "f_unsigned"|0 |The height of the drawing.
48  * draw | @ref guivartype_config "config" |mandatory|The config containing the drawing.
49  *
50  * The variables available are the same as for the window resolution see @ref builder_window::window_resolution for the list of items.
51  */
52 class drawing : public styled_widget
53 {
54 public:
55  explicit drawing(const implementation::builder_drawing& builder);
56 
58  {
59  return get_canvas(0);
60  }
61 
62  void set_drawing_data(const ::config& cfg)
63  {
64  get_drawing_canvas().set_cfg(cfg);
65  }
66 
67  void append_drawing_data(const ::config& cfg)
68  {
69  get_drawing_canvas().append_cfg(cfg);
70  }
71 
72  /***** ***** ***** ***** layout functions ***** ***** ***** *****/
73 
74  /** See @ref widget::request_reduce_width. */
75  virtual void request_reduce_width(const unsigned maximum_width) override;
76 
77  /** See @ref widget::request_reduce_height. */
78  virtual void request_reduce_height(const unsigned maximum_height) override;
79 
80 private:
81  /** See @ref widget::calculate_best_size. */
82  virtual point calculate_best_size() const override;
83 
84 public:
85  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
86 
87  /** See @ref styled_widget::set_active. */
88  virtual void set_active(const bool active) override;
89 
90  /** See @ref styled_widget::get_active. */
91  virtual bool get_active() const override;
92 
93  /** See @ref styled_widget::get_state. */
94  virtual unsigned get_state() const override;
95 
96  /** See @ref widget::disable_click_dismiss. */
97  bool disable_click_dismiss() const override;
98 
99  /***** ***** ***** setters / getters for members ***** ****** *****/
100 
101  void set_best_size(const point& best_size)
102  {
103  best_size_ = best_size;
104  }
105 
106 private:
107  /**
108  * Possible states of the widget.
109  *
110  * Note the order of the states must be the same as defined in
111  * settings.hpp.
112  */
113  enum state_t {
115  };
116 
117  /** When we're used as a fixed size item, this holds the best size. */
119 
120 public:
121  /** Static type getter that does not rely on the widget being constructed. */
122  static const std::string& type();
123 
124 private:
125  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
126  virtual const std::string& get_control_type() const override;
127 };
128 
129 // }---------- DEFINITION ---------{
130 
132 {
133  explicit drawing_definition(const config& cfg);
134 
136  {
137  explicit resolution(const config& cfg);
138  };
139 };
140 
141 // }---------- BUILDER -----------{
142 
143 namespace implementation
144 {
145 
147 {
148  explicit builder_drawing(const config& cfg);
149 
151 
152  virtual widget* build() const override;
153 
154  /** The width of the widget. */
156 
157  /** The height of the widget. */
159 
160  /** Config containing what to draw on the widgets canvas. */
162 };
163 
164 } // namespace implementation
165 
166 // }------------ END --------------
167 
168 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
virtual widget * build() const =0
state_t
Possible states of the widget.
Definition: drawing.hpp:113
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
void set_best_size(const point &best_size)
Definition: drawing.hpp:101
Generic file dialog.
Definition: field-fwd.hpp:23
void append_drawing_data(const ::config &cfg)
Definition: drawing.hpp:67
canvas & get_drawing_canvas()
Definition: drawing.hpp:57
A simple canvas which can be drawn upon.
Definition: canvas.hpp:42
typed_formula< unsigned > height
The height of the widget.
Definition: drawing.hpp:158
Holds a 2D point.
Definition: point.hpp:24
Base class for all visible items.
point resolution()
Definition: general.cpp:393
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
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