From 878cac3b3fbad72266bb2b6e89409ea656ff2d6a Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 1 Apr 2020 21:05:05 +0100 Subject: [PATCH] Implement mouse-hiding in fullscreen --- src/Backends/Platform.h | 1 + src/Backends/Platform/GLFW3.cpp | 5 +++++ src/Backends/Platform/SDL2.cpp | 5 +++++ src/Main.cpp | 3 ++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Backends/Platform.h b/src/Backends/Platform.h index 64a96719..a71bff20 100644 --- a/src/Backends/Platform.h +++ b/src/Backends/Platform.h @@ -8,6 +8,7 @@ void PlatformBackend_Init(void); void PlatformBackend_Deinit(void); void PlatformBackend_PostWindowCreation(void); BOOL PlatformBackend_GetBasePath(char *string_buffer); +void PlatformBackend_HideMouse(void); BOOL PlatformBackend_SystemTask(void); void PlatformBackend_ShowMessageBox(const char *title, const char *message); unsigned long PlatformBackend_GetTicks(void); diff --git a/src/Backends/Platform/GLFW3.cpp b/src/Backends/Platform/GLFW3.cpp index ae3be315..b84f1315 100644 --- a/src/Backends/Platform/GLFW3.cpp +++ b/src/Backends/Platform/GLFW3.cpp @@ -279,6 +279,11 @@ BOOL PlatformBackend_GetBasePath(char *string_buffer) return FALSE; } +void PlatformBackend_HideMouse(void) +{ + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); +} + BOOL PlatformBackend_SystemTask(void) { if (glfwWindowShouldClose(window)) diff --git a/src/Backends/Platform/SDL2.cpp b/src/Backends/Platform/SDL2.cpp index 2e55511c..0b257b6c 100644 --- a/src/Backends/Platform/SDL2.cpp +++ b/src/Backends/Platform/SDL2.cpp @@ -64,6 +64,11 @@ BOOL PlatformBackend_GetBasePath(char *string_buffer) return TRUE; } +void PlatformBackend_HideMouse(void) +{ + SDL_ShowCursor(SDL_DISABLE); +} + BOOL PlatformBackend_SystemTask(void) { while (SDL_PollEvent(NULL) || !bActive) diff --git a/src/Main.cpp b/src/Main.cpp index 5d6e0698..fa34e8b0 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -93,6 +93,7 @@ int main(int argc, char *argv[]) // Get executable's path if (!PlatformBackend_GetBasePath(gModulePath)) { + // Fall back on argv[0] if the backend cannot provide a path strcpy(gModulePath, argv[0]); for (size_t i = strlen(gModulePath);; --i) @@ -269,7 +270,7 @@ int main(int argc, char *argv[]) bFullscreen = TRUE; - //SDL_ShowCursor(SDL_DISABLE); + PlatformBackend_HideMouse(); break; }