The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
text_formatting.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2017 by the Battle for Wesnoth Project http://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 
26 {
27  return formatter() << "<span color='" << color.to_hex_string() << "'>";
28 }
29 
31 {
32  const auto color = game_config::team_rgb_colors.find(id);
33  if(color != game_config::team_rgb_colors.end()) {
34  return (color->second[0]).to_hex_string();
35  }
36 
37  return "";
38 }
39 
41 {
42  const auto name = game_config::team_rgb_name.find(id);
43  if(name != game_config::team_rgb_name.end()) {
44  return formatter() << "<span color='" << get_pango_color_from_id(id) << "'>" << name->second << "</span>";
45  }
46 
47  return _("Invalid Color");
48 }
49 
50 }
std::vector< char_t > string
Note: Specific to sdl_ttf.
std::string span_color(const color_t &color)
Retuns a Pango formatting string using the provided color_t object.
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:89
std::string get_pango_color_from_id(const std::string &id)
Returns a hex color string from a color range.
std::string to_hex_string() const
Returns the stored color in rrggbb hex format.
Definition: color.cpp:97
std::ostringstream wrapper.
Definition: formatter.hpp:38
std::map< std::string, std::vector< color_t > > team_rgb_colors
std::string get_color_string_pango(const std::string &id)
Returns the name of a color range, colored with its own color.
static const char * name(const std::vector< SDL_Joystick * > &joysticks, const size_t index)
Definition: joystick.cpp:48
std::map< std::string, t_string > team_rgb_name