OGS
Color.cpp
Go to the documentation of this file.
1
15#include "Color.h"
16
17#include "BaseLib/Logging.h"
18
19namespace DataHolderLib
20{
21Color createColor(unsigned char r,
22 unsigned char g,
23 unsigned char b,
24 unsigned char a)
25{
26 return Color{{r, g, b, a}};
27}
28
30{
31 return createColor(static_cast<unsigned char>((rand() % 5) * 50),
32 static_cast<unsigned char>((rand() % 5) * 50),
33 static_cast<unsigned char>((rand() % 5) * 50));
34}
35
36Color getColor(const std::string& id, std::map<std::string, Color>& colors)
37{
38 auto it = colors.find(id);
39
40 if (it == end(colors))
41 {
42 WARN("Key '{:s}' not found in color lookup table.", id);
43 it = colors.insert({id, getRandomColor()}).first;
44 }
45
46 return it->second;
47}
48
49} // namespace DataHolderLib
Definition of the Color class.
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
Color getRandomColor()
Returns a random RGB colour.
Definition Color.cpp:29
Color createColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Definition Color.cpp:21
Color getColor(const std::string &id, std::map< std::string, Color > &colors)
Definition Color.cpp:36
std::array< unsigned char, 4 > Color
Definition Color.h:24