From 8d88394e385dfc8322c4b05b72f0f43bd08bc20f Mon Sep 17 00:00:00 2001 From: catsoften Date: Sat, 15 Apr 2023 19:03:43 -0400 Subject: [PATCH] Add RGBA.Pack(), Simplify ui::Colour/RGBA conversions --- src/graphics/Pixel.h | 6 ++++++ src/gui/interface/Slider.cpp | 4 ++-- src/lua/LuaScriptInterface.cpp | 6 ++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/graphics/Pixel.h b/src/graphics/Pixel.h index e9092938f..cce7336a9 100644 --- a/src/graphics/Pixel.h +++ b/src/graphics/Pixel.h @@ -136,6 +136,12 @@ struct alignas(alignof(uint32_t) > alignof(T) ? alignof(uint32_t) : alignof(T)) return RGB(Red, Green, Blue); } + template>> + constexpr pixel Pack() const + { + return Red << 16 | Green << 8 | Blue | Alpha << 24; + } + template>> constexpr static RGBA Unpack(pixel_rgba px) { diff --git a/src/gui/interface/Slider.cpp b/src/gui/interface/Slider.cpp index 4d612eb3a..0247534d3 100644 --- a/src/gui/interface/Slider.cpp +++ b/src/gui/interface/Slider.cpp @@ -68,8 +68,8 @@ void Slider::SetColour(Colour col1, Colour col2) this->col1 = col1; this->col2 = col2; bgGradient = Graphics::Gradient({ - { RGB(col1.Red, col1.Green, col1.Blue), 0.f }, - { RGB(col2.Red, col2.Green, col2.Blue), 1.f }, + { col1.NoAlpha(), 0.f }, + { col2.NoAlpha(), 1.f }, }, Size.X-7); } diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index a378a51be..0ae077710 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -1856,9 +1856,7 @@ int LuaScriptInterface::simulation_decoColor(lua_State * l) RGBA color(0, 0, 0, 0); if (acount == 0) { - ui::Colour tempColor = luacon_model->GetColourSelectorColour(); - unsigned int color = (tempColor.Alpha << 24) | RGB(tempColor.Red, tempColor.Green, tempColor.Blue).Pack(); - lua_pushnumber(l, color); + lua_pushnumber(l, luacon_model->GetColourSelectorColour().Pack()); return 1; } else if (acount == 1) @@ -1870,7 +1868,7 @@ int LuaScriptInterface::simulation_decoColor(lua_State * l) color.Blue = std::clamp(luaL_optint(l, 3, 255), 0, 255); color.Alpha = std::clamp(luaL_optint(l, 4, 255), 0, 255); } - luacon_model->SetColourSelectorColour(ui::Colour(color.Red, color.Green, color.Blue, color.Alpha)); + luacon_model->SetColourSelectorColour(color); return 0; }