acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
opacity.h
1// Created by CamiloSasukeThomasBorregaardSoerensen 2021-01-26 00:17
2// This is how things starts happening, promise of Life, in a virgin Temple...
3// to be or not to be, or will it be or won't, that is the question....
4#pragma once
5
6
7class CLASS_DECL_ACME opacity
8{
9protected:
10
11
12 ::u8 m_u8Opacity;
13
14
15public:
16
17
18 constexpr opacity() { m_u8Opacity = 255; }
19 constexpr opacity(const class ::opacity & opacity) : m_u8Opacity(opacity.m_u8Opacity) { }
20
21 template < prototype_floating FLOATING >
22 constexpr opacity(FLOATING f) { m_u8Opacity = byte_clip(f * 255.); }
23 template < prototype_integral INTEGRAL >
24 constexpr opacity(INTEGRAL i) { m_u8Opacity = byte_clip(i); }
25
26
27 constexpr ::f64 f64_opacity() const { return m_u8Opacity / 255.; }
28 constexpr ::f32 f32_opacity() const { return m_u8Opacity / 255.f; }
29 constexpr ::u8 u8_opacity() const { return m_u8Opacity; }
30
31
32 constexpr bool is_opaque() const { return m_u8Opacity == 255; }
33 constexpr bool is_translucent() const { return m_u8Opacity < 255; }
34 constexpr bool is_transparent() const { return m_u8Opacity == 0; }
35 constexpr bool non_transparent() const { return m_u8Opacity > 0; }
36 constexpr ::u8 complement() const { return 255 - m_u8Opacity; }
37
38 template < prototype_floating FLOATING >
39 constexpr opacity & operator = (FLOATING f) { m_u8Opacity = byte_clip(f * 255.); return *this; }
40 template < prototype_integral INTEGRAL >
41 constexpr opacity & operator = (INTEGRAL i) { m_u8Opacity = byte_clip(i); return *this; }
42
43 template < prototype_integral INTEGRAL >
44 constexpr opacity operator + (INTEGRAL i) { return byte_clip(m_u8Opacity + i); }
45 template < prototype_integral INTEGRAL >
46 constexpr opacity operator - (INTEGRAL i) { return byte_clip(m_u8Opacity - i); }
47
48};
49
50
51inline class ::opacity operator""_opacity(long double d) { return d; }
52inline class ::opacity operator""_opacity(unsigned long long ul) { return (::u8) ul; }
53
54
55
56