Merge commit '09b4a705a9251d54e797eb75db1f3d4687829a24'

This commit is contained in:
2025-04-16 19:48:37 -05:00
32 changed files with 3065 additions and 87 deletions

View File

@ -32,11 +32,15 @@ static void keyEventHandler(turbine::Context &ctx, turbine::Key key, bool down)
sctx->ui.handleKeyEvent(key, down);
}
[[nodiscard]]
ox::Vector<ox::SpanView<uint8_t>> WindowIcons() noexcept;
static ox::Error runApp(
ox::StringViewCR appName,
ox::StringViewCR projectDataDir,
ox::UPtr<ox::FileSystem> &&fs) noexcept {
OX_REQUIRE_M(ctx, turbine::init(std::move(fs), appName));
oxLogError(turbine::setWindowIcon(*ctx, WindowIcons()));
turbine::setWindowTitle(*ctx, keelCtx(*ctx).appName);
turbine::setKeyEventHandler(*ctx, keyEventHandler);
turbine::setRefreshWithin(*ctx, 0);

View File

@ -71,12 +71,6 @@ class SelectionTracker {
return m_selectionOngoing;
}
constexpr void startSelection(ox::Point cursor) noexcept {
m_pointA = cursor;
m_pointB = cursor;
m_selectionOngoing = true;
}
/**
*
* @param cursor

View File

@ -26,20 +26,22 @@ void removeDrawer(Context &ctx, Drawer *cd) noexcept;
ox::Error initGfx(Context &ctx) noexcept;
ox::Error setWindowIcon(Context &ctx, ox::SpanView<ox::SpanView<uint8_t>> const &iconPngs) noexcept;
void setWindowTitle(Context &ctx, ox::StringViewCR title) noexcept;
void focusWindow(Context &ctx) noexcept;
[[nodiscard]]
int getScreenWidth(Context &ctx) noexcept;
int getScreenWidth(Context const &ctx) noexcept;
[[nodiscard]]
int getScreenHeight(Context &ctx) noexcept;
int getScreenHeight(Context const &ctx) noexcept;
[[nodiscard]]
ox::Size getScreenSize(Context &ctx) noexcept;
ox::Size getScreenSize(Context const &ctx) noexcept;
ox::Bounds getWindowBounds(Context &ctx) noexcept;
ox::Bounds getWindowBounds(Context const &ctx) noexcept;
ox::Error setWindowBounds(Context &ctx, ox::Bounds const&bnds) noexcept;

View File

@ -27,19 +27,19 @@ ox::Error initGfx(Context&) noexcept {
void setWindowTitle(Context&, ox::StringViewCR) noexcept {
}
int getScreenWidth(Context&) noexcept {
int getScreenWidth(Context const&) noexcept {
return 240;
}
int getScreenHeight(Context&) noexcept {
int getScreenHeight(Context const&) noexcept {
return 160;
}
ox::Size getScreenSize(Context&) noexcept {
ox::Size getScreenSize(Context const&) noexcept {
return {240, 160};
}
ox::Bounds getWindowBounds(Context&) noexcept {
ox::Bounds getWindowBounds(Context const&) noexcept {
return {0, 0, 240, 160};
}

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,39 @@ 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> const &iconPng) noexcept {
ox::Result<IconData> out;
unsigned w{}, h{};
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);
out.value.h = static_cast<int>(h);
return out;
}
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, static_cast<int>(imgs.size()), imgs.data());
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());
@ -238,25 +272,25 @@ void focusWindow(Context &ctx) noexcept {
glfwFocusWindow(ctx.window);
}
int getScreenWidth(Context &ctx) noexcept {
int getScreenWidth(Context const &ctx) noexcept {
int w = 0, h = 0;
glfwGetFramebufferSize(ctx.window, &w, &h);
return w;
}
int getScreenHeight(Context &ctx) noexcept {
int getScreenHeight(Context const &ctx) noexcept {
int w = 0, h = 0;
glfwGetFramebufferSize(ctx.window, &w, &h);
return h;
}
ox::Size getScreenSize(Context &ctx) noexcept {
ox::Size getScreenSize(Context const &ctx) noexcept {
int w = 0, h = 0;
glfwGetFramebufferSize(ctx.window, &w, &h);
return {w, h};
}
ox::Bounds getWindowBounds(Context &ctx) noexcept {
ox::Bounds getWindowBounds(Context const &ctx) noexcept {
ox::Bounds bnds;
glfwGetWindowPos(ctx.window, &bnds.x, &bnds.y);
glfwGetWindowSize(ctx.window, &bnds.width, &bnds.height);