Skip to content

Commit

Permalink
Implement mouse scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskr97 committed Oct 11, 2021
1 parent 0225970 commit 4109899
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Core/Platform/Window/GLFWWindowBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ namespace Core::Platform::Window {
INPUTFILTER->ButtonPressed(di);
});

// Mouse scroll callback
glfwSetScrollCallback(this->windowHandle, [](GLFWwindow* window, double xoffset, double yoffset){
auto time = std::chrono::steady_clock::now();
Locator::getLogger()->info("OFFSET: {} - {}", xoffset, yoffset);
if(!INPUTFILTER) return;

// Send desired output
INPUTFILTER->ButtonPressed(DeviceInput(DEVICE_MOUSE, MOUSE_WHEELUP, yoffset > 0 ? 1 : 0, time));
INPUTFILTER->ButtonPressed(DeviceInput(DEVICE_MOUSE, MOUSE_WHEELDOWN, yoffset > 0 ? 0 : 1, time));

// Reset immediately
INPUTFILTER->ButtonPressed(DeviceInput(DEVICE_MOUSE, MOUSE_WHEELUP, 0, time));
INPUTFILTER->ButtonPressed(DeviceInput(DEVICE_MOUSE, MOUSE_WHEELDOWN, 0, time));
});

// Window specific mouse position callback
glfwSetCursorPosCallback(this->windowHandle, [](GLFWwindow* window, double xpos, double ypos){
if(INPUTFILTER)
Expand Down

0 comments on commit 4109899

Please sign in to comment.