lxgui
Loading...
Searching...
No Matches
gui_color.hpp
1#ifndef LXGUI_GUI_COLOR_HPP
2#define LXGUI_GUI_COLOR_HPP
3
4#include "lxgui/lxgui.hpp"
5
6#include <cstdint>
7#include <iosfwd>
8#include <string>
9
10namespace lxgui::gui {
11
13class color {
14public:
15 using channel = float;
16
17 struct hls {
19 };
20
21 struct hsv {
23 };
24
25 constexpr color() = default;
26 constexpr color(channel nr, channel ng, channel nb, channel na = 1.0f) noexcept :
27 r(nr), g(ng), b(nb), a(na) {}
28 explicit color(const std::string& s);
29
30 hls to_hls() const noexcept;
31 hsv to_hsv() const noexcept;
32
33 bool operator==(const color& c) const noexcept;
34 bool operator!=(const color& c) const noexcept;
35
36 void operator+=(const color& c) noexcept;
37 void operator-=(const color& c) noexcept;
38 void operator*=(const color& c) noexcept;
39 void operator*=(float f) noexcept;
40
41 channel r = 1.0f, g = 1.0f, b = 1.0f, a = 1.0f;
42
43 static const color empty;
44 static const color white;
45 static const color black;
46 static const color red;
47 static const color green;
48 static const color blue;
49 static const color grey;
50
51 static constexpr color
52 from_bytes(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a = 255u) noexcept {
53 return color(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
54 }
55
56 static color from_hls(const hls& hls) noexcept;
57 static color from_hsv(const hsv& hsv) noexcept;
58};
59
60color operator+(const color& c1, const color& c2) noexcept;
61color operator-(const color& c1, const color& c2) noexcept;
62color operator*(const color& c1, const color& c2) noexcept;
63color operator*(const color& c1, float f) noexcept;
64color operator*(float f, const color& c2) noexcept;
65
66std::ostream& operator<<(std::ostream& stream, const color& c);
67std::istream& operator>>(std::istream& stream, color& c);
68
76struct color32 {
77 using chanel = unsigned char;
78
79 chanel r, g, b, a;
80};
81
82} // namespace lxgui::gui
83
84#endif
Holds a single color (float RGBA, 128 bits)
Definition gui_color.hpp:13
static const color green
Definition gui_color.hpp:47
static const color red
Definition gui_color.hpp:46
static const color blue
Definition gui_color.hpp:48
hsv to_hsv() const noexcept
Definition gui_color.cpp:62
static color from_hls(const hls &hls) noexcept
static color from_hsv(const hsv &hsv) noexcept
constexpr color()=default
static const color white
Definition gui_color.hpp:44
constexpr color(channel nr, channel ng, channel nb, channel na=1.0f) noexcept
Definition gui_color.hpp:26
static constexpr color from_bytes(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a=255u) noexcept
Definition gui_color.hpp:52
static const color grey
Definition gui_color.hpp:49
static const color black
Definition gui_color.hpp:45
hls to_hls() const noexcept
Definition gui_color.cpp:26
static const color empty
Definition gui_color.hpp:43
std::ostream & operator<<(std::ostream &stream, const color &c)
std::istream & operator>>(std::istream &stream, color &c)
color operator+(const color &c1, const color &c2) noexcept
color operator*(const color &c1, const color &c2) noexcept
color operator-(const color &c1, const color &c2) noexcept
STL namespace.
Holds a single color (byte RGBA, 32 bits)
Definition gui_color.hpp:76
unsigned char chanel
Definition gui_color.hpp:77