aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Utils/Color.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-11-27 12:04:31 -0800
committerrtk0c <[email protected]>2022-11-27 12:04:31 -0800
commit182c8f8357739f905bbd721006480502435b6b43 (patch)
tree082613a474d863182e2ad8f2167f1643f26e67a3 /app/source/Cplt/Utils/Color.hpp
parentb01ed99a1cd0c863c8709930658513c04dd70f61 (diff)
Update brace style to match rest of my projectscplt-imgui
Diffstat (limited to 'app/source/Cplt/Utils/Color.hpp')
-rw-r--r--app/source/Cplt/Utils/Color.hpp66
1 files changed, 22 insertions, 44 deletions
diff --git a/app/source/Cplt/Utils/Color.hpp b/app/source/Cplt/Utils/Color.hpp
index 15fe6a1..6d56951 100644
--- a/app/source/Cplt/Utils/Color.hpp
+++ b/app/source/Cplt/Utils/Color.hpp
@@ -9,8 +9,7 @@
#include <cstdint>
#include <limits>
-class RgbaColor
-{
+class RgbaColor {
public:
uint8_t r;
uint8_t g;
@@ -22,36 +21,31 @@ public:
: r{ 255 }
, g{ 255 }
, b{ 255 }
- , a{ 255 }
- {
+ , a{ 255 } {
}
constexpr RgbaColor(float r, float g, float b, float a = 1.0f) noexcept
: r{ static_cast<uint8_t>(r * 255.0f) }
, g{ static_cast<uint8_t>(g * 255.0f) }
, b{ static_cast<uint8_t>(b * 255.0f) }
- , a{ static_cast<uint8_t>(a * 255.0f) }
- {
+ , a{ static_cast<uint8_t>(a * 255.0f) } {
}
constexpr RgbaColor(int r, int g, int b, int a = 255) noexcept
: r{ static_cast<uint8_t>(r & 0xFF) }
, g{ static_cast<uint8_t>(g & 0xFF) }
, b{ static_cast<uint8_t>(b & 0xFF) }
- , a{ static_cast<uint8_t>(a & 0xFF) }
- {
+ , a{ static_cast<uint8_t>(a & 0xFF) } {
}
constexpr RgbaColor(uint32_t rgba) noexcept
: r{ static_cast<uint8_t>((rgba >> 0) & 0xFF) }
, g{ static_cast<uint8_t>((rgba >> 8) & 0xFF) }
, b{ static_cast<uint8_t>((rgba >> 16) & 0xFF) }
- , a{ static_cast<uint8_t>((rgba >> 24) & 0xFF) }
- {
+ , a{ static_cast<uint8_t>((rgba >> 24) & 0xFF) } {
}
- constexpr uint32_t GetScalar() const noexcept
- {
+ constexpr uint32_t GetScalar() const noexcept {
uint32_t res = 0;
res |= r << 24;
res |= g << 16;
@@ -60,41 +54,34 @@ public:
return res;
}
- constexpr void SetScalar(uint32_t scalar) noexcept
- {
+ constexpr void SetScalar(uint32_t scalar) noexcept {
r = (scalar >> 0) & 0xFF;
g = (scalar >> 8) & 0xFF;
b = (scalar >> 16) & 0xFF;
a = (scalar >> 24) & 0xFF;
}
- constexpr float GetNormalizedRed() const noexcept
- {
+ constexpr float GetNormalizedRed() const noexcept {
return r / 255.0f;
}
- constexpr float GetNormalizedGreen() const noexcept
- {
+ constexpr float GetNormalizedGreen() const noexcept {
return g / 255.0f;
}
- constexpr float GetNormalizedBlue() const noexcept
- {
+ constexpr float GetNormalizedBlue() const noexcept {
return b / 255.0f;
}
- constexpr float GetNormalizedAlpha() const noexcept
- {
+ constexpr float GetNormalizedAlpha() const noexcept {
return a / 255.0f;
}
- constexpr Vec4i AsVec4i() const noexcept
- {
+ constexpr Vec4i AsVec4i() const noexcept {
return Vec4i{ r, g, b, a };
}
- constexpr Vec4f AsVec4f() const noexcept
- {
+ constexpr Vec4f AsVec4f() const noexcept {
return Vec4f{
GetNormalizedRed(),
GetNormalizedGreen(),
@@ -103,20 +90,17 @@ public:
};
}
- ImVec4 AsImVec() const
- {
+ ImVec4 AsImVec() const {
auto v = AsVec4f();
return ImVec4{ v.x, v.y, v.z, v.w };
}
- ImColor AsImColor() const
- {
+ ImColor AsImColor() const {
auto v = AsVec4f();
return ImColor{ v.x, v.y, v.z, v.w };
}
- ImU32 AsImU32() const
- {
+ ImU32 AsImU32() const {
ImU32 res;
res |= r << IM_COL32_R_SHIFT;
res |= g << IM_COL32_G_SHIFT;
@@ -125,8 +109,7 @@ public:
return res;
}
- constexpr void SetVec(const Vec4f& vec) noexcept
- {
+ constexpr void SetVec(const Vec4f& vec) noexcept {
r = (uint8_t)(vec.x * 255.0f);
g = (uint8_t)(vec.y * 255.0f);
b = (uint8_t)(vec.z * 255.0f);
@@ -139,8 +122,7 @@ public:
friend constexpr bool operator==(const RgbaColor&, const RgbaColor&) noexcept = default;
};
-class HsvColor
-{
+class HsvColor {
public:
float h;
float s;
@@ -152,24 +134,21 @@ public:
: h{ 0.0f }
, s{ 0.0f }
, v{ 1.0f }
- , a{ 1.0f }
- {
+ , a{ 1.0f } {
}
constexpr HsvColor(float h, float s, float v, float a) noexcept
: h{ h }
, s{ s }
, v{ v }
- , a{ a }
- {
+ , a{ a } {
}
// Forward declaring because cyclic reference between RgbaColor and HsvColor
constexpr RgbaColor ToRgba() const noexcept;
};
-constexpr HsvColor RgbaColor::ToHsv() const noexcept
-{
+constexpr HsvColor RgbaColor::ToHsv() const noexcept {
float fr = GetNormalizedRed();
float fg = GetNormalizedBlue();
float fb = GetNormalizedGreen();
@@ -185,8 +164,7 @@ constexpr HsvColor RgbaColor::ToHsv() const noexcept
return HsvColor(hcv.x, s, hcv.z, fa);
}
-constexpr RgbaColor HsvColor::ToRgba() const noexcept
-{
+constexpr RgbaColor HsvColor::ToRgba() const noexcept {
float r = MathUtils::Abs(h * 6 - 3) - 1;
float g = 2 - MathUtils::Abs(h * 6 - 2);
float b = 2 - MathUtils::Abs(h * 6 - 4);