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