The Battle for Wesnoth  1.19.0-dev
helper.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
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 <string>
24 #include <string_view>
25 
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  * Converts a color string to a color.
38  *
39  * @param color A color string see @ref GUIWidgetWML for more info.
40  *
41  * @returns The color.
42  */
43 color_t decode_color(const std::string& color);
44 
45 /**
46  * Converts a text alignment string to a text alignment.
47  *
48  * @param alignment An alignment string see @ref GUIWidgetWML for more info.
49  *
50  * @returns The text alignment.
51  */
52 PangoAlignment decode_text_alignment(const std::string& alignment);
53 
54 /**
55  * Converts a text alignment to its string representation.
56  *
57  * @param alignment An alignment.
58  *
59  * @returns An alignment string see @ref GUIWidgetWML for more info.
60  */
61 std::string encode_text_alignment(const PangoAlignment alignment);
62 
63 /**
64  * Converts a font style string to a font style.
65  *
66  * @param style A font style string see @ref GUIWidgetWML for more info.
67  *
68  * @returns The font style.
69  */
70 font::pango_text::FONT_STYLE decode_font_style(const std::string& style);
71 
72 /**
73  * Returns a default error message if a mandatory widget is omitted.
74  *
75  * @param id The id of the omitted widget.
76  * @returns The error message.
77  */
78 t_string missing_widget(const std::string& id);
79 
80 /**
81  * Gets a formula object with the screen size.
82  *
83  * @param variable A formula object in which the screen_width,
84  * screen_height, gamemap_width and
85  * gamemap_height variable will set to the
86  * current values of these in settings. It
87  * modifies the object send.
88  */
90 
91 /**
92  * Gets a formula object with the screen size.
93  *
94  * @returns Formula object with the screen_width,
95  * screen_height, gamemap_width and
96  * gamemap_height variable set to the current
97  * values of these in settings.
98  */
100 
101 /** Returns the current mouse position. */
103 
104 /**
105  * Returns a truncated version of the text.
106  *
107  * For debugging it's sometimes useful to get a part of the label of the
108  * widget. This function shows the first part.
109  *
110  * @param text The text to truncate.
111  *
112  * @returns The truncated text.
113  */
114 std::string_view debug_truncate(std::string_view text);
115 
116 } // namespace gui2
Generic file dialog.
void get_screen_size_variables(wfl::map_formula_callable &variable)
Gets a formula object with the screen size.
Definition: helper.cpp:94
color_t decode_color(const std::string &color)
Converts a color string to a color.
Definition: helper.cpp:53
t_string missing_widget(const std::string &id)
Returns a default error message if a mandatory widget is omitted.
Definition: helper.cpp:89
point get_mouse_position()
Returns the current mouse position.
Definition: helper.cpp:112
std::string_view debug_truncate(std::string_view text)
Returns a truncated version of the text.
Definition: helper.cpp:117
font::pango_text::FONT_STYLE decode_font_style(const std::string &style)
Converts a font style string to a font style.
Definition: helper.cpp:32
PangoAlignment decode_text_alignment(const std::string &alignment)
Converts a text alignment string to a text alignment.
Definition: helper.cpp:58
std::string encode_text_alignment(const PangoAlignment alignment)
Converts a text alignment to its string representation.
Definition: helper.cpp:73
Definition: contexts.hpp:43
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:59
Holds a 2D point.
Definition: point.hpp:25