HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
color.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../geometry/numeric_array.hpp"
8
9namespace tt {
10
39class color {
40public:
41 constexpr color(color const &) noexcept = default;
42 constexpr color(color &&) noexcept = default;
43 constexpr color &operator=(color const &) noexcept = default;
44 constexpr color &operator=(color &&) noexcept = default;
45
46 [[nodiscard]] constexpr explicit color(f32x4 other) noexcept : _v(std::move(other))
47 {
48 tt_axiom(is_valid());
49 }
50 [[nodiscard]] constexpr explicit operator f32x4() const noexcept
51 {
52 return _v;
53 }
54
55 [[nodiscard]] constexpr color() noexcept : _v(0.0, 0.0, 0.0, 1.0) {}
56 [[nodiscard]] constexpr color(float r, float g, float b, float a = 1.0) noexcept : _v(r, g, b, a) {}
57
58 [[nodiscard]] static constexpr color transparent() noexcept
59 {
60 return {0.0f, 0.0f, 0.0f, 0.0f};
61 }
62
63 [[nodiscard]] constexpr float &r() noexcept
64 {
65 return _v.x();
66 }
67
68 [[nodiscard]] constexpr float &g() noexcept
69 {
70 return _v.y();
71 }
72
73 [[nodiscard]] constexpr float &b() noexcept
74 {
75 return _v.z();
76 }
77
78 [[nodiscard]] constexpr float &a() noexcept
79 {
80 return _v.w();
81 }
82
83 [[nodiscard]] constexpr float const &r() const noexcept
84 {
85 return _v.x();
86 }
87
88 [[nodiscard]] constexpr float const &g() const noexcept
89 {
90 return _v.y();
91 }
92
93 [[nodiscard]] constexpr float const &b() const noexcept
94 {
95 return _v.z();
96 }
97
98 [[nodiscard]] constexpr float const &a() const noexcept
99 {
100 return _v.w();
101 }
102
103 [[nodiscard]] constexpr bool is_valid() const noexcept
104 {
105 return _v.w() >= 0.0 && _v.w() <= 1.0;
106 }
107
108 [[nodiscard]] constexpr friend bool operator==(color const &lhs, color const &rhs) noexcept
109 {
110 return lhs._v == rhs._v;
111 }
112
113 [[nodiscard]] constexpr friend color operator*(color const &lhs, color const &rhs) noexcept
114 {
115 return color{lhs._v * rhs._v};
116 }
117
118 [[nodiscard]] constexpr friend color composit(color const &lhs, color const &rhs) noexcept
119 {
120 return color{composit(lhs._v, rhs._v)};
121 }
122
123private:
124 f32x4 _v;
125};
126
127} // namespace tt
This is a RGBA floating point color.
Definition color.hpp:39
T move(T... args)