[studio,turbine] Add support for window icons
Some checks are pending
Build / build (push) Waiting to run

This commit is contained in:
2025-04-11 21:37:22 -05:00
parent 5ca7e2f226
commit a521887ddd
9 changed files with 149 additions and 30 deletions

View File

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

View File

@ -21,4 +21,5 @@ target_link_libraries(
glad
glfw
imgui
lodepng
)

View File

@ -4,6 +4,7 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <lodepng.h>
#if TURBINE_USE_IMGUI
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
@ -228,6 +229,34 @@ ox::Error initGfx(Context &ctx) noexcept {
return {};
}
struct IconData {
std::vector<uint8_t> pixels;
int w{}, h{};
};
[[nodiscard]]
static ox::Result<IconData> toGlfwImgPixels(ox::SpanView<uint8_t> iconPng) noexcept {
ox::Result<IconData> out;
unsigned w{}, h{};
if (lodepng::decode(out.value.pixels, w, h, iconPng.data(), LodePNGColorType::LCT_RGBA)) {
return ox::Error{1, "unable to decode window icon PNG data"};
}
out.value.w = static_cast<int>(w);
out.value.h = static_cast<int>(h);
return out;
}
ox::Error setWindowIcon(Context &ctx, ox::SpanView<uint8_t> iconPng) noexcept {
OX_REQUIRE_M(icon, toGlfwImgPixels(iconPng));
GLFWimage const img {
.pixels = icon.pixels.data(),
.width = icon.w,
.height = icon.h,
};
glfwSetWindowIcon(ctx.window, 1, &img);
return {};
}
void setWindowTitle(Context &ctx, ox::StringViewCR title) noexcept {
auto cstr = ox_malloca(title.bytes() + 1, char);
ox::strncpy(cstr.get(), title.data(), title.bytes());