diff options
Diffstat (limited to 'src/game/client/io/mouse.cc')
| -rw-r--r-- | src/game/client/io/mouse.cc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/game/client/io/mouse.cc b/src/game/client/io/mouse.cc new file mode 100644 index 0000000..b79365c --- /dev/null +++ b/src/game/client/io/mouse.cc @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: BSD-2-Clause +// Copyright (c) 2025 Kirill Dmitrievich +// File: mouse.cc; Created: Tue Dec 30 2025 12:39:32 +// Description: Mouse and scroll wheel handling + +#include "client/pch.hh" + +#include "client/io/mouse.hh" + +#include "client/globals.hh" + +static void on_cursor_enter_glfw(GLFWwindow* window, int entered) +{ + ImGui_ImplGlfw_CursorEnterCallback(window, entered); +} +static void on_cursor_pos_glfw(GLFWwindow* window, double xpos, double ypos) +{ + globals::dispatcher.trigger(CursorPosEvent(xpos, ypos)); + + ImGui_ImplGlfw_CursorPosCallback(window, xpos, ypos); +} + +static void on_mouse_button_glfw(GLFWwindow* window, int button, int action, int modbits) +{ + globals::dispatcher.trigger(MouseButtonEvent(button, action, modbits)); + + ImGui_ImplGlfw_MouseButtonCallback(window, button, action, modbits); +} + +static void on_scroll_glfw(GLFWwindow* window, double xoffset, double yoffset) +{ + globals::dispatcher.trigger(ScrollEvent(xoffset, yoffset)); + + ImGui_ImplGlfw_ScrollCallback(window, xoffset, yoffset); +} + +void mouse::init(void) +{ + spdlog::info("mouse: taking over device events"); + glfwSetCursorEnterCallback(globals::window, &on_cursor_enter_glfw); + glfwSetCursorPosCallback(globals::window, &on_cursor_pos_glfw); + glfwSetMouseButtonCallback(globals::window, &on_mouse_button_glfw); + glfwSetScrollCallback(globals::window, &on_scroll_glfw); +} |
