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