The Battle for Wesnoth  1.19.11+dev
standard_colors.cpp
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 #include "font/standard_colors.hpp"
17 
18 #include "color.hpp"
19 #include "gui/core/log.hpp"
20 
21 #include <algorithm>
22 #include <pango/pango-color.h>
23 
24 namespace font {
25 
26 const color_t
27  NORMAL_COLOR {221, 221, 221},
28  GRAY_COLOR {136, 136, 136},
29  GOOD_COLOR {0 , 181, 26 },
30  BAD_COLOR {255, 0 , 0 },
31  YELLOW_COLOR {255, 255, 0 },
32  TITLE_COLOR {186, 172, 125},
33  LABEL_COLOR {107, 140, 255},
34  INACTIVE_COLOR {150, 150, 150};
35 
36 const color_t
37  weapon_color {245, 230, 193},
38  good_dmg_color {130, 240, 50 },
39  bad_dmg_color {250, 140, 80 },
40  weapon_details_color {196, 176, 147},
41  unit_type_color {245, 230, 193};
42 
43 color_t string_to_color(const std::string& color_str)
44 {
45  std::string cstr = color_str;
46  // Hex rrggbb string with no leading '#'.
47  // Pango can't deal with this, so we prepend '#'.
48  if(cstr.size() == 6
49  && std::all_of(cstr.begin(), cstr.end(), [](int i) { return isxdigit(i); }))
50  {
51  cstr = '#' + cstr;
52  }
53 
54  PangoColor color;
55  if(pango_color_parse(&color, cstr.c_str())) {
56  return color_t::from_pango_format(color.red, color.green, color.blue);
57  }
58 
59  WRN_GUI_D << "No valid color found for " << color_str << ", falling back to " << font::NORMAL_COLOR << ".";
60  return font::NORMAL_COLOR;
61 }
62 
63 } // namespace font
64 
std::size_t i
Definition: function.cpp:1030
Define the common log macros for the gui toolkit.
#define WRN_GUI_D
Definition: log.hpp:31
Graphical text output.
const color_t LABEL_COLOR
const color_t YELLOW_COLOR
const color_t unit_type_color
const color_t GOOD_COLOR
const color_t BAD_COLOR
const color_t TITLE_COLOR
const color_t GRAY_COLOR
const color_t weapon_details_color
const color_t good_dmg_color
const color_t NORMAL_COLOR
color_t string_to_color(const std::string &color_str)
Return the color the string represents.
const color_t weapon_color
const color_t INACTIVE_COLOR
const color_t bad_dmg_color
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:61
static constexpr color_t from_pango_format(uint16_t r, uint16_t g, uint16_t b)
Creates a new color_t object from a triplet of 16 bit color values, usually used by Pango.
Definition: color.hpp:147