Ember
Loading...
Searching...
No Matches
Color.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
5namespace EmberCore {
6
10struct Color {
11 uint8_t r = 0;
12 uint8_t g = 0;
13 uint8_t b = 0;
14 uint8_t a = 255; // Alpha, 255 = fully opaque
15
16 Color() = default;
17 Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) : r(r), g(g), b(b), a(a) {}
18
19 // Common color constructors
20 static Color FromRGB(uint8_t r, uint8_t g, uint8_t b) { return Color(r, g, b, 255); }
21
22 static Color FromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { return Color(r, g, b, a); }
23
24 // Create from 32-bit RGBA value
25 static Color FromRGBA32(uint32_t rgba) {
26 return Color(static_cast<uint8_t>((rgba >> 24) & 0xFF), // R
27 static_cast<uint8_t>((rgba >> 16) & 0xFF), // G
28 static_cast<uint8_t>((rgba >> 8) & 0xFF), // B
29 static_cast<uint8_t>(rgba & 0xFF) // A
30 );
31 }
32
33 // Convert to 32-bit RGBA value
34 uint32_t ToRGBA32() const {
35 return (static_cast<uint32_t>(r) << 24) | (static_cast<uint32_t>(g) << 16) | (static_cast<uint32_t>(b) << 8) |
36 static_cast<uint32_t>(a);
37 }
38
39 bool operator==(const Color &other) const { return r == other.r && g == other.g && b == other.b && a == other.a; }
40
41 bool operator!=(const Color &other) const { return !(*this == other); }
42
43 // Common predefined colors
44 static const Color Black;
45 static const Color White;
46 static const Color Red;
47 static const Color Green;
48 static const Color Blue;
49 static const Color Yellow;
50 static const Color Cyan;
51 static const Color Magenta;
52 static const Color Gray;
53 static const Color DarkGray;
54 static const Color LightGray;
55 static const Color Transparent;
56};
57
58} // namespace EmberCore
Main types header for EmberCore.
static const Color Yellow
Definition Color.h:49
static const Color LightGray
Definition Color.h:54
static Color FromRGBA32(uint32_t rgba)
Definition Color.h:25
uint8_t b
Definition Color.h:13
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Definition Color.h:17
static const Color Transparent
Definition Color.h:55
static const Color Gray
Definition Color.h:52
bool operator!=(const Color &other) const
Definition Color.h:41
static const Color Cyan
Definition Color.h:50
bool operator==(const Color &other) const
Definition Color.h:39
static const Color DarkGray
Definition Color.h:53
static const Color Magenta
Definition Color.h:51
static const Color Black
Definition Color.h:44
static Color FromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Definition Color.h:22
uint8_t r
Definition Color.h:11
uint8_t g
Definition Color.h:12
static const Color Blue
Definition Color.h:48
uint8_t a
Definition Color.h:14
static const Color Red
Definition Color.h:46
static const Color White
Definition Color.h:45
static const Color Green
Definition Color.h:47
uint32_t ToRGBA32() const
Definition Color.h:34
static Color FromRGB(uint8_t r, uint8_t g, uint8_t b)
Definition Color.h:20