The Battle for Wesnoth
1.19.4+dev
font
text_formatting.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2003 - 2024
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
#include "
font/text_formatting.hpp
"
15
16
#include "
formatter.hpp
"
17
#include "
game_config.hpp
"
18
#include "
gettext.hpp
"
19
#include "
color.hpp
"
20
21
22
namespace
font
{
23
24
std::string
span_color
(
const
color_t
& color)
25
{
26
return
formatter
() <<
"<span color='"
<< color.
to_hex_string
() <<
"'>"
;
27
}
28
29
std::string
span_color
(
const
color_t
& color,
const
std::string&
data
)
30
{
31
return
span_color
(color) +
data
+
"</span>"
;
32
}
33
34
std::string
get_pango_color_from_id
(
const
std::string&
id
)
35
{
36
const
auto
color =
game_config::team_rgb_colors
.find(
id
);
37
if
(color !=
game_config::team_rgb_colors
.end()) {
38
return
(color->second[0]).to_hex_string();
39
}
40
41
return
""
;
42
}
43
44
std::string
get_color_string_pango
(
const
std::string&
id
)
45
{
46
const
auto
name =
game_config::team_rgb_name
.find(
id
);
47
if
(name !=
game_config::team_rgb_name
.end()) {
48
return
formatter
() <<
"<span color='"
<<
get_pango_color_from_id
(
id
) <<
"'>"
<< name->second <<
"</span>"
;
49
}
50
51
return
_
(
"Invalid Color"
);
52
}
53
54
}
formatter
std::ostringstream wrapper.
Definition:
formatter.hpp:40
color.hpp
formatter.hpp
game_config.hpp
gettext.hpp
_
static std::string _(const char *str)
Definition:
gettext.hpp:93
font
Collection of helper functions relating to Pango formatting.
Definition:
editor_controller.hpp:31
font::get_pango_color_from_id
std::string get_pango_color_from_id(const std::string &id)
Returns a hex color string from a color range.
Definition:
text_formatting.cpp:34
font::get_color_string_pango
std::string get_color_string_pango(const std::string &id)
Returns the name of a color range, colored with its own color.
Definition:
text_formatting.cpp:44
font::span_color
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
Definition:
text_formatting.cpp:24
game_config::team_rgb_name
std::map< std::string, t_string, std::less<> > team_rgb_name
Definition:
game_config.cpp:146
game_config::team_rgb_colors
std::map< std::string, std::vector< color_t >, std::less<> > team_rgb_colors
Definition:
game_config.cpp:148
data
std::string_view data
Definition:
picture.cpp:178
color_t
The basic class for representing 8-bit RGB or RGBA colour values.
Definition:
color.hpp:59
color_t::to_hex_string
std::string to_hex_string() const
Returns the stored color in rrggbb hex format.
Definition:
color.cpp:88
text_formatting.hpp
Generated by
1.9.1