IDS peak ICV v1.1.0
Loading...
Searching...
No Matches
peak_icv_opacity.hpp
Go to the documentation of this file.
1
11#pragma once
12
15
16#include <type_traits>
17#include <cstdint>
18#include <string>
19
20namespace peak
21{
22namespace icv
23{
37class Opacity : public detail::IPrintable<Opacity>
38{
39public:
45 constexpr explicit Opacity()
46 : Opacity(maximum)
47 {}
48
58 constexpr explicit Opacity(uint32_t value)
59 : m_value(value)
60 {
61 if (value > maximum)
62 {
64 "Opacity value has to be within the range of " + std::to_string(minimum) + " to " + std::to_string(maximum) + ".");
65 }
66 }
67
73 PEAK_COMMON_NO_DISCARD constexpr uint32_t GetValue() const
74 {
75 return m_value;
76 }
77
83 PEAK_COMMON_NO_DISCARD static constexpr uint32_t GetMinimum()
84 {
85 return minimum;
86 }
87
93 PEAK_COMMON_NO_DISCARD static constexpr uint32_t GetMaximum()
94 {
95 return maximum;
96 }
97
103 template <typename Opacity
105 ,
106 std::enable_if_t<std::is_integral<Opacity>::value, bool> = true
108 >
109 auto operator==(const Opacity& value) const
110 {
111 return static_cast<uint32_t>(value) == m_value;
112 }
113
114protected:
115 void Print(detail::CommaSeperatedStream& stream) const override
116 {
117 stream << GetValue();
118 }
119
120private:
121 static constexpr uint32_t minimum = 0;
122 static constexpr uint32_t maximum = 100;
123 uint32_t m_value{ maximum };
124};
125
126} /* namespace icv */
127} /* namespace peak */
Holds an opacity value representing the transparency level of an object or pixel.
constexpr Opacity(uint32_t value)
Constructs an Opacity object with the specified value.
constexpr uint32_t GetValue() const
static constexpr uint32_t GetMaximum()
constexpr Opacity()
Constructs an Opacity object with full opacity (100).
auto operator==(const Opacity &value) const
static constexpr uint32_t GetMinimum()
Thrown when a value is outside the allowed range.