The Battle for Wesnoth  1.15.2+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  * A widget to draw upon.
34  *
35  * This widget has a fixed size like the spacer, but allows the user to
36  * manual draw items. The widget is display only.
37  */
38 class drawing : public styled_widget
39 {
40 public:
41  explicit drawing(const implementation::builder_drawing& builder);
42 
44  {
45  return get_canvas(0);
46  }
47 
48  void set_drawing_data(const ::config& cfg)
49  {
50  get_drawing_canvas().set_cfg(cfg);
51  }
52 
53  void append_drawing_data(const ::config& cfg)
54  {
55  get_drawing_canvas().append_cfg(cfg);
56  }
57 
58  /***** ***** ***** ***** layout functions ***** ***** ***** *****/
59 
60  /** See @ref widget::request_reduce_width. */
61  virtual void request_reduce_width(const unsigned maximum_width) override;
62 
63  /** See @ref widget::request_reduce_height. */
64  virtual void request_reduce_height(const unsigned maximum_height) override;
65 
66 private:
67  /** See @ref widget::calculate_best_size. */
68  virtual point calculate_best_size() const override;
69 
70 public:
71  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
72 
73  /** See @ref styled_widget::set_active. */
74  virtual void set_active(const bool active) override;
75 
76  /** See @ref styled_widget::get_active. */
77  virtual bool get_active() const override;
78 
79  /** See @ref styled_widget::get_state. */
80  virtual unsigned get_state() const override;
81 
82  /** See @ref widget::disable_click_dismiss. */
83  bool disable_click_dismiss() const override;
84 
85  /***** ***** ***** setters / getters for members ***** ****** *****/
86 
87  void set_best_size(const point& best_size)
88  {
89  best_size_ = best_size;
90  }
91 
92 private:
93  /**
94  * Possible states of the widget.
95  *
96  * Note the order of the states must be the same as defined in
97  * settings.hpp.
98  */
99  enum state_t {
101  };
102 
103  /** When we're used as a fixed size item, this holds the best size. */
105 
106 public:
107  /** Static type getter that does not rely on the widget being constructed. */
108  static const std::string& type();
109 
110 private:
111  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
112  virtual const std::string& get_control_type() const override;
113 };
114 
115 // }---------- DEFINITION ---------{
116 
118 {
119  explicit drawing_definition(const config& cfg);
120 
122  {
123  explicit resolution(const config& cfg);
124  };
125 };
126 
127 // }---------- BUILDER -----------{
128 
129 namespace implementation
130 {
131 
133 {
134  explicit builder_drawing(const config& cfg);
135 
137 
138  widget* build() const;
139 
140  /** The width of the widget. */
142 
143  /** The height of the widget. */
145 
146  /** Config containing what to draw on the widgets canvas. */
148 };
149 
150 } // namespace implementation
151 
152 // }------------ END --------------
153 
154 } // 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:99
void set_drawing_data(const ::config &cfg)
Definition: drawing.hpp:48
Base class for all widgets.
Definition: widget.hpp:47
point best_size_
When we&#39;re used as a fixed size item, this holds the best size.
Definition: drawing.hpp:104
A widget to draw upon.
Definition: drawing.hpp:38
void set_best_size(const point &best_size)
Definition: drawing.hpp:87
Generic file dialog.
Definition: field-fwd.hpp:22
void append_drawing_data(const ::config &cfg)
Definition: drawing.hpp:53
canvas & get_drawing_canvas()
Definition: drawing.hpp:43
A simple canvas which can be drawn upon.
Definition: canvas.hpp:41
typed_formula< unsigned > height
The height of the widget.
Definition: drawing.hpp:144
window * build(const builder_window::window_resolution *definition)
Builds a window.
Holds a 2D point.
Definition: point.hpp:23
Base class for all visible items.
point resolution()
Definition: general.cpp:373
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
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:147
typed_formula< unsigned > width
The width of the widget.
Definition: drawing.hpp:141