[nostalgia/core/glfw] Fix keyboard support for ImGui

This commit is contained in:
2022-02-01 02:15:49 -06:00
parent 87c03c0d98
commit 0d76129a0e
2 changed files with 20 additions and 20 deletions
+20 -1
View File
@@ -15,7 +15,7 @@ namespace nostalgia::core {
constexpr auto Scale = 5;
static void handleGlfwError(int err, const char *desc) {
static void handleGlfwError(int err, const char *desc) noexcept {
oxErrf("GLFW error ({}): {}\n", err, desc);
}
@@ -23,6 +23,24 @@ void ImGui_Impl_NewFrame() noexcept {
ImGui_ImplGlfw_NewFrame();
}
static void handleKeyPress(Context *ctx, int key) noexcept {
switch (key) {
case GLFW_KEY_ESCAPE:
case GLFW_KEY_Q:
shutdown(ctx);
break;
default:
break;
}
}
static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept {
const auto ctx = static_cast<Context *>(glfwGetWindowUserPointer(window));
if (action == GLFW_PRESS) {
handleKeyPress(ctx, key);
}
}
ox::Error initGfx(Context *ctx) noexcept {
auto id = ctx->windowerData<GlfwImplData>();
glfwSetErrorCallback(handleGlfwError);
@@ -37,6 +55,7 @@ ox::Error initGfx(Context *ctx) noexcept {
if (id->window == nullptr) {
return OxError(1, "Could not open GLFW window");
}
glfwSetKeyCallback(id->window, handleGlfwKeyEvent);
glfwSetWindowUserPointer(id->window, ctx);
glfwMakeContextCurrent(id->window);
if constexpr(config::ImGuiEnabled) {