The Battle for Wesnoth  1.19.7+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  GREEN_COLOR {0 , 255, 0 },
34  BLUE_COLOR {0 , 0 , 255},
35  INACTIVE_COLOR {150, 150, 150};
36 
38 
39 const color_t
40  weapon_color {245, 230, 193},
41  good_dmg_color {130, 240, 50 },
42  bad_dmg_color {250, 140, 80 },
43  weapon_details_color {196, 176, 147},
44  inactive_details_color { 86, 86, 86},
45  inactive_ability_color {146, 146, 146},
46  unit_type_color {245, 230, 193},
47  race_color {166, 146, 117};
48 
49 color_t string_to_color(const std::string &cmp_str)
50 {
51  // TODO needs a more generic mechanism so that more common color names are recognized
52  if (cmp_str == "green") {
53  return font::GOOD_COLOR;
54  }
55  if (cmp_str == "red") {
56  return font::BAD_COLOR;
57  }
58  if (cmp_str == "black") {
59  return font::BLACK_COLOR;
60  }
61  if (cmp_str == "yellow") {
62  return font::YELLOW_COLOR;
63  }
64  if (cmp_str == "white") {
65  return font::BIGMAP_COLOR;
66  }
67  if (cmp_str == "blue") {
68  return font::BLUE_COLOR;
69  }
70 
71  if (cmp_str.size() == 7 && cmp_str.at(0) == '#') {
72  // #rrggbb color, pango format.
73  return color_t::from_hex_string(cmp_str.substr(1));
74  } else if (cmp_str.size() == 6) {
75  // rrggbb color, wesnoth format
76  return color_t::from_hex_string(cmp_str);
77  }
78  return font::NORMAL_COLOR;
79 }
80 
81 } // namespace font
82 
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 GREEN_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 INACTIVE_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