The Battle for Wesnoth  1.15.1+dev
canvas_private.hpp
Go to the documentation of this file.
1 /*
2 Copyright (C) 2007 - 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 #include "gui/core/canvas.hpp"
17 
18 namespace gui2 {
19 
20 /** Definition of a line shape. */
21 class line_shape : public canvas::shape {
22 public:
23  /**
24  * Constructor.
25  *
26  * @param cfg The config object to define the line see
27  * https://www.wesnoth.org/wiki/GUICanvasWML#Line
28  * for more information.
29  */
30  explicit line_shape(const config& cfg);
31 
32  /** Implement shape::draw(). */
33  void draw(surface& canvas,
34  SDL_Renderer* renderer,
35  wfl::map_formula_callable& variables) override;
36 
37 private:
38  typed_formula<unsigned> x1_, /**< The start x coordinate of the line. */
39  y1_, /**< The start y coordinate of the line. */
40  x2_, /**< The end x coordinate of the line. */
41  y2_; /**< The end y coordinate of the line. */
42 
43  /** The color of the line. */
45 
46  /**
47  * The thickness of the line.
48  *
49  * if the value is odd the x and y are the middle of the line.
50  * if the value is even the x and y are the middle of a line
51  * with width - 1. (0 is special case, does nothing.)
52  */
53  unsigned thickness_;
54 };
55 
56 /** Definition of a rectangle shape. */
58 public:
59  /**
60  * Constructor.
61  *
62  * @param cfg The config object to define the rectangle see
63  * https://www.wesnoth.org/wiki/GUICanvasWML#Rectangle
64  * for more information.
65  */
66  explicit rectangle_shape(const config& cfg);
67 
68  /** Implement shape::draw(). */
69  void draw(surface& canvas,
70  SDL_Renderer* renderer,
71  wfl::map_formula_callable& variables) override;
72 
73 private:
74  typed_formula<int> x_, /**< The x coordinate of the rectangle. */
75  y_, /**< The y coordinate of the rectangle. */
76  w_, /**< The width of the rectangle. */
77  h_; /**< The height of the rectangle. */
78 
79  /**
80  * Border thickness.
81  *
82  * If 0 the fill color is used for the entire widget.
83  */
85 
86  /**
87  * The border color of the rectangle.
88  *
89  * If the color is fully transparent the border isn't drawn.
90  */
92 
93  /**
94  * The border color of the rectangle.
95  *
96  * If the color is fully transparent the rectangle won't be filled.
97  */
99 };
100 
101 /** Definition of a rounded rectangle shape. */
103 public:
104  /**
105  * Constructor.
106  *
107  * @param cfg The config object to define the round rectangle see
108  * https://www.wesnoth.org/wiki/GUICanvasWML#Rounded_Rectangle
109  * for more information.
110  */
111  explicit round_rectangle_shape(const config& cfg);
112 
113  /** Implement shape::draw(). */
114  void draw(surface& canvas,
115  SDL_Renderer* renderer,
116  wfl::map_formula_callable& variables) override;
117 
118 private:
119  typed_formula<int> x_, /**< The x coordinate of the rectangle. */
120  y_, /**< The y coordinate of the rectangle. */
121  w_, /**< The width of the rectangle. */
122  h_, /**< The height of the rectangle. */
123  r_; /**< The radius of the corners. */
124 
125  /**
126  * Border thickness.
127  *
128  * If 0 the fill color is used for the entire widget.
129  */
131 
132  /**
133  * The border color of the rounded rectangle.
134  *
135  * If the color is fully transparent the border isn't drawn.
136  */
138 
139  /**
140  * The border color of the rounded rectangle.
141  *
142  * If the color is fully transparent the rounded rectangle won't be filled.
143  */
145 };
146 
147 /** Definition of a circle shape. */
148 class circle_shape : public canvas::shape {
149 public:
150  /**
151  * Constructor.
152  *
153  * @param cfg The config object to define the circle see
154  * https://www.wesnoth.org/wiki/GUICanvasWML#Circle
155  * for more information.
156  */
157  explicit circle_shape(const config& cfg);
158 
159  /** Implement shape::draw(). */
160  void draw(surface& canvas,
161  SDL_Renderer* renderer,
162  wfl::map_formula_callable& variables) override;
163 
164 private:
165  typed_formula<unsigned> x_, /**< The center x coordinate of the circle. */
166  y_, /**< The center y coordinate of the circle. */
167  radius_; /**< The radius of the circle. */
168 
169  /** The border color of the circle. */
170  typed_formula<color_t> border_color_, fill_color_; /**< The fill color of the circle. */
171 
172  /** The border thickness of the circle. */
173  unsigned int border_thickness_;
174 };
175 
176 /** Definition of an image shape. */
177 class image_shape : public canvas::shape {
178 public:
179  /**
180  * Constructor.
181  *
182  * @param cfg The config object to define the image see
183  * https://www.wesnoth.org/wiki/GUICanvasWML#Image
184  * for more information.
185  */
186  image_shape(const config& cfg, wfl::action_function_symbol_table& functions);
187 
188  /** Implement shape::draw(). */
189  void draw(surface& canvas,
190  SDL_Renderer* renderer,
191  wfl::map_formula_callable& variables) override;
192 
193 private:
194  typed_formula<unsigned> x_, /**< The x coordinate of the image. */
195  y_, /**< The y coordinate of the image. */
196  w_, /**< The width of the image. */
197  h_; /**< The height of the image. */
198 
199  /** Contains the size of the image. */
200  SDL_Rect src_clip_;
201 
202  /** The image is cached in this surface. */
204 
205  /**
206  * Name of the image.
207  *
208  * This value is only used when the image name is a formula. If it isn't a
209  * formula the image will be loaded in the constructor. If it's a formula it
210  * will be loaded every draw cycles. This allows 'changing' images.
211  */
213 
214  /**
215  * Determines the way an image will be resized.
216  *
217  * If the image is smaller is needed it needs to resized, how is determined
218  * by the value of this enum.
219  */
220  enum resize_mode {
225  };
226 
227  /** Converts a string to a resize mode. */
228  resize_mode get_resize_mode(const std::string& resize_mode);
229 
230  /** The resize mode for an image. */
232 
233  /** Mirror the image over the vertical axis. */
235 
236  // TODO: use a typed_formula?
238 
239  static void dimension_validation(unsigned value, const std::string& name, const std::string& key);
240 };
241 
242 /** Definition of a text shape. */
243 class text_shape : public canvas::shape {
244 public:
245  /**
246  * Constructor.
247  *
248  * @param cfg The config object to define the text see
249  * https://www.wesnoth.org/wiki/GUICanvasWML#Text
250  * for more information.
251  */
252  explicit text_shape(const config& cfg);
253 
254  /** Implement shape::draw(). */
255  void draw(surface& canvas,
256  SDL_Renderer* renderer,
257  wfl::map_formula_callable& variables) override;
258 
259 private:
260  typed_formula<unsigned> x_, /**< The x coordinate of the text. */
261  y_, /**< The y coordinate of the text. */
262  w_, /**< The width of the text. */
263  h_; /**< The height of the text. */
264 
265  /** The text font family. */
267 
268  /** The font size of the text. */
270 
271  /** The style of the text. */
273 
274  /** The alignment of the text. */
276 
277  /** The color of the text. */
279 
280  /** The text to draw. */
282 
283  /** The text markup switch of the text. */
285 
286  /** The link aware switch of the text. */
288 
289  /** The link color of the text. */
291 
292  /** The maximum width for the text. */
294 
295  /** The number of characters per line. */
297 
298  /** The maximum height for the text. */
300 };
301 
302 }
typed_formula< color_t > color_
The color of the line.
typed_formula< unsigned > y_
The center y coordinate of the circle.
int border_thickness_
Border thickness.
family_class
Font classes for get_font_families().
Definition of a rounded rectangle shape.
int border_thickness_
Border thickness.
Definition of an image shape.
surface image_
The image is cached in this surface.
typed_formula< color_t > border_color_
The border color of the rounded rectangle.
typed_formula< unsigned > x2_
The end x coordinate of the line.
typed_formula< int > maximum_height_
The maximum height for the text.
Definition of a text shape.
typed_formula< unsigned > y2_
The end y coordinate of the line.
typed_formula< color_t > fill_color_
The border color of the rounded rectangle.
unsigned int border_thickness_
The border thickness of the circle.
Definition of a rectangle shape.
Generic file dialog.
Definition: field-fwd.hpp:22
typed_formula< bool > vertical_mirror_
Mirror the image over the vertical axis.
static const char * name(const std::vector< SDL_Joystick *> &joysticks, const std::size_t index)
Definition: joystick.cpp:48
Abstract base class for all other shapes.
Definition: canvas.hpp:50
Definition of a line shape.
This file contains the canvas object which is the part where the widgets draw (temporally) images on...
typed_formula< int > y_
The y coordinate of the rectangle.
wfl::formula actions_formula_
resize_mode resize_mode_
The resize mode for an image.
typed_formula< bool > link_aware_
The link aware switch of the text.
typed_formula< bool > text_markup_
The text markup switch of the text.
font::family_class font_family_
The text font family.
typed_formula< color_t > fill_color_
The border color of the rectangle.
typed_formula< std::string > image_name_
Name of the image.
typed_formula< int > y_
The y coordinate of the rectangle.
typed_formula< int > maximum_width_
The maximum width for the text.
A simple canvas which can be drawn upon.
Definition: canvas.hpp:41
typed_formula< color_t > border_color_
The border color of the rectangle.
typed_formula< unsigned > y_
The y coordinate of the text.
font::pango_text::FONT_STYLE font_style_
The style of the text.
void draw(surface &canvas, SDL_Renderer *renderer, wfl::map_formula_callable &variables) override
Implement shape::draw().
Definition: canvas.cpp:589
Definition of a circle shape.
line_shape(const config &cfg)
Constructor.
Definition: canvas.cpp:574
typed_formula< color_t > fill_color_
The fill color of the circle.
typed_formula< unsigned > y_
The y coordinate of the image.
resize_mode
Determines the way an image will be resized.
SDL_Rect src_clip_
Contains the size of the image.
typed_formula< t_string > text_
The text to draw.
typed_formula< PangoAlignment > text_alignment_
The alignment of the text.
typed_formula< color_t > link_color_
The link color of the text.
typed_formula< unsigned > font_size_
The font size of the text.
typed_formula< unsigned > x1_
The start x coordinate of the line.
unsigned characters_per_line_
The number of characters per line.
unsigned thickness_
The thickness of the line.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
typed_formula< color_t > color_
The color of the text.
std::size_t w_
typed_formula< unsigned > y1_
The start y coordinate of the line.