OGS
Color.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "Color.h"
5
6#include "BaseLib/Logging.h"
7
8namespace DataHolderLib
9{
10Color createColor(unsigned char r,
11 unsigned char g,
12 unsigned char b,
13 unsigned char a)
14{
15 return Color{{r, g, b, a}};
16}
17
19{
20 return createColor(static_cast<unsigned char>((rand() % 5) * 50),
21 static_cast<unsigned char>((rand() % 5) * 50),
22 static_cast<unsigned char>((rand() % 5) * 50));
23}
24
25Color getColor(const std::string& id, std::map<std::string, Color>& colors)
26{
27 auto it = colors.find(id);
28
29 if (it == end(colors))
30 {
31 WARN("Key '{:s}' not found in color lookup table.", id);
32 it = colors.insert({id, getRandomColor()}).first;
33 }
34
35 return it->second;
36}
37
38} // namespace DataHolderLib
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
Color getRandomColor()
Returns a random RGB colour.
Definition Color.cpp:18
Color createColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Definition Color.cpp:10
Color getColor(const std::string &id, std::map< std::string, Color > &colors)
Definition Color.cpp:25
std::array< unsigned char, 4 > Color
Definition Color.h:12