gdk-graphics 0a0aef92e917cfbac53dffbc32c295e4de914093
Loading...
Searching...
No Matches
color.h
1// © Joseph Cameron - MIT License
2
3#ifndef GDK_GRAPHICS_COLOR_H
4#define GDK_GRAPHICS_COLOR_H
5
6#include <iosfwd>
7
8namespace gdk::graphics {
10 struct color final {
11 using channel_type = float;
12
13 channel_type r = 0, g = 0, b = 0, a = 1;
14
16 void clamp();
17
20 void operator+=(const color &aOther);
21
23 [[nodiscard]] constexpr bool operator==(const color &aOther) const = default;
24
26 color(const color &) = default;
28 color& operator=(const color &acolor) = default;
29
31 color(color &&) = default;
33 color& operator=(color &&acolor) = default;
34
36 color() = default;
37
40 constexpr color(const channel_type aR,
41 const channel_type aG,
42 const channel_type aB,
43 const channel_type aA = 1)
44 : r(aR), g(aG), b(aB), a(aA)
45 {}
46
49 //
51 static const color black;
53 static const color white;
55 static const color red;
57 static const color green;
59 static const color dark_green;
61 static const color blue;
64 static const color deathly_pink;
68 };
69
70 std::ostream &operator<<(std::ostream &stream, const color &acolor);
71
72 inline const color color::black{0.0f, 0.0f, 0.0f, 1.0f};
73 inline const color color::white{1.0f, 1.0f, 1.0f, 1.0f};
74 inline const color color::red{1.0f, 0.0f, 0.0f, 1.0f};
75 inline const color color::green{0.0f, 1.0f, 0.0f, 1.0f};
76 inline const color color::dark_green{0.0f, 0.6f, 0.0f, 1.0f};
77 inline const color color::blue{0.0f, 0.0f, 1.0f, 1.0f};
78 inline const color color::deathly_pink{1.0f, 0.2f, 0.8f, 1.0f};
79 inline const color color::cornflower_blue{
80 0.3921568627450980392156862745098f,
81 0.58431372549019607843137254901961f,
82 0.92941176470588235294117647058824f,
83 1.0f
84 };
85}
86
87#endif
88
Represents a 4 channel color: {Red, Green, Blue, Alpha}.
Definition color.h:10
static const color red
opaque red color
Definition color.h:55
static const color dark_green
opaque dark green color
Definition color.h:59
void operator+=(const color &aOther)
add two colors together.
color(color &&)=default
move semantics
static const color blue
opaque blue color
Definition color.h:61
static const color deathly_pink
Definition color.h:64
static const color cornflower_blue
an opaque pastel blue color
Definition color.h:66
color(const color &)=default
copy semantics
color & operator=(const color &acolor)=default
copy semantics
constexpr bool operator==(const color &aOther) const =default
equality semantics
constexpr color(const channel_type aR, const channel_type aG, const channel_type aB, const channel_type aA=1)
constructs a color with provided channel values. Alpha has a default opaque value
Definition color.h:40
static const color white
opaque white color
Definition color.h:53
color()=default
constructs a color as opaque black
static const color green
opaque green color
Definition color.h:57
static const color black
opaque black color
Definition color.h:51
color & operator=(color &&acolor)=default
move semantics
void clamp()
clamp each channel to the [0 - 1] range