The Battle for Wesnoth  1.19.7+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 <string>
22 #include <string_view>
23 
24 struct point;
25 class t_string;
26 
27 namespace wfl
28 {
29 class map_formula_callable;
30 } // namespace wfl
31 
32 namespace gui2
33 {
34 /**
35  * Converts a color string to a color.
36  *
37  * @param color A color string, @see color_t::from_rgba_string.
38  *
39  * @returns The color.
40  */
41 color_t decode_color(const std::string& color);
42 
43 /**
44  * Converts a text alignment string to a text alignment.
45  *
46  * @param alignment An alignment string, possible values: "left", "right", "center".
47  *
48  * @returns The text alignment.
49  */
50 PangoAlignment decode_text_alignment(const std::string& alignment);
51 
52 /**
53  * Converts a text weight string to a PangoWeight.
54  *
55  * @param weight A weight string, possible values: "thin", "light", "normal", "semibold", "bold", "heavy".
56  *
57  * @returns The corresponding PangoWeight.
58  */
59 PangoWeight decode_text_weight(const std::string& weight);
60 
61 /**
62  * Converts a text style string to a PangoStyle.
63  *
64  * @param style A style string, possible values: "normal", "italic", "oblique".
65  *
66  * @returns The corresponding PangoStyle.
67  */
68 PangoStyle decode_text_style(const std::string& style);
69 
70 /**
71  * Converts a font style string to a font style.
72  *
73  * @param style A font style string, possible values: "bold", "italic", "normal", "underline".
74  *
75  * @returns The font style.
76  */
77 font::pango_text::FONT_STYLE decode_font_style(const std::string& style);
78 
79 /**
80  * Converts a text ellipsize mode string to a PangoEllipsizeMode.
81  *
82  * @param ellipsize_mode A ellipsize mode string, possible values: "none", "start", "middle", "end".
83  *
84  * @returns The corresponding PangoEllipsizeMode.
85  */
86 PangoEllipsizeMode decode_ellipsize_mode(const std::string& ellipsize_mode);
87 
88 /**
89  * Converts a PangoAlignment to its string representation.
90  *
91  * @param alignment A PangoAlignment.
92  *
93  * @returns An alignment string, possible values: "left", "right", "center".
94  */
95 std::string encode_text_alignment(const PangoAlignment alignment);
96 
97 /**
98  * Converts a PangoEllipsizeMode to its string representation.
99  *
100  * @param ellipsize_mode A PangoEllipsizeMode.
101  *
102  * @returns An pango ellipsize mode string, possible values: "none", "start", "middle", "end".
103  */
104 std::string encode_ellipsize_mode(const PangoEllipsizeMode ellipsize_mode);
105 
106 /**
107  * Returns a default error message if a mandatory widget is omitted.
108  *
109  * @param id The id of the omitted widget.
110  * @returns The error message.
111  */
112 t_string missing_widget(const std::string& id);
113 
114 /**
115  * Gets a formula object with the screen size.
116  *
117  * @param variable A formula object in which the screen_width,
118  * screen_height, gamemap_width and
119  * gamemap_height variable will set to the
120  * current values of these in settings. It
121  * modifies the object send.
122  */
124 
125 /**
126  * Gets a formula object with the screen size.
127  *
128  * @returns Formula object with the screen_width,
129  * screen_height, gamemap_width and
130  * gamemap_height variable set to the current
131  * values of these in settings.
132  */
134 
135 /** Returns the current mouse position. */
137 
138 /**
139  * Returns a truncated version of the text.
140  *
141  * For debugging it's sometimes useful to get a part of the label of the
142  * widget. This function shows the first part.
143  *
144  * @param text The text to truncate.
145  *
146  * @returns The truncated text.
147  */
148 std::string_view debug_truncate(std::string_view text);
149 
150 } // 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:156
color_t decode_color(const std::string &color)
Converts a color string to a color.
Definition: helper.cpp:48
t_string missing_widget(const std::string &id)
Returns a default error message if a mandatory widget is omitted.
Definition: helper.cpp:151
std::string encode_ellipsize_mode(const PangoEllipsizeMode ellipsize_mode)
Converts a PangoEllipsizeMode to its string representation.
Definition: helper.cpp:121
point get_mouse_position()
Returns the current mouse position.
Definition: helper.cpp:173
std::string_view debug_truncate(std::string_view text)
Returns a truncated version of the text.
Definition: helper.cpp:178
PangoWeight decode_text_weight(const std::string &weight)
Converts a text weight string to a PangoWeight.
Definition: helper.cpp:53
font::pango_text::FONT_STYLE decode_font_style(const std::string &style)
Converts a font style string to a font style.
Definition: helper.cpp:31
PangoAlignment decode_text_alignment(const std::string &alignment)
Converts a text alignment string to a text alignment.
Definition: helper.cpp:89
PangoStyle decode_text_style(const std::string &style)
Converts a text style string to a PangoStyle.
Definition: helper.cpp:74
std::string encode_text_alignment(const PangoAlignment alignment)
Converts a PangoAlignment to its string representation.
Definition: helper.cpp:135
PangoEllipsizeMode decode_ellipsize_mode(const std::string &ellipsize_mode)
Converts a text ellipsize mode string to a PangoEllipsizeMode.
Definition: helper.cpp:104
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