@@ -24,7 +24,8 @@ m_width(width), m_height(height), m_title(title), m_eventManager(eventManager) {
2424 glfwSetFramebufferSizeCallback (m_window, framebufferResizeCallback);
2525
2626 glfwSetKeyCallback (m_window, keyCallback);
27- glfwSetCursorPosCallback (m_window, mouseButtonCallback);
27+ glfwSetCursorPosCallback (m_window, cursorPosCallback);
28+ glfwSetMouseButtonCallback (m_window, mouseButtonCallback);
2829 }
2930
3031 // The destructor cleans up GLFW resources.
@@ -83,9 +84,28 @@ m_width(width), m_height(height), m_title(title), m_eventManager(eventManager) {
8384 }
8485
8586 }
86- void Window::mouseButtonCallback (GLFWwindow *window, double xpos, double ypos) {
87+
88+ void Window::mouseButtonCallback (GLFWwindow *window, int button, int action, int mods) {
89+ auto * windowInstance = static_cast <Window*>(glfwGetWindowUserPointer (window));
90+ if (!windowInstance) return ;
91+
92+ Event event{};
93+ if (action == GLFW_PRESS) {
94+ event.type = EventType::MouseButtonPressed;
95+ event.mouseButton .button = button;
96+ windowInstance->m_eventManager .post (event);
97+ } else if (action == GLFW_RELEASE) {
98+ event.type = EventType::MouseButtonReleased;
99+ event.mouseButton .button = button;
100+ }
101+
102+ windowInstance->m_eventManager .post (event);
103+ }
104+
105+ void Window::cursorPosCallback (GLFWwindow *window, double xpos, double ypos) {
87106 auto * windowInstance = static_cast <Window*>(glfwGetWindowUserPointer (window));
88107 if (!windowInstance) return ;
108+
89109 Event event{};
90110 event.type = EventType::MouseMoved;
91111 event.mouseMove .x = xpos;
0 commit comments