[studio,turbine] Add support for mouse back/forward buttons
All checks were successful
Build / build (push) Successful in 1m30s
All checks were successful
Build / build (push) Successful in 1m30s
This commit is contained in:
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 ////////////////////////////////////////////////////////
|
||||
|
@ -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<Context*>(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<ox::UPtr<Context>> 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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user