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