Skip to content

Commit

Permalink
Add RGBA.Pack(), Simplify ui::Colour/RGBA conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
catsoften authored and LBPHacker committed Apr 16, 2023
1 parent 561fc17 commit 8d88394
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/graphics/Pixel.h
Expand Up @@ -136,6 +136,12 @@ struct alignas(alignof(uint32_t) > alignof(T) ? alignof(uint32_t) : alignof(T))
return RGB<T>(Red, Green, Blue);
}

template<typename S = T, typename = std::enable_if_t<std::is_same_v<S, uint8_t>>>
constexpr pixel Pack() const
{
return Red << 16 | Green << 8 | Blue | Alpha << 24;
}

template<typename S = T, typename = std::enable_if_t<std::is_same_v<S, uint8_t>>>
constexpr static RGBA<T> Unpack(pixel_rgba px)
{
Expand Down
4 changes: 2 additions & 2 deletions src/gui/interface/Slider.cpp
Expand Up @@ -68,8 +68,8 @@ void Slider::SetColour(Colour col1, Colour col2)
this->col1 = col1;
this->col2 = col2;
bgGradient = Graphics::Gradient({
{ RGB<uint8_t>(col1.Red, col1.Green, col1.Blue), 0.f },
{ RGB<uint8_t>(col2.Red, col2.Green, col2.Blue), 1.f },
{ col1.NoAlpha(), 0.f },
{ col2.NoAlpha(), 1.f },
}, Size.X-7);
}

Expand Down
6 changes: 2 additions & 4 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -1856,9 +1856,7 @@ int LuaScriptInterface::simulation_decoColor(lua_State * l)
RGBA<uint8_t> color(0, 0, 0, 0);
if (acount == 0)
{
ui::Colour tempColor = luacon_model->GetColourSelectorColour();
unsigned int color = (tempColor.Alpha << 24) | RGB<uint8_t>(tempColor.Red, tempColor.Green, tempColor.Blue).Pack();
lua_pushnumber(l, color);
lua_pushnumber(l, luacon_model->GetColourSelectorColour().Pack());
return 1;
}
else if (acount == 1)
Expand All @@ -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;
}

Expand Down

0 comments on commit 8d88394

Please sign in to comment.