The Battle for Wesnoth  1.15.10+dev
helper.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 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 
17 #include "color.hpp"
18 #include "font/text.hpp"
19 
20 #include <pango/pango-layout.h>
21 
22 #include <cstdint>
23 #include <string>
24 
25 struct SDL_Rect;
26 struct point;
27 class t_string;
28 
29 namespace wfl
30 {
31 class map_formula_callable;
32 } // namespace wfl
33 
34 namespace gui2
35 {
36 /**
37  * Creates a rectangle.
38  *
39  * @param origin The top left corner.
40  * @param size The width (x) and height (y).
41  *
42  * @returns SDL_Rect with the proper rectangle.
43  */
44 SDL_Rect create_rect(const point& origin, const point& size);
45 
46 /**
47  * Converts a color string to a color.
48  *
49  * @param color A color string see @ref GUIWidgetWML for more info.
50  *
51  * @returns The color.
52  */
53 color_t decode_color(const std::string& color);
54 
55 /**
56  * Converts a text alignment string to a text alignment.
57  *
58  * @param alignment An alignment string see @ref GUIWidgetWML for more info.
59  *
60  * @returns The text alignment.
61  */
62 PangoAlignment decode_text_alignment(const std::string& alignment);
63 
64 /**
65  * Converts a text alignment to its string representation.
66  *
67  * @param alignment An alignment.
68  *
69  * @returns An alignment string see @ref GUIWidgetWML for more info.
70  */
71 std::string encode_text_alignment(const PangoAlignment alignment);
72 
73 /**
74  * Converts a font style string to a font style.
75  *
76  * @param style A font style string see @ref GUIWidgetWML for more info.
77  *
78  * @returns The font style.
79  */
81 
82 /**
83  * Returns a default error message if a mandatory widget is omitted.
84  *
85  * @param id The id of the omitted widget.
86  * @returns The error message.
87  */
88 t_string missing_widget(const std::string& id);
89 
90 /**
91  * Gets a formula object with the screen size.
92  *
93  * @param variable A formula object in which the screen_width,
94  * screen_height, gamemap_width and
95  * gamemap_height variable will set to the
96  * current values of these in settings. It
97  * modifies the object send.
98  */
100 
101 /**
102  * Gets a formula object with the screen size.
103  *
104  * @returns Formula object with the screen_width,
105  * screen_height, gamemap_width and
106  * gamemap_height variable set to the current
107  * values of these in settings.
108  */
110 
111 /** Returns the current mouse position. */
113 
114 /**
115  * Returns a truncated version of the text.
116  *
117  * For debugging it's sometimes useful to get a part of the label of the
118  * widget. This function shows the first part.
119  *
120  * @param text The text to truncate.
121  *
122  * @returns The truncated text.
123  */
124 std::string debug_truncate(const std::string& text);
125 
126 } // namespace gui2
std::string encode_text_alignment(const PangoAlignment alignment)
Converts a text alignment to its string representation.
Definition: helper.cpp:78
SDL_Rect create_rect(const point &origin, const point &size)
Creates a rectangle.
Definition: helper.cpp:32
PangoAlignment decode_text_alignment(const std::string &alignment)
Converts a text alignment string to a text alignment.
Definition: helper.cpp:63
void get_screen_size_variables(wfl::map_formula_callable &variable)
Gets a formula object with the screen size.
Definition: helper.cpp:99
Generic file dialog.
Definition: field-fwd.hpp:22
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
std::string debug_truncate(const std::string &text)
Returns a truncated version of the text.
Definition: helper.cpp:125
Holds a 2D point.
Definition: point.hpp:23
point get_mouse_position()
Returns the current mouse position.
Definition: helper.cpp:117
Definition: contexts.hpp:43
int style
Definition: sdl_ttf.cpp:57
font::pango_text::FONT_STYLE decode_font_style(const std::string &style)
Converts a font style string to a font style.
Definition: helper.cpp:37
t_string missing_widget(const std::string &id)
Returns a default error message if a mandatory widget is omitted.
Definition: helper.cpp:94
color_t decode_color(const std::string &color)
Converts a color string to a color.
Definition: helper.cpp:58