mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-23 02:38:52 -05:00
Put window callbacks in a substruct.
This commit is contained in:
parent
cb8c7740e6
commit
8d60214fac
40
src/input.c
40
src/input.c
|
@ -146,8 +146,8 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
|||
}
|
||||
|
||||
// Call user callback function
|
||||
if (window->keyCallback && !repeated)
|
||||
window->keyCallback((GLFWwindow*) window, key, action);
|
||||
if (window->callbacks.key && !repeated)
|
||||
window->callbacks.key((GLFWwindow*) window, key, action);
|
||||
}
|
||||
|
||||
|
||||
|
@ -161,8 +161,8 @@ void _glfwInputChar(_GLFWwindow* window, int character)
|
|||
if (!((character >= 32 && character <= 126) || character >= 160))
|
||||
return;
|
||||
|
||||
if (window->charCallback)
|
||||
window->charCallback((GLFWwindow*) window, character);
|
||||
if (window->callbacks.character)
|
||||
window->callbacks.character((GLFWwindow*) window, character);
|
||||
}
|
||||
|
||||
|
||||
|
@ -175,8 +175,8 @@ void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)
|
|||
window->scrollX += xoffset;
|
||||
window->scrollY += yoffset;
|
||||
|
||||
if (window->scrollCallback)
|
||||
window->scrollCallback((GLFWwindow*) window, xoffset, yoffset);
|
||||
if (window->callbacks.scroll)
|
||||
window->callbacks.scroll((GLFWwindow*) window, xoffset, yoffset);
|
||||
}
|
||||
|
||||
|
||||
|
@ -195,8 +195,8 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
|
|||
else
|
||||
window->mouseButton[button] = (char) action;
|
||||
|
||||
if (window->mouseButtonCallback)
|
||||
window->mouseButtonCallback((GLFWwindow*) window, button, action);
|
||||
if (window->callbacks.mouseButton)
|
||||
window->callbacks.mouseButton((GLFWwindow*) window, button, action);
|
||||
}
|
||||
|
||||
|
||||
|
@ -223,11 +223,11 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
|
|||
window->cursorPosY = y;
|
||||
}
|
||||
|
||||
if (window->cursorPosCallback)
|
||||
if (window->callbacks.cursorPos)
|
||||
{
|
||||
window->cursorPosCallback((GLFWwindow*) window,
|
||||
window->cursorPosX,
|
||||
window->cursorPosY);
|
||||
window->callbacks.cursorPos((GLFWwindow*) window,
|
||||
window->cursorPosX,
|
||||
window->cursorPosY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,8 +238,8 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
|
|||
|
||||
void _glfwInputCursorEnter(_GLFWwindow* window, int entered)
|
||||
{
|
||||
if (window->cursorEnterCallback)
|
||||
window->cursorEnterCallback((GLFWwindow*) window, entered);
|
||||
if (window->callbacks.cursorEnter)
|
||||
window->callbacks.cursorEnter((GLFWwindow*) window, entered);
|
||||
}
|
||||
|
||||
|
||||
|
@ -464,7 +464,7 @@ GLFWAPI void glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun)
|
|||
return;
|
||||
}
|
||||
|
||||
window->keyCallback = cbfun;
|
||||
window->callbacks.key = cbfun;
|
||||
}
|
||||
|
||||
|
||||
|
@ -482,7 +482,7 @@ GLFWAPI void glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun)
|
|||
return;
|
||||
}
|
||||
|
||||
window->charCallback = cbfun;
|
||||
window->callbacks.character = cbfun;
|
||||
}
|
||||
|
||||
|
||||
|
@ -500,7 +500,7 @@ GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow* handle, GLFWmousebuttonfun c
|
|||
return;
|
||||
}
|
||||
|
||||
window->mouseButtonCallback = cbfun;
|
||||
window->callbacks.mouseButton = cbfun;
|
||||
}
|
||||
|
||||
|
||||
|
@ -518,7 +518,7 @@ GLFWAPI void glfwSetCursorPosCallback(GLFWwindow* handle, GLFWcursorposfun cbfun
|
|||
return;
|
||||
}
|
||||
|
||||
window->cursorPosCallback = cbfun;
|
||||
window->callbacks.cursorPos = cbfun;
|
||||
}
|
||||
|
||||
|
||||
|
@ -536,7 +536,7 @@ GLFWAPI void glfwSetCursorEnterCallback(GLFWwindow* handle, GLFWcursorenterfun c
|
|||
return;
|
||||
}
|
||||
|
||||
window->cursorEnterCallback = cbfun;
|
||||
window->callbacks.cursorEnter = cbfun;
|
||||
}
|
||||
|
||||
|
||||
|
@ -554,6 +554,6 @@ GLFWAPI void glfwSetScrollCallback(GLFWwindow* handle, GLFWscrollfun cbfun)
|
|||
return;
|
||||
}
|
||||
|
||||
window->scrollCallback = cbfun;
|
||||
window->callbacks.scroll = cbfun;
|
||||
}
|
||||
|
||||
|
|
|
@ -235,18 +235,20 @@ struct _GLFWwindow
|
|||
PFNGLGETSTRINGIPROC GetStringi;
|
||||
#endif
|
||||
|
||||
GLFWwindowposfun windowPosCallback;
|
||||
GLFWwindowsizefun windowSizeCallback;
|
||||
GLFWwindowclosefun windowCloseCallback;
|
||||
GLFWwindowrefreshfun windowRefreshCallback;
|
||||
GLFWwindowfocusfun windowFocusCallback;
|
||||
GLFWwindowiconifyfun windowIconifyCallback;
|
||||
GLFWmousebuttonfun mouseButtonCallback;
|
||||
GLFWcursorposfun cursorPosCallback;
|
||||
GLFWcursorenterfun cursorEnterCallback;
|
||||
GLFWscrollfun scrollCallback;
|
||||
GLFWkeyfun keyCallback;
|
||||
GLFWcharfun charCallback;
|
||||
struct {
|
||||
GLFWwindowposfun pos;
|
||||
GLFWwindowsizefun size;
|
||||
GLFWwindowclosefun close;
|
||||
GLFWwindowrefreshfun refresh;
|
||||
GLFWwindowfocusfun focus;
|
||||
GLFWwindowiconifyfun iconify;
|
||||
GLFWmousebuttonfun mouseButton;
|
||||
GLFWcursorposfun cursorPos;
|
||||
GLFWcursorenterfun cursorEnter;
|
||||
GLFWscrollfun scroll;
|
||||
GLFWkeyfun key;
|
||||
GLFWcharfun character;
|
||||
} callbacks;
|
||||
|
||||
// This is defined in the window API's platform.h
|
||||
_GLFW_PLATFORM_WINDOW_STATE;
|
||||
|
|
53
src/window.c
53
src/window.c
|
@ -80,8 +80,8 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
|
|||
{
|
||||
_glfw.focusedWindow = window;
|
||||
|
||||
if (window->windowFocusCallback)
|
||||
window->windowFocusCallback((GLFWwindow*) window, focused);
|
||||
if (window->callbacks.focus)
|
||||
window->callbacks.focus((GLFWwindow*) window, focused);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -106,8 +106,8 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
|
|||
|
||||
_glfw.focusedWindow = NULL;
|
||||
|
||||
if (window->windowFocusCallback)
|
||||
window->windowFocusCallback((GLFWwindow*) window, focused);
|
||||
if (window->callbacks.focus)
|
||||
window->callbacks.focus((GLFWwindow*) window, focused);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,8 +125,8 @@ void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
|
|||
window->positionX = x;
|
||||
window->positionY = y;
|
||||
|
||||
if (window->windowPosCallback)
|
||||
window->windowPosCallback((GLFWwindow*) window, x, y);
|
||||
if (window->callbacks.pos)
|
||||
window->callbacks.pos((GLFWwindow*) window, x, y);
|
||||
}
|
||||
|
||||
|
||||
|
@ -142,8 +142,8 @@ void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
|
|||
window->width = width;
|
||||
window->height = height;
|
||||
|
||||
if (window->windowSizeCallback)
|
||||
window->windowSizeCallback((GLFWwindow*) window, width, height);
|
||||
if (window->callbacks.size)
|
||||
window->callbacks.size((GLFWwindow*) window, width, height);
|
||||
}
|
||||
|
||||
|
||||
|
@ -158,8 +158,8 @@ void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
|
|||
|
||||
window->iconified = iconified;
|
||||
|
||||
if (window->windowIconifyCallback)
|
||||
window->windowIconifyCallback((GLFWwindow*) window, iconified);
|
||||
if (window->callbacks.iconify)
|
||||
window->callbacks.iconify((GLFWwindow*) window, iconified);
|
||||
}
|
||||
|
||||
|
||||
|
@ -179,8 +179,8 @@ void _glfwInputWindowVisibility(_GLFWwindow* window, int visible)
|
|||
|
||||
void _glfwInputWindowDamage(_GLFWwindow* window)
|
||||
{
|
||||
if (window->windowRefreshCallback)
|
||||
window->windowRefreshCallback((GLFWwindow*) window);
|
||||
if (window->callbacks.refresh)
|
||||
window->callbacks.refresh((GLFWwindow*) window);
|
||||
}
|
||||
|
||||
|
||||
|
@ -190,8 +190,8 @@ void _glfwInputWindowDamage(_GLFWwindow* window)
|
|||
|
||||
void _glfwInputWindowCloseRequest(_GLFWwindow* window)
|
||||
{
|
||||
if (window->windowCloseCallback)
|
||||
window->closeRequested = window->windowCloseCallback((GLFWwindow*) window);
|
||||
if (window->callbacks.close)
|
||||
window->closeRequested = window->callbacks.close((GLFWwindow*) window);
|
||||
else
|
||||
window->closeRequested = GL_TRUE;
|
||||
}
|
||||
|
@ -489,18 +489,7 @@ GLFWAPI void glfwDestroyWindow(GLFWwindow* handle)
|
|||
return;
|
||||
|
||||
// Clear all callbacks to avoid exposing a half torn-down window object
|
||||
window->windowPosCallback = NULL;
|
||||
window->windowSizeCallback = NULL;
|
||||
window->windowCloseCallback = NULL;
|
||||
window->windowRefreshCallback = NULL;
|
||||
window->windowFocusCallback = NULL;
|
||||
window->windowIconifyCallback = NULL;
|
||||
window->mouseButtonCallback = NULL;
|
||||
window->cursorPosCallback = NULL;
|
||||
window->cursorEnterCallback = NULL;
|
||||
window->scrollCallback = NULL;
|
||||
window->keyCallback = NULL;
|
||||
window->charCallback = NULL;
|
||||
memset(&window->callbacks, 0, sizeof(window->callbacks));
|
||||
|
||||
// The window's context must not be current on another thread when the
|
||||
// window is destroyed
|
||||
|
@ -800,7 +789,7 @@ GLFWAPI void glfwSetWindowPosCallback(GLFWwindow* handle, GLFWwindowposfun cbfun
|
|||
return;
|
||||
}
|
||||
|
||||
window->windowPosCallback = cbfun;
|
||||
window->callbacks.pos = cbfun;
|
||||
}
|
||||
|
||||
|
||||
|
@ -818,7 +807,7 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow* handle, GLFWwindowsizefun cbf
|
|||
return;
|
||||
}
|
||||
|
||||
window->windowSizeCallback = cbfun;
|
||||
window->callbacks.size = cbfun;
|
||||
}
|
||||
|
||||
|
||||
|
@ -836,7 +825,7 @@ GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow* handle, GLFWwindowclosefun c
|
|||
return;
|
||||
}
|
||||
|
||||
window->windowCloseCallback = cbfun;
|
||||
window->callbacks.close = cbfun;
|
||||
}
|
||||
|
||||
|
||||
|
@ -854,7 +843,7 @@ GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow* handle, GLFWwindowrefreshf
|
|||
return;
|
||||
}
|
||||
|
||||
window->windowRefreshCallback = cbfun;
|
||||
window->callbacks.refresh = cbfun;
|
||||
}
|
||||
|
||||
|
||||
|
@ -872,7 +861,7 @@ GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow* handle, GLFWwindowfocusfun c
|
|||
return;
|
||||
}
|
||||
|
||||
window->windowFocusCallback = cbfun;
|
||||
window->callbacks.focus = cbfun;
|
||||
}
|
||||
|
||||
|
||||
|
@ -890,7 +879,7 @@ GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow* handle, GLFWwindowiconifyf
|
|||
return;
|
||||
}
|
||||
|
||||
window->windowIconifyCallback = cbfun;
|
||||
window->callbacks.iconify = cbfun;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user