Add RGBA.Pack(), Simplify ui::Colour/RGBA conversions
This commit is contained in:
parent
561fc17431
commit
8d88394e38
@ -136,6 +136,12 @@ struct alignas(alignof(uint32_t) > alignof(T) ? alignof(uint32_t) : alignof(T))
|
|||||||
return RGB<T>(Red, Green, Blue);
|
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>>>
|
template<typename S = T, typename = std::enable_if_t<std::is_same_v<S, uint8_t>>>
|
||||||
constexpr static RGBA<T> Unpack(pixel_rgba px)
|
constexpr static RGBA<T> Unpack(pixel_rgba px)
|
||||||
{
|
{
|
||||||
|
@ -68,8 +68,8 @@ void Slider::SetColour(Colour col1, Colour col2)
|
|||||||
this->col1 = col1;
|
this->col1 = col1;
|
||||||
this->col2 = col2;
|
this->col2 = col2;
|
||||||
bgGradient = Graphics::Gradient({
|
bgGradient = Graphics::Gradient({
|
||||||
{ RGB<uint8_t>(col1.Red, col1.Green, col1.Blue), 0.f },
|
{ col1.NoAlpha(), 0.f },
|
||||||
{ RGB<uint8_t>(col2.Red, col2.Green, col2.Blue), 1.f },
|
{ col2.NoAlpha(), 1.f },
|
||||||
}, Size.X-7);
|
}, Size.X-7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1856,9 +1856,7 @@ int LuaScriptInterface::simulation_decoColor(lua_State * l)
|
|||||||
RGBA<uint8_t> color(0, 0, 0, 0);
|
RGBA<uint8_t> color(0, 0, 0, 0);
|
||||||
if (acount == 0)
|
if (acount == 0)
|
||||||
{
|
{
|
||||||
ui::Colour tempColor = luacon_model->GetColourSelectorColour();
|
lua_pushnumber(l, luacon_model->GetColourSelectorColour().Pack());
|
||||||
unsigned int color = (tempColor.Alpha << 24) | RGB<uint8_t>(tempColor.Red, tempColor.Green, tempColor.Blue).Pack();
|
|
||||||
lua_pushnumber(l, color);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (acount == 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.Blue = std::clamp(luaL_optint(l, 3, 255), 0, 255);
|
||||||
color.Alpha = std::clamp(luaL_optint(l, 4, 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user