From 6882dc84043f8d596665bfc6bde862b0c81b57a9 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 19 Jun 2021 11:19:44 -0500 Subject: [PATCH] [nostalglia/core/glfw] Cleanup event handling --- src/nostalgia/core/glfw/core.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/nostalgia/core/glfw/core.cpp b/src/nostalgia/core/glfw/core.cpp index 90508749..0157e4df 100644 --- a/src/nostalgia/core/glfw/core.cpp +++ b/src/nostalgia/core/glfw/core.cpp @@ -18,16 +18,25 @@ namespace nostalgia::core { void draw(Context *ctx) noexcept; +static void handleKeyPress(Context *ctx, int key) { + const auto id = ctx->windowerData(); + switch (key) { + case GLFW_KEY_ESCAPE: + case GLFW_KEY_Q: + id->running = false; + break; + default: + break; + } +} + static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) { const auto ctx = static_cast(glfwGetWindowUserPointer(window)); - const auto id = ctx->windowerData(); switch (action) { case GLFW_PRESS: - switch (key) { - case GLFW_KEY_Q: - id->running = false; - break; - } + handleKeyPress(ctx, key); + break; + default: break; } }