The Battle for Wesnoth  1.15.2+dev
text_formatting.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
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 #include <iomanip>
22 
23 namespace font {
24 
25 std::string span_color(const color_t& color)
26 {
27  return formatter() << "<span color='" << color.to_hex_string() << "'>";
28 }
29 
30 std::string span_color(const color_t& color, const std::string& data)
31 {
32  return span_color(color) + data + "</span>";
33 }
34 
35 std::string get_pango_color_from_id(const std::string& id)
36 {
37  const auto color = game_config::team_rgb_colors.find(id);
38  if(color != game_config::team_rgb_colors.end()) {
39  return (color->second[0]).to_hex_string();
40  }
41 
42  return "";
43 }
44 
45 std::string get_color_string_pango(const std::string& id)
46 {
47  const auto name = game_config::team_rgb_name.find(id);
48  if(name != game_config::team_rgb_name.end()) {
49  return formatter() << "<span color='" << get_pango_color_from_id(id) << "'>" << name->second << "</span>";
50  }
51 
52  return _("Invalid Color");
53 }
54 
55 }
Note: Specific to sdl_ttf.
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:91
std::string get_pango_color_from_id(const std::string &id)
Returns a hex color string from a color range.
std::ostringstream wrapper.
Definition: formatter.hpp:38
std::map< std::string, std::vector< color_t > > team_rgb_colors
std::string to_hex_string() const
Returns the stored color in rrggbb hex format.
Definition: color.cpp:97
std::string get_color_string_pango(const std::string &id)
Returns the name of a color range, colored with its own color.
std::map< std::string, t_string > team_rgb_name