mirror of
https://github.com/glfw/glfw.git
synced 2024-11-10 00:51:47 +00:00
Cleanup
This commit is contained in:
parent
797ee8d8e3
commit
bda031f4ac
@ -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];
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
159
src/input.c
159
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;
|
||||
case GLFW_STICKY_KEYS:
|
||||
setStickyKeys(window, value ? GLFW_TRUE : GLFW_FALSE);
|
||||
break;
|
||||
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 (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:
|
||||
{
|
||||
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:
|
||||
{
|
||||
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)
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user