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