shithub: cstory

Download patch

ref: 878cac3b3fbad72266bb2b6e89409ea656ff2d6a
parent: 0c70b1ac31ba5f884976de5ec210576271f446dd
author: Clownacy <Clownacy@users.noreply.github.com>
date: Wed Apr 1 17:05:05 EDT 2020

Implement mouse-hiding in fullscreen

--- a/src/Backends/Platform.h
+++ b/src/Backends/Platform.h
@@ -8,6 +8,7 @@
 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);
--- a/src/Backends/Platform/GLFW3.cpp
+++ b/src/Backends/Platform/GLFW3.cpp
@@ -279,6 +279,11 @@
 	return FALSE;
 }
 
+void PlatformBackend_HideMouse(void)
+{
+	glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
+}
+
 BOOL PlatformBackend_SystemTask(void)
 {
 	if (glfwWindowShouldClose(window))
--- a/src/Backends/Platform/SDL2.cpp
+++ b/src/Backends/Platform/SDL2.cpp
@@ -64,6 +64,11 @@
 	return TRUE;
 }
 
+void PlatformBackend_HideMouse(void)
+{
+	SDL_ShowCursor(SDL_DISABLE);
+}
+
 BOOL PlatformBackend_SystemTask(void)
 {
 	while (SDL_PollEvent(NULL) || !bActive)
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -93,6 +93,7 @@
 	// 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 @@
 
 			bFullscreen = TRUE;
 
-			//SDL_ShowCursor(SDL_DISABLE);
+			PlatformBackend_HideMouse();
 			break;
 	}