Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_color.hpp
1#pragma once
2
3#include <iostream>
4#include <vector>
5
6namespace spk
7{
17 struct Color
18 {
20 float r;
22 float g;
24 float b;
26 float a;
27
31 Color();
36 Color(int p_value);
44 Color(int p_r, int p_g, int p_b, int p_a = 255);
52 Color(float p_r, float p_g, float p_b, float p_a = 1.0f);
53
59 Color operator+(const Color &p_other) const;
65 Color operator-(const Color &p_other) const;
71 bool operator==(const Color &p_other) const;
77 bool operator!=(const Color &p_other) const;
78
83 uint32_t toInt() const;
84
91 friend std::ostream &operator<<(std::ostream &p_os, const spk::Color &p_other);
98 friend std::wostream &operator<<(std::wostream &p_os, const spk::Color &p_other);
99
101 static const Color red;
103 static const Color blue;
105 static const Color green;
107 static const Color yellow;
109 static const Color purple;
111 static const Color cyan;
113 static const Color orange;
115 static const Color magenta;
117 static const Color pink;
119 static const Color black;
121 static const Color white;
123 static const Color grey;
124 };
125}
126
127namespace std
128{
139 template <>
140 struct hash<spk::Color>
141 {
147 size_t operator()(const spk::Color &p_color) const
148 {
149 size_t h1 = std::hash<float>{}(p_color.r);
150 size_t h2 = std::hash<float>{}(p_color.g);
151 size_t h3 = std::hash<float>{}(p_color.b);
152 size_t h4 = std::hash<float>{}(p_color.a);
153 size_t seed = h1;
154 seed ^= h2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
155 seed ^= h3 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
156 seed ^= h4 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
157 return (seed);
158 }
159 };
160}
STL namespace.
RGBA color utility storing normalized floating components.
Definition spk_color.hpp:18
float a
Alpha component in [0,1].
Definition spk_color.hpp:26
static const Color green
Predefined opaque green color.
Definition spk_color.hpp:105
static const Color blue
Predefined opaque blue color.
Definition spk_color.hpp:103
static const Color purple
Predefined opaque purple color.
Definition spk_color.hpp:109
Color operator+(const Color &p_other) const
Adds channel values component-wise.
Definition spk_color.cpp:51
static const Color white
Predefined opaque white color.
Definition spk_color.hpp:121
uint32_t toInt() const
Packs the color into 0xRRGGBBAA integer format.
Definition spk_color.cpp:85
float b
Blue component in [0,1].
Definition spk_color.hpp:24
static const Color orange
Predefined opaque orange color.
Definition spk_color.hpp:113
static const Color red
Predefined opaque red color.
Definition spk_color.hpp:101
static const Color black
Predefined opaque black color.
Definition spk_color.hpp:119
static const Color cyan
Predefined opaque cyan color.
Definition spk_color.hpp:111
friend std::ostream & operator<<(std::ostream &p_os, const spk::Color &p_other)
Streams a color to an ASCII output stream.
Definition spk_color.cpp:90
static const Color magenta
Predefined opaque magenta color.
Definition spk_color.hpp:115
float g
Green component in [0,1].
Definition spk_color.hpp:22
bool operator==(const Color &p_other) const
Equality comparison on every component.
Definition spk_color.cpp:73
static const Color grey
Predefined opaque grey color.
Definition spk_color.hpp:123
Color operator-(const Color &p_other) const
Subtracts channel values component-wise.
Definition spk_color.cpp:62
float r
Red component in [0,1].
Definition spk_color.hpp:20
bool operator!=(const Color &p_other) const
Inequality comparison on every component.
Definition spk_color.cpp:80
Color()
Builds an opaque black color.
Definition spk_color.cpp:22
static const Color yellow
Predefined opaque yellow color.
Definition spk_color.hpp:107
static const Color pink
Predefined opaque pink color.
Definition spk_color.hpp:117
size_t operator()(const spk::Color &p_color) const
Hashes a color using its four components.
Definition spk_color.hpp:147