From bda031f4ac3c7d2a23f717652449c8c21c7d98fc Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 25 May 2016 14:43:51 +0200 Subject: [PATCH] Cleanup --- src/cocoa_window.m | 2 +- src/context.c | 4 +- src/egl_context.c | 4 +- src/glx_context.c | 4 +- src/input.c | 155 +++++++++++++++++++++------------------------ src/internal.h | 18 +++--- src/mir_window.c | 2 +- src/nsgl_context.m | 4 +- src/wgl_context.c | 4 +- src/win32_window.c | 6 +- src/window.c | 2 +- src/wl_window.c | 2 +- src/x11_window.c | 2 +- 13 files changed, 98 insertions(+), 111 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 76c17a2d..67174c48 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1066,7 +1066,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) releaseMonitor(window); if (window->context.client != GLFW_NO_API) - window->context.destroyContext(window); + window->context.destroy(window); [window->ns.object setDelegate:nil]; [window->ns.delegate release]; diff --git a/src/context.c b/src/context.c index 5f4a08c3..6722cfe2 100644 --- a/src/context.c +++ b/src/context.c @@ -576,11 +576,11 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle) if (previous) { if (!window || window->context.source != previous->context.source) - previous->context.makeContextCurrent(NULL); + previous->context.makeCurrent(NULL); } if (window) - window->context.makeContextCurrent(window); + window->context.makeCurrent(window); } GLFWAPI GLFWwindow* glfwGetCurrentContext(void) diff --git a/src/egl_context.c b/src/egl_context.c index 06203027..5dc3a8ad 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -613,12 +613,12 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, } } - window->context.makeContextCurrent = makeContextCurrent; + window->context.makeCurrent = makeContextCurrent; window->context.swapBuffers = swapBuffers; window->context.swapInterval = swapInterval; window->context.extensionSupported = extensionSupported; window->context.getProcAddress = getProcAddress; - window->context.destroyContext = destroyContext; + window->context.destroy = destroyContext; return GLFW_TRUE; } diff --git a/src/glx_context.c b/src/glx_context.c index 1760582b..76c67216 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -572,12 +572,12 @@ GLFWbool _glfwCreateContextGLX(_GLFWwindow* window, return GLFW_FALSE; } - window->context.makeContextCurrent = makeContextCurrent; + window->context.makeCurrent = makeContextCurrent; window->context.swapBuffers = swapBuffers; window->context.swapInterval = swapInterval; window->context.extensionSupported = extensionSupported; window->context.getProcAddress = getProcAddress; - window->context.destroyContext = destroyContext; + window->context.destroy = destroyContext; return GLFW_TRUE; } diff --git a/src/input.c b/src/input.c index 7109ee26..b38be87c 100644 --- a/src/input.c +++ b/src/input.c @@ -35,76 +35,6 @@ #define _GLFW_STICK 3 -// Sets the cursor mode for the specified window -// -static void setCursorMode(_GLFWwindow* window, int mode) -{ - if (mode != GLFW_CURSOR_NORMAL && - mode != GLFW_CURSOR_HIDDEN && - mode != GLFW_CURSOR_DISABLED) - { - _glfwInputError(GLFW_INVALID_ENUM, "Invalid cursor mode %i", mode); - return; - } - - if (window->cursorMode == mode) - return; - - _glfwPlatformGetCursorPos(window, - &window->virtualCursorPosX, - &window->virtualCursorPosY); - - if (_glfw.cursorWindow == window) - _glfwPlatformSetCursorMode(window, mode); - - window->cursorMode = mode; -} - -// Set sticky keys mode for the specified window -// -static void setStickyKeys(_GLFWwindow* window, int enabled) -{ - if (window->stickyKeys == enabled) - return; - - if (!enabled) - { - int i; - - // Release all sticky keys - for (i = 0; i <= GLFW_KEY_LAST; i++) - { - if (window->keys[i] == _GLFW_STICK) - window->keys[i] = GLFW_RELEASE; - } - } - - window->stickyKeys = enabled; -} - -// Set sticky mouse buttons mode for the specified window -// -static void setStickyMouseButtons(_GLFWwindow* window, int enabled) -{ - if (window->stickyMouseButtons == enabled) - return; - - if (!enabled) - { - int i; - - // Release all sticky mouse buttons - for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++) - { - if (window->mouseButtons[i] == _GLFW_STICK) - window->mouseButtons[i] = GLFW_RELEASE; - } - } - - window->stickyMouseButtons = enabled; -} - - ////////////////////////////////////////////////////////////////////////// ////// GLFW event API ////// ////////////////////////////////////////////////////////////////////////// @@ -170,16 +100,16 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods) window->callbacks.mouseButton((GLFWwindow*) window, button, action, mods); } -void _glfwInputCursorPos(_GLFWwindow* window, double x, double y) +void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos) { - if (window->virtualCursorPosX == x && window->virtualCursorPosY == y) + if (window->virtualCursorPosX == xpos && window->virtualCursorPosY == ypos) return; - window->virtualCursorPosX = x; - window->virtualCursorPosY = y; + window->virtualCursorPosX = xpos; + window->virtualCursorPosY = ypos; if (window->callbacks.cursorPos) - window->callbacks.cursorPos((GLFWwindow*) window, x, y); + window->callbacks.cursorPos((GLFWwindow*) window, xpos, ypos); } void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered) @@ -248,18 +178,75 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value) switch (mode) { case GLFW_CURSOR: - setCursorMode(window, value); - break; + { + if (value != GLFW_CURSOR_NORMAL && + value != GLFW_CURSOR_HIDDEN && + value != GLFW_CURSOR_DISABLED) + { + _glfwInputError(GLFW_INVALID_ENUM, + "Invalid cursor mode %i", + value); + return; + } + + if (window->cursorMode == value) + return; + + _glfwPlatformGetCursorPos(window, + &window->virtualCursorPosX, + &window->virtualCursorPosY); + + if (_glfw.cursorWindow == window) + _glfwPlatformSetCursorMode(window, value); + + window->cursorMode = value; + return; + } + case GLFW_STICKY_KEYS: - setStickyKeys(window, value ? GLFW_TRUE : GLFW_FALSE); - break; + { + if (window->stickyKeys == value) + return; + + if (!value) + { + int i; + + // Release all sticky keys + for (i = 0; i <= GLFW_KEY_LAST; i++) + { + if (window->keys[i] == _GLFW_STICK) + window->keys[i] = GLFW_RELEASE; + } + } + + window->stickyKeys = value ? GLFW_TRUE : GLFW_FALSE; + return; + } + case GLFW_STICKY_MOUSE_BUTTONS: - setStickyMouseButtons(window, value ? GLFW_TRUE : GLFW_FALSE); - break; - default: - _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode %i", mode); - break; + { + if (window->stickyMouseButtons == value) + return; + + if (!value) + { + int i; + + // Release all sticky mouse buttons + for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++) + { + if (window->mouseButtons[i] == _GLFW_STICK) + window->mouseButtons[i] = GLFW_RELEASE; + } + } + + window->stickyMouseButtons = value ? GLFW_TRUE : GLFW_FALSE; + return; + } } + + _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode %i", mode); } GLFWAPI const char* glfwGetKeyName(int key, int scancode) diff --git a/src/internal.h b/src/internal.h index 32418649..de813e0e 100644 --- a/src/internal.h +++ b/src/internal.h @@ -324,12 +324,12 @@ struct _GLFWcontext PFNGLGETINTEGERVPROC GetIntegerv; PFNGLGETSTRINGPROC GetString; - _GLFWmakecontextcurrentfun makeContextCurrent; + _GLFWmakecontextcurrentfun makeCurrent; _GLFWswapbuffersfun swapBuffers; _GLFWswapintervalfun swapInterval; _GLFWextensionsupportedfun extensionSupported; _GLFWgetprocaddressfun getProcAddress; - _GLFWdestroycontextfun destroyContext; + _GLFWdestroycontextfun destroy; // This is defined in the context API's context.h _GLFW_PLATFORM_CONTEXT_STATE; @@ -881,11 +881,11 @@ void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods, GLFWb /*! @brief Notifies shared code of a scroll event. * @param[in] window The window that received the event. - * @param[in] x The scroll offset along the x-axis. - * @param[in] y The scroll offset along the y-axis. + * @param[in] xoffset The scroll offset along the x-axis. + * @param[in] yoffset The scroll offset along the y-axis. * @ingroup event */ -void _glfwInputScroll(_GLFWwindow* window, double x, double y); +void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset); /*! @brief Notifies shared code of a mouse button click event. * @param[in] window The window that received the event. @@ -897,13 +897,13 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods) /*! @brief Notifies shared code of a cursor motion event. * @param[in] window The window that received the event. - * @param[in] x The new x-coordinate of the cursor, relative to the left edge - * of the client area of the window. - * @param[in] y The new y-coordinate of the cursor, relative to the top edge + * @param[in] xpos The new x-coordinate of the cursor, relative to the left + * edge of the client area of the window. + * @param[in] ypos The new y-coordinate of the cursor, relative to the top edge * of the client area of the window. * @ingroup event */ -void _glfwInputCursorPos(_GLFWwindow* window, double x, double y); +void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos); /*! @brief Notifies shared code of a cursor enter/leave event. * @param[in] window The window that received the event. diff --git a/src/mir_window.c b/src/mir_window.c index 57b13865..b9b5752b 100644 --- a/src/mir_window.c +++ b/src/mir_window.c @@ -395,7 +395,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) } if (window->context.client != GLFW_NO_API) - window->context.destroyContext(window); + window->context.destroy(window); } void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) diff --git a/src/nsgl_context.m b/src/nsgl_context.m index 1b515cb3..b58e4d73 100644 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -274,12 +274,12 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, [window->context.nsgl.object setView:window->ns.view]; - window->context.makeContextCurrent = makeContextCurrent; + window->context.makeCurrent = makeContextCurrent; window->context.swapBuffers = swapBuffers; window->context.swapInterval = swapInterval; window->context.extensionSupported = extensionSupported; window->context.getProcAddress = getProcAddress; - window->context.destroyContext = destroyContext; + window->context.destroy = destroyContext; return GLFW_TRUE; } diff --git a/src/wgl_context.c b/src/wgl_context.c index 55399cb1..92042935 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -576,12 +576,12 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, } } - window->context.makeContextCurrent = makeContextCurrent; + window->context.makeCurrent = makeContextCurrent; window->context.swapBuffers = swapBuffers; window->context.swapInterval = swapInterval; window->context.extensionSupported = extensionSupported; window->context.getProcAddress = getProcAddress; - window->context.destroyContext = destroyContext; + window->context.destroy = destroyContext; return GLFW_TRUE; } diff --git a/src/win32_window.c b/src/win32_window.c index 43c793d5..dbe374c1 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1029,11 +1029,11 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, // First we clear the current context (the one we just created) // This is usually done by glfwDestroyWindow, but as we're not doing // full GLFW window destruction, it's duplicated here - window->context.makeContextCurrent(NULL); + window->context.makeCurrent(NULL); // Next destroy the Win32 window and WGL context (without resetting // or destroying the GLFW window object) - window->context.destroyContext(window); + window->context.destroy(window); destroyWindow(window); // ...and then create them again, this time with better APIs @@ -1069,7 +1069,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) releaseMonitor(window); if (window->context.client != GLFW_NO_API) - window->context.destroyContext(window); + window->context.destroy(window); destroyWindow(window); diff --git a/src/window.c b/src/window.c index f6dc2c78..ed0a22d6 100644 --- a/src/window.c +++ b/src/window.c @@ -205,7 +205,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, if (ctxconfig.client != GLFW_NO_API) { - window->context.makeContextCurrent(window); + window->context.makeCurrent(window); // Retrieve the actual (as opposed to requested) context attributes if (!_glfwRefreshContextAttribs(&ctxconfig)) diff --git a/src/wl_window.c b/src/wl_window.c index b889f927..04cbd997 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -436,7 +436,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) } if (window->context.client != GLFW_NO_API) - window->context.destroyContext(window); + window->context.destroy(window); if (window->wl.native) wl_egl_window_destroy(window->wl.native); diff --git a/src/x11_window.c b/src/x11_window.c index 36e16730..34fb1819 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1548,7 +1548,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) } if (window->context.client != GLFW_NO_API) - window->context.destroyContext(window); + window->context.destroy(window); if (window->x11.handle) {