Colors: Introduce color type abstraction
SFML and Dear ImGui have incompatible color types, abstract them through a new Color class which has conversions. Centralize color constants in a namespace as well.
This commit is contained in:
parent
f25a649144
commit
a0bdfce61a
3 changed files with 47 additions and 9 deletions
37
Color.h
Normal file
37
Color.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// Created by trotfunky on 26/01/24.
|
||||
//
|
||||
|
||||
#ifndef RAYCASTING_COLOR_H
|
||||
#define RAYCASTING_COLOR_H
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#ifdef IMGUI
|
||||
#include <imgui.h>
|
||||
#endif
|
||||
|
||||
|
||||
class Color {
|
||||
public:
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t alpha;
|
||||
|
||||
constexpr Color(uint8_t r, uint8_t g, uint8_t b, uint8_t alpha = 255) :
|
||||
r(r), g(g), b(b), alpha(alpha) {};
|
||||
|
||||
operator sf::Color() const { return {r, g, b, alpha}; }
|
||||
#ifdef IMGUI
|
||||
operator ImColor() const { return {r, g, b, alpha}; }
|
||||
#endif
|
||||
};
|
||||
|
||||
namespace Colors {
|
||||
static constexpr Color Ground{67, 137, 39};
|
||||
static constexpr Color Ceiling{39, 69, 137};
|
||||
static constexpr Color Wall{84, 56, 34};
|
||||
static constexpr Color Door{186, 152, 107};
|
||||
static constexpr Color Window{104, 123, 165};
|
||||
}
|
||||
#endif //RAYCASTING_COLOR_H
|
Loading…
Add table
Add a link
Reference in a new issue