[turbine,studio,nostalgia/studio] Add support for window icon scaling, expand icons sizes for Nostalgia Studio
Some checks are pending
Build / build (push) Waiting to run

This commit is contained in:
2025-04-11 22:42:23 -05:00
parent 9b6b60e4d1
commit 02230ef619
17 changed files with 1474 additions and 15 deletions

View File

@ -26,7 +26,7 @@ void removeDrawer(Context &ctx, Drawer *cd) noexcept;
ox::Error initGfx(Context &ctx) noexcept;
ox::Error setWindowIcon(Context &ctx, ox::SpanView<uint8_t> const &iconPng) noexcept;
ox::Error setWindowIcon(Context &ctx, ox::SpanView<ox::SpanView<uint8_t>> const &iconPngs) noexcept;
void setWindowTitle(Context &ctx, ox::StringViewCR title) noexcept;

View File

@ -238,7 +238,7 @@ struct IconData {
static ox::Result<IconData> toGlfwImgPixels(ox::SpanView<uint8_t> const &iconPng) noexcept {
ox::Result<IconData> out;
unsigned w{}, h{};
if (lodepng::decode(out.value.pixels, w, h, iconPng.data(), LodePNGColorType::LCT_RGBA)) {
if (lodepng::decode(out.value.pixels, w, h, iconPng.data(), iconPng.size())) {
return ox::Error{1, "unable to decode window icon PNG data"};
}
out.value.w = static_cast<int>(w);
@ -246,14 +246,19 @@ static ox::Result<IconData> toGlfwImgPixels(ox::SpanView<uint8_t> const &iconPng
return out;
}
ox::Error setWindowIcon(Context &ctx, ox::SpanView<uint8_t> const &iconPng) noexcept {
OX_REQUIRE_M(icon, toGlfwImgPixels(iconPng));
GLFWimage const img {
.width = icon.w,
.height = icon.h,
.pixels = icon.pixels.data(),
};
glfwSetWindowIcon(ctx.window, 1, &img);
ox::Error setWindowIcon(Context &ctx, ox::SpanView<ox::SpanView<uint8_t>> const &iconPngs) noexcept {
ox::Vector<IconData, 8> src;
ox::Vector<GLFWimage, 8> imgs;
for (auto const &iconPng : iconPngs) {
OX_RETURN_ERROR(toGlfwImgPixels(iconPng).moveTo(src.emplace_back()));
auto &icon = *src.back().unwrap();
imgs.emplace_back(GLFWimage{
.width = icon.w,
.height = icon.h,
.pixels = icon.pixels.data(),
});
}
glfwSetWindowIcon(ctx.window, imgs.size(), imgs.data());
return {};
}