The Battle for Wesnoth  1.19.5+dev
standard_colors.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
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 namespace font {
19 
20 const color_t
21  NORMAL_COLOR {221, 221, 221},
22  GRAY_COLOR {136, 136, 136},
23  LOBBY_COLOR {187, 187, 187},
24  GOOD_COLOR {0 , 181, 26 },
25  BAD_COLOR {255, 0 , 0 },
26  BLACK_COLOR {0 , 0 , 0 },
27  YELLOW_COLOR {255, 255, 0 },
28  BUTTON_COLOR {186, 172, 125},
29  PETRIFIED_COLOR {160, 160, 160},
30  TITLE_COLOR {186, 172, 125},
31  LABEL_COLOR {107, 140, 255},
32  BIGMAP_COLOR {255, 255, 255},
33  BLUE_COLOR {0 , 0 , 255};
34 
36 
37 const color_t
38  weapon_color {245, 230, 193},
39  good_dmg_color {130, 240, 50 },
40  bad_dmg_color {250, 140, 80 },
41  weapon_details_color {196, 176, 147},
42  inactive_details_color { 86, 86, 86},
43  inactive_ability_color {146, 146, 146},
44  unit_type_color {245, 230, 193},
45  race_color {166, 146, 117};
46 
47 color_t string_to_color(const std::string &cmp_str)
48 {
49  // TODO needs a more generic mechanism so that more common color names are recognized
50  if (cmp_str == "green") {
51  return font::GOOD_COLOR;
52  }
53  if (cmp_str == "red") {
54  return font::BAD_COLOR;
55  }
56  if (cmp_str == "black") {
57  return font::BLACK_COLOR;
58  }
59  if (cmp_str == "yellow") {
60  return font::YELLOW_COLOR;
61  }
62  if (cmp_str == "white") {
63  return font::BIGMAP_COLOR;
64  }
65  if (cmp_str == "blue") {
66  return font::BLUE_COLOR;
67  }
68 
69  if (cmp_str.size() == 7 && cmp_str.at(0) == '#') {
70  // #rrggbb color, pango format.
71  return color_t::from_hex_string(cmp_str.substr(1));
72  } else if (cmp_str.size() == 6) {
73  // rrggbb color, wesnoth format
74  return color_t::from_hex_string(cmp_str);
75  }
76  return font::NORMAL_COLOR;
77 }
78 
79 } // namespace font
80 
Graphical text output.
const color_t LABEL_COLOR
const color_t inactive_details_color
const color_t YELLOW_COLOR
const color_t BLACK_COLOR
const color_t BUTTON_COLOR
const color_t unit_type_color
const color_t GOOD_COLOR
const color_t BLUE_COLOR
const color_t BIGMAP_COLOR
const color_t inactive_ability_color
color_t string_to_color(const std::string &cmp_str)
Return the color the string represents.
const color_t BAD_COLOR
const color_t TITLE_COLOR
const color_t LOBBY_COLOR
const color_t GRAY_COLOR
const color_t DISABLED_COLOR
const color_t weapon_details_color
const color_t good_dmg_color
const color_t PETRIFIED_COLOR
const color_t NORMAL_COLOR
const color_t weapon_color
const color_t race_color
const color_t bad_dmg_color
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:59
static color_t from_hex_string(std::string_view c)
Creates a new color_t object from a string variable in hex format.
Definition: color.cpp:64
constexpr color_t inverse() const
Definition: color.hpp:224