diff --git a/src/olympic/studio/applib/src/app.cpp b/src/olympic/studio/applib/src/app.cpp index 8507638c5..6eb9d131d 100644 --- a/src/olympic/studio/applib/src/app.cpp +++ b/src/olympic/studio/applib/src/app.cpp @@ -28,10 +28,15 @@ class StudioUIDrawer: public turbine::gl::Drawer { }; static void keyEventHandler(turbine::Context &ctx, turbine::Key key, bool down) noexcept { - auto sctx = turbine::applicationData(ctx); + auto const sctx = turbine::applicationData(ctx); sctx->ui.handleKeyEvent(key, down); } +static void mouseButtonEventHandler(turbine::Context &ctx, int const btn, bool const down) noexcept { + auto const sctx = turbine::applicationData(ctx); + sctx->ui.handleMouseButtonEvent(btn, down); +} + [[nodiscard]] ox::Vector> WindowIcons() noexcept; @@ -43,6 +48,7 @@ static ox::Error runApp( oxLogError(turbine::setWindowIcon(*ctx, WindowIcons())); turbine::setWindowTitle(*ctx, keelCtx(*ctx).appName); turbine::setKeyEventHandler(*ctx, keyEventHandler); + turbine::setMouseButtonEventHandler(*ctx, mouseButtonEventHandler); turbine::requireRefreshWithin(*ctx, 0); StudioUI ui(*ctx, projectDataDir); StudioUIDrawer drawer(ui); diff --git a/src/olympic/studio/applib/src/studioui.cpp b/src/olympic/studio/applib/src/studioui.cpp index 83f5fea99..8cfbcd4f8 100644 --- a/src/olympic/studio/applib/src/studioui.cpp +++ b/src/olympic/studio/applib/src/studioui.cpp @@ -177,6 +177,16 @@ void StudioUI::handleKeyEvent(turbine::Key const key, bool const down) noexcept } } +void StudioUI::handleMouseButtonEvent(int const btn, bool const down) noexcept { + if (down) { + if (btn == 3) { // back button + navigateBack(m_sctx); + } else if (btn == 4) { // forward button + navigateForward(m_sctx); + } + } +} + void StudioUI::handleNavigationChange(ox::StringParam path, ox::StringParam navArgs) noexcept { m_navAction.emplace(std::move(path), std::move(navArgs)); } diff --git a/src/olympic/studio/applib/src/studioui.hpp b/src/olympic/studio/applib/src/studioui.hpp index ed4c0f9f5..dc758786e 100644 --- a/src/olympic/studio/applib/src/studioui.hpp +++ b/src/olympic/studio/applib/src/studioui.hpp @@ -87,6 +87,8 @@ class StudioUI final: public ox::SignalHandler { void handleKeyEvent(turbine::Key, bool down) noexcept; + void handleMouseButtonEvent(int btn, bool down) noexcept; + void handleNavigationChange(ox::StringParam path, ox::StringParam navArgs) noexcept; [[nodiscard]] diff --git a/src/olympic/turbine/include/turbine/turbine.hpp b/src/olympic/turbine/include/turbine/turbine.hpp index 338cd4b35..65cce5d13 100644 --- a/src/olympic/turbine/include/turbine/turbine.hpp +++ b/src/olympic/turbine/include/turbine/turbine.hpp @@ -79,11 +79,14 @@ enum Key { }; using KeyEventHandler = void(*)(Context&, Key, bool); +using MouseButtonEventHandler = void(*)(Context&, int btn, bool); void setKeyEventHandler(Context &ctx, KeyEventHandler h) noexcept; +void setMouseButtonEventHandler(Context &ctx, MouseButtonEventHandler h) noexcept; + [[nodiscard]] -KeyEventHandler keyEventHandler(Context &ctx) noexcept; +KeyEventHandler keyEventHandler(Context const &ctx) noexcept; [[nodiscard]] bool buttonDown(Context const&ctx, Key) noexcept; diff --git a/src/olympic/turbine/src/gba/turbine.cpp b/src/olympic/turbine/src/gba/turbine.cpp index c015e036e..df24c0ed2 100644 --- a/src/olympic/turbine/src/gba/turbine.cpp +++ b/src/olympic/turbine/src/gba/turbine.cpp @@ -133,7 +133,9 @@ void setKeyEventHandler(Context &ctx, KeyEventHandler h) noexcept { ctx.keyEventHandler = h; } -KeyEventHandler keyEventHandler(Context &ctx) noexcept { +void setMouseButtonEventHandler(Context&, MouseButtonEventHandler) noexcept {} + +KeyEventHandler keyEventHandler(Context const &ctx) noexcept { return ctx.keyEventHandler; } diff --git a/src/olympic/turbine/src/glfw/context.hpp b/src/olympic/turbine/src/glfw/context.hpp index c526b6ba5..a9e1d318c 100644 --- a/src/olympic/turbine/src/glfw/context.hpp +++ b/src/olympic/turbine/src/glfw/context.hpp @@ -16,6 +16,7 @@ class Context { UpdateHandler updateHandler = [](Context&) -> int {return -1;}; keel::Context keelCtx; KeyEventHandler keyEventHandler = nullptr; + MouseButtonEventHandler mouseButtonEventHandler = nullptr; ox::AnyPtr applicationData; // GLFW impl data //////////////////////////////////////////////////////// diff --git a/src/olympic/turbine/src/glfw/turbine.cpp b/src/olympic/turbine/src/glfw/turbine.cpp index 5d740953e..716e70309 100644 --- a/src/olympic/turbine/src/glfw/turbine.cpp +++ b/src/olympic/turbine/src/glfw/turbine.cpp @@ -299,9 +299,14 @@ static void handleKeyPress(Context &ctx, int const key, bool const down) noexcep static void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept { } -static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept { +static void handleGlfwMouseButtonEvent( + GLFWwindow *window, + int const btn, + int const action, + int) noexcept { auto &ctx = *static_cast(glfwGetWindowUserPointer(window)); setMandatoryRefreshPeriod(ctx, ticksMs(ctx) + config::MandatoryRefreshPeriod); + ctx.mouseButtonEventHandler(ctx, btn, action == 1); } static void handleGlfwKeyEvent(GLFWwindow *window, int const key, int, int const action, int) noexcept { @@ -339,7 +344,8 @@ ox::Result> init( glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); constexpr auto Scale = 5; - ctx->window = glfwCreateWindow(240 * Scale, 160 * Scale, ctx->keelCtx.appName.c_str(), nullptr, nullptr); + ctx->window = glfwCreateWindow( + 240 * Scale, 160 * Scale, ctx->keelCtx.appName.c_str(), nullptr, nullptr); //ctx.window = glfwCreateWindow(876, 743, ctx.keelCtx.appName.c_str(), nullptr, nullptr); if (ctx->window == nullptr) { return ox::Error(1, "Could not open GLFW window"); @@ -447,15 +453,19 @@ void setShutdownHandler(Context &ctx, ShutdownHandler const handler) noexcept { ctx.shutdownHandler = handler; } -void setUpdateHandler(Context &ctx, UpdateHandler h) noexcept { +void setUpdateHandler(Context &ctx, UpdateHandler const h) noexcept { ctx.updateHandler = h; } -void setKeyEventHandler(Context &ctx, KeyEventHandler h) noexcept { +void setKeyEventHandler(Context &ctx, KeyEventHandler const h) noexcept { ctx.keyEventHandler = h; } -KeyEventHandler keyEventHandler(Context &ctx) noexcept { +void setMouseButtonEventHandler(Context &ctx, MouseButtonEventHandler const h) noexcept { + ctx.mouseButtonEventHandler = h; +} + +KeyEventHandler keyEventHandler(Context const &ctx) noexcept { return ctx.keyEventHandler; }