From 50ba9d9f68517d9e5074cfddce311c5ed5337964 Mon Sep 17 00:00:00 2001 From: iamCaveLamp Date: Mon, 24 Dec 2018 22:24:51 +0200 Subject: [PATCH] Removed duplicates of centerCursor function --- src/cocoa_window.m | 17 ++++------------- src/internal.h | 1 + src/win32_window.c | 11 +---------- src/window.c | 13 ++++++++----- src/x11_window.c | 11 +---------- 5 files changed, 15 insertions(+), 38 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 9c018eb8b..726fea08b 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -71,15 +71,6 @@ static NSUInteger getStyleMask(_GLFWwindow* window) return styleMask; } -// Center the cursor in the view of the window -// -static void centerCursor(_GLFWwindow *window) -{ - int width, height; - _glfwPlatformGetWindowSize(window, &width, &height); - _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); -} - // Returns whether the cursor is in the client area of the specified window // static GLFWbool cursorInClientArea(_GLFWwindow* window) @@ -137,7 +128,7 @@ static void updateCursorMode(_GLFWwindow* window) _glfwPlatformGetCursorPos(window, &_glfw.ns.restoreCursorPosX, &_glfw.ns.restoreCursorPosY); - centerCursor(window); + _glfwPlatformCenterCursor(window); CGAssociateMouseAndMouseCursorPosition(false); } else if (_glfw.ns.disabledCursorWindow == window) @@ -282,7 +273,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; [window->context.nsgl.object update]; if (_glfw.ns.disabledCursorWindow == window) - centerCursor(window); + _glfwPlatformCenterCursor(window); const int maximized = [window->ns.object isZoomed]; if (window->ns.maximized != maximized) @@ -317,7 +308,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; [window->context.nsgl.object update]; if (_glfw.ns.disabledCursorWindow == window) - centerCursor(window); + _glfwPlatformCenterCursor(window); int x, y; _glfwPlatformGetWindowPos(window, &x, &y); @@ -343,7 +334,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; - (void)windowDidBecomeKey:(NSNotification *)notification { if (_glfw.ns.disabledCursorWindow == window) - centerCursor(window); + _glfwPlatformCenterCursor(window); _glfwInputWindowFocus(window, GLFW_TRUE); updateCursorMode(window); diff --git a/src/internal.h b/src/internal.h index 7be2b267c..81487e14a 100644 --- a/src/internal.h +++ b/src/internal.h @@ -601,6 +601,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor, int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape); void _glfwPlatformDestroyCursor(_GLFWcursor* cursor); void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor); +void _glfwPlatformCenterCursor(_GLFWwindow* window); const char* _glfwPlatformGetScancodeName(int scancode); int _glfwPlatformGetKeyScancode(int key); diff --git a/src/win32_window.c b/src/win32_window.c index 796ae150e..326c81aa0 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -236,15 +236,6 @@ static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area) } } -// Centers the cursor over the window client area -// -static void centerCursor(_GLFWwindow* window) -{ - int width, height; - _glfwPlatformGetWindowSize(window, &width, &height); - _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); -} - // Updates the cursor image according to its cursor mode // static void updateCursorImage(_GLFWwindow* window) @@ -287,7 +278,7 @@ static void disableCursor(_GLFWwindow* window) &_glfw.win32.restoreCursorPosX, &_glfw.win32.restoreCursorPosY); updateCursorImage(window); - centerCursor(window); + _glfwPlatformCenterCursor(window); updateClipRect(window); if (!RegisterRawInputDevices(&rid, 1, sizeof(rid))) diff --git a/src/window.c b/src/window.c index 4e365cb47..dbccceeb4 100644 --- a/src/window.c +++ b/src/window.c @@ -143,6 +143,13 @@ void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor) window->monitor = monitor; } +void _glfwPlatformCenterCursor(_GLFWwindow* window) +{ + int width, height; + + _glfwPlatformGetWindowSize(window, &width, &height); + _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); +} ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// @@ -230,11 +237,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, if (window->monitor) { if (wndconfig.centerCursor) - { - int width, height; - _glfwPlatformGetWindowSize(window, &width, &height); - _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); - } + _glfwPlatformCenterCursor(window); } else { diff --git a/src/x11_window.c b/src/x11_window.c index 5e9161072..483efb24b 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -501,15 +501,6 @@ static char* convertLatin1toUTF8(const char* source) return target; } -// Centers the cursor over the window client area -// -static void centerCursor(_GLFWwindow* window) -{ - int width, height; - _glfwPlatformGetWindowSize(window, &width, &height); - _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); -} - // Updates the cursor image according to its cursor mode // static void updateCursorImage(_GLFWwindow* window) @@ -553,7 +544,7 @@ static void disableCursor(_GLFWwindow* window) &_glfw.x11.restoreCursorPosX, &_glfw.x11.restoreCursorPosY); updateCursorImage(window); - centerCursor(window); + _glfwPlatformCenterCursor(window); XGrabPointer(_glfw.x11.display, window->x11.handle, True, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, GrabModeAsync, GrabModeAsync,