The Battle for Wesnoth  1.19.7+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 class drawing : public styled_widget
30 {
31 public:
32  explicit drawing(const implementation::builder_drawing& builder);
33 
35  {
36  return get_canvas(0);
37  }
38 
39  void set_drawing_data(const ::config& cfg)
40  {
42  }
43 
44  void append_drawing_data(const ::config& cfg)
45  {
47  }
48 
49  /***** ***** ***** ***** layout functions ***** ***** ***** *****/
50 
51  /** See @ref widget::request_reduce_width. */
52  virtual void request_reduce_width(const unsigned maximum_width) override;
53 
54  /** See @ref widget::request_reduce_height. */
55  virtual void request_reduce_height(const unsigned maximum_height) override;
56 
57 private:
58  /** See @ref widget::calculate_best_size. */
59  virtual point calculate_best_size() const override;
60 
61 public:
62  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
63 
64  /** See @ref styled_widget::set_active. */
65  virtual void set_active(const bool active) override;
66 
67  /** See @ref styled_widget::get_active. */
68  virtual bool get_active() const override;
69 
70  /** See @ref styled_widget::get_state. */
71  virtual unsigned get_state() const override;
72 
73  /** See @ref widget::disable_click_dismiss. */
74  bool disable_click_dismiss() const override;
75 
76  /***** ***** ***** setters / getters for members ***** ****** *****/
77 
78  void set_best_size(const point& best_size)
79  {
80  best_size_ = best_size;
81  }
82 
83 private:
84  /**
85  * Possible states of the widget.
86  *
87  * Note the order of the states must be the same as defined in
88  * settings.hpp.
89  */
90  enum state_t {
92  };
93 
94  /** When we're used as a fixed size item, this holds the best size. */
96 
97 public:
98  /** Static type getter that does not rely on the widget being constructed. */
99  static const std::string& type();
100 
101 private:
102  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
103  virtual const std::string& get_control_type() const override;
104 };
105 
106 // }---------- DEFINITION ---------{
107 
109 {
110  explicit drawing_definition(const config& cfg);
111 
113  {
114  explicit resolution(const config& cfg);
115  };
116 };
117 
118 // }---------- BUILDER -----------{
119 
120 namespace implementation
121 {
122 
124 {
125  explicit builder_drawing(const config& cfg);
126 
128 
129  virtual std::unique_ptr<widget> build() const override;
130 
131  /** The width of the widget. */
133 
134  /** The height of the widget. */
136 
137  /** Config containing what to draw on the widgets canvas. */
139 };
140 
141 } // namespace implementation
142 
143 // }------------ END --------------
144 
145 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
A simple canvas which can be drawn upon.
Definition: canvas.hpp:45
void append_cfg(const config &cfg)
Appends data to the config.
Definition: canvas.hpp:132
void set_cfg(const config &cfg, const bool force=false)
Sets the config.
Definition: canvas.hpp:121
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:44
canvas & get_drawing_canvas()
Definition: drawing.hpp:34
void set_best_size(const point &best_size)
Definition: drawing.hpp:78
point best_size_
When we're used as a fixed size item, this holds the best size.
Definition: drawing.hpp:95
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:90
void set_drawing_data(const ::config &cfg)
Definition: drawing.hpp:39
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
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:135
config draw
Config containing what to draw on the widgets canvas.
Definition: drawing.hpp:138
typed_formula< unsigned > width
The width of the widget.
Definition: drawing.hpp:132
builder_drawing(const config &cfg)
Definition: drawing.cpp:109
virtual std::unique_ptr< widget > build() const override
Definition: drawing.cpp:117
virtual std::unique_ptr< widget > build() const=0
Holds a 2D point.
Definition: point.hpp:25