sandbox
Loading...
Searching...
No Matches
color.hpp
1#ifndef LIBSBX_MATH_COLOR_HPP_
2#define LIBSBX_MATH_COLOR_HPP_
3
4#include <cmath>
5
6#include <yaml-cpp/yaml.h>
7
9
10// #include <libsbx/math/vector4.hpp>
11
12namespace sbx::math {
13
14class color {
15
16public:
17
18 color() noexcept;
19
20 color(std::uint32_t rgba) noexcept;
21
22 color(std::float_t red, std::float_t green, std::float_t blue, std::float_t alpha = 1.0f) noexcept;
23
24 static auto black() noexcept -> color {
25 return color{0.0f, 0.0f, 0.0f, 1.0f};
26 }
27
28 static auto white() noexcept -> color {
29 return color{1.0f, 1.0f, 1.0f, 1.0f};
30 }
31
32 static auto red() noexcept -> color {
33 return color{1.0f, 0.0f, 0.0f, 1.0f};
34 }
35
36 static auto green() noexcept -> color {
37 return color{0.0f, 1.0f, 0.0f, 1.0f};
38 }
39
40 static auto blue() noexcept -> color {
41 return color{0.0f, 0.0f, 1.0f, 1.0f};
42 }
43
44 static auto magenta() noexcept -> color {
45 return color{1.0f, 0.0f, 1.0f, 1.0f};
46 }
47
48 static auto yellow() noexcept -> color {
49 return color{1.0f, 1.0f, 0.0f, 1.0f};
50 }
51
52 static auto cyan() noexcept -> color {
53 return color{0.0f, 1.0f, 1.0f, 1.0f};
54 }
55
56 auto r() const noexcept -> const std::float_t&;
57
58 auto r() noexcept -> std::float_t&;
59
60 auto g() const noexcept -> const std::float_t&;
61
62 auto g() noexcept -> std::float_t&;
63
64 auto b() const noexcept -> const std::float_t&;
65
66 auto b() noexcept -> std::float_t&;
67
68 auto a() const noexcept -> const std::float_t&;
69
70 auto a() noexcept -> std::float_t&;
71
72private:
73
74 std::float_t _red;
75 std::float_t _green;
76 std::float_t _blue;
77 std::float_t _alpha;
78
79}; // class color
80
81auto operator==(const color& lhs, const color& rhs) noexcept -> bool;
82
83auto operator*(color lhs, const std::float_t value) -> color;
84
85} // namespace sbx::math
86
87template<>
88struct YAML::convert<sbx::math::color> {
89 static auto encode(const sbx::math::color& color) -> Node;
90 static auto decode(const Node& node, sbx::math::color& color) -> bool;
91}; // struct YAML::convert
92
93auto operator<<(YAML::Emitter& out, const sbx::math::color& color) -> YAML::Emitter&;
94
95template<>
96struct std::hash<sbx::math::color> {
97 auto operator()(const sbx::math::color& color) const noexcept -> std::size_t;
98}; // struct std::hash
99
100#endif // LIBSBX_MATH_COLOR_HPP_
Definition: tests.cpp:5
Definition: color.hpp:14