From 877557fff0a6e6dc15431619fecf128576143bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 15 Dec 2018 21:38:03 +0100 Subject: [PATCH] Platform: minor event cleanup in GlfwApplication. --- src/Magnum/Platform/GlfwApplication.cpp | 34 ++++++++++--------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/Magnum/Platform/GlfwApplication.cpp b/src/Magnum/Platform/GlfwApplication.cpp index 9bcec0af9..17c4de39d 100644 --- a/src/Magnum/Platform/GlfwApplication.cpp +++ b/src/Magnum/Platform/GlfwApplication.cpp @@ -464,50 +464,44 @@ void GlfwApplication::setupCallbacks() { static_cast(glfwGetWindowUserPointer(window))->viewportEvent(e); }); glfwSetKeyCallback(_window, [](GLFWwindow* const window, const int key, int, const int action, const int mods) { - const auto instance = static_cast(glfwGetWindowUserPointer(window)); + auto& app = *static_cast(glfwGetWindowUserPointer(window)); KeyEvent e(static_cast(key), {static_cast(mods)}, action == GLFW_REPEAT); - if(action == GLFW_PRESS) { - instance->keyPressEvent(e); - } else if(action == GLFW_RELEASE) { - instance->keyReleaseEvent(e); - } else if(action == GLFW_REPEAT) { - instance->keyPressEvent(e); - } + if(action == GLFW_PRESS || action == GLFW_REPEAT) + app.keyPressEvent(e); + else if(action == GLFW_RELEASE) + app.keyReleaseEvent(e); }); glfwSetMouseButtonCallback(_window, [](GLFWwindow* const window, const int button, const int action, const int mods) { - const auto instance = static_cast(glfwGetWindowUserPointer(window)); + auto& app = *static_cast(glfwGetWindowUserPointer(window)); double x, y; glfwGetCursorPos(window, &x, &y); MouseEvent e(static_cast(button), {Int(x), Int(y)}, {static_cast(mods)}); - if(action == GLFW_PRESS) { - instance->mousePressEvent(e); - } else if(action == GLFW_RELEASE) { - instance->mouseReleaseEvent(e); - } /* we don't handle GLFW_REPEAT */ + if(action == GLFW_PRESS) /* we don't handle GLFW_REPEAT */ + app.mousePressEvent(e); + else if(action == GLFW_RELEASE) + app.mouseReleaseEvent(e); }); glfwSetCursorPosCallback(_window, [](GLFWwindow* const window, const double x, const double y) { MouseMoveEvent e{window, Vector2i{Int(x), Int(y)}}; static_cast(glfwGetWindowUserPointer(window))->mouseMoveEvent(e); }); glfwSetScrollCallback(_window, [](GLFWwindow* window, double xoffset, double yoffset) { - const auto instance = static_cast(glfwGetWindowUserPointer(window)); - MouseScrollEvent e(window, Vector2{Float(xoffset), Float(yoffset)}); - instance->mouseScrollEvent(e); + static_cast(glfwGetWindowUserPointer(window))->mouseScrollEvent(e); }); glfwSetCharCallback(_window, [](GLFWwindow* window, unsigned int codepoint) { - const auto instance = static_cast(glfwGetWindowUserPointer(window)); + auto& app = *static_cast(glfwGetWindowUserPointer(window)); - if(!(instance->_flags & Flag::TextInputActive)) return; + if(!(app._flags & Flag::TextInputActive)) return; char utf8[4]; const std::size_t size = Utility::Unicode::utf8(codepoint, utf8); TextInputEvent e{{utf8, size}}; - instance->textInputEvent(e); + app.textInputEvent(e); }); }