1
0
Fork 0
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:
Camilla Berglund 2013-01-15 21:34:26 +01:00
parent cb8c7740e6
commit 8d60214fac
3 changed files with 55 additions and 64 deletions

View File

@ -146,8 +146,8 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
} }
// Call user callback function // Call user callback function
if (window->keyCallback && !repeated) if (window->callbacks.key && !repeated)
window->keyCallback((GLFWwindow*) window, key, action); window->callbacks.key((GLFWwindow*) window, key, action);
} }
@ -161,8 +161,8 @@ void _glfwInputChar(_GLFWwindow* window, int character)
if (!((character >= 32 && character <= 126) || character >= 160)) if (!((character >= 32 && character <= 126) || character >= 160))
return; return;
if (window->charCallback) if (window->callbacks.character)
window->charCallback((GLFWwindow*) window, character); window->callbacks.character((GLFWwindow*) window, character);
} }
@ -175,8 +175,8 @@ void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)
window->scrollX += xoffset; window->scrollX += xoffset;
window->scrollY += yoffset; window->scrollY += yoffset;
if (window->scrollCallback) if (window->callbacks.scroll)
window->scrollCallback((GLFWwindow*) window, xoffset, yoffset); window->callbacks.scroll((GLFWwindow*) window, xoffset, yoffset);
} }
@ -195,8 +195,8 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
else else
window->mouseButton[button] = (char) action; window->mouseButton[button] = (char) action;
if (window->mouseButtonCallback) if (window->callbacks.mouseButton)
window->mouseButtonCallback((GLFWwindow*) window, button, action); window->callbacks.mouseButton((GLFWwindow*) window, button, action);
} }
@ -223,11 +223,11 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
window->cursorPosY = y; window->cursorPosY = y;
} }
if (window->cursorPosCallback) if (window->callbacks.cursorPos)
{ {
window->cursorPosCallback((GLFWwindow*) window, window->callbacks.cursorPos((GLFWwindow*) window,
window->cursorPosX, window->cursorPosX,
window->cursorPosY); window->cursorPosY);
} }
} }
@ -238,8 +238,8 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
void _glfwInputCursorEnter(_GLFWwindow* window, int entered) void _glfwInputCursorEnter(_GLFWwindow* window, int entered)
{ {
if (window->cursorEnterCallback) if (window->callbacks.cursorEnter)
window->cursorEnterCallback((GLFWwindow*) window, entered); window->callbacks.cursorEnter((GLFWwindow*) window, entered);
} }
@ -464,7 +464,7 @@ GLFWAPI void glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun)
return; return;
} }
window->keyCallback = cbfun; window->callbacks.key = cbfun;
} }
@ -482,7 +482,7 @@ GLFWAPI void glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun)
return; return;
} }
window->charCallback = cbfun; window->callbacks.character = cbfun;
} }
@ -500,7 +500,7 @@ GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow* handle, GLFWmousebuttonfun c
return; return;
} }
window->mouseButtonCallback = cbfun; window->callbacks.mouseButton = cbfun;
} }
@ -518,7 +518,7 @@ GLFWAPI void glfwSetCursorPosCallback(GLFWwindow* handle, GLFWcursorposfun cbfun
return; return;
} }
window->cursorPosCallback = cbfun; window->callbacks.cursorPos = cbfun;
} }
@ -536,7 +536,7 @@ GLFWAPI void glfwSetCursorEnterCallback(GLFWwindow* handle, GLFWcursorenterfun c
return; return;
} }
window->cursorEnterCallback = cbfun; window->callbacks.cursorEnter = cbfun;
} }
@ -554,6 +554,6 @@ GLFWAPI void glfwSetScrollCallback(GLFWwindow* handle, GLFWscrollfun cbfun)
return; return;
} }
window->scrollCallback = cbfun; window->callbacks.scroll = cbfun;
} }

View File

@ -235,18 +235,20 @@ struct _GLFWwindow
PFNGLGETSTRINGIPROC GetStringi; PFNGLGETSTRINGIPROC GetStringi;
#endif #endif
GLFWwindowposfun windowPosCallback; struct {
GLFWwindowsizefun windowSizeCallback; GLFWwindowposfun pos;
GLFWwindowclosefun windowCloseCallback; GLFWwindowsizefun size;
GLFWwindowrefreshfun windowRefreshCallback; GLFWwindowclosefun close;
GLFWwindowfocusfun windowFocusCallback; GLFWwindowrefreshfun refresh;
GLFWwindowiconifyfun windowIconifyCallback; GLFWwindowfocusfun focus;
GLFWmousebuttonfun mouseButtonCallback; GLFWwindowiconifyfun iconify;
GLFWcursorposfun cursorPosCallback; GLFWmousebuttonfun mouseButton;
GLFWcursorenterfun cursorEnterCallback; GLFWcursorposfun cursorPos;
GLFWscrollfun scrollCallback; GLFWcursorenterfun cursorEnter;
GLFWkeyfun keyCallback; GLFWscrollfun scroll;
GLFWcharfun charCallback; GLFWkeyfun key;
GLFWcharfun character;
} callbacks;
// This is defined in the window API's platform.h // This is defined in the window API's platform.h
_GLFW_PLATFORM_WINDOW_STATE; _GLFW_PLATFORM_WINDOW_STATE;

View File

@ -80,8 +80,8 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
{ {
_glfw.focusedWindow = window; _glfw.focusedWindow = window;
if (window->windowFocusCallback) if (window->callbacks.focus)
window->windowFocusCallback((GLFWwindow*) window, focused); window->callbacks.focus((GLFWwindow*) window, focused);
} }
} }
else else
@ -106,8 +106,8 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
_glfw.focusedWindow = NULL; _glfw.focusedWindow = NULL;
if (window->windowFocusCallback) if (window->callbacks.focus)
window->windowFocusCallback((GLFWwindow*) window, focused); window->callbacks.focus((GLFWwindow*) window, focused);
} }
} }
} }
@ -125,8 +125,8 @@ void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
window->positionX = x; window->positionX = x;
window->positionY = y; window->positionY = y;
if (window->windowPosCallback) if (window->callbacks.pos)
window->windowPosCallback((GLFWwindow*) window, x, y); window->callbacks.pos((GLFWwindow*) window, x, y);
} }
@ -142,8 +142,8 @@ void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
window->width = width; window->width = width;
window->height = height; window->height = height;
if (window->windowSizeCallback) if (window->callbacks.size)
window->windowSizeCallback((GLFWwindow*) window, width, height); window->callbacks.size((GLFWwindow*) window, width, height);
} }
@ -158,8 +158,8 @@ void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
window->iconified = iconified; window->iconified = iconified;
if (window->windowIconifyCallback) if (window->callbacks.iconify)
window->windowIconifyCallback((GLFWwindow*) window, iconified); window->callbacks.iconify((GLFWwindow*) window, iconified);
} }
@ -179,8 +179,8 @@ void _glfwInputWindowVisibility(_GLFWwindow* window, int visible)
void _glfwInputWindowDamage(_GLFWwindow* window) void _glfwInputWindowDamage(_GLFWwindow* window)
{ {
if (window->windowRefreshCallback) if (window->callbacks.refresh)
window->windowRefreshCallback((GLFWwindow*) window); window->callbacks.refresh((GLFWwindow*) window);
} }
@ -190,8 +190,8 @@ void _glfwInputWindowDamage(_GLFWwindow* window)
void _glfwInputWindowCloseRequest(_GLFWwindow* window) void _glfwInputWindowCloseRequest(_GLFWwindow* window)
{ {
if (window->windowCloseCallback) if (window->callbacks.close)
window->closeRequested = window->windowCloseCallback((GLFWwindow*) window); window->closeRequested = window->callbacks.close((GLFWwindow*) window);
else else
window->closeRequested = GL_TRUE; window->closeRequested = GL_TRUE;
} }
@ -489,18 +489,7 @@ GLFWAPI void glfwDestroyWindow(GLFWwindow* handle)
return; return;
// Clear all callbacks to avoid exposing a half torn-down window object // Clear all callbacks to avoid exposing a half torn-down window object
window->windowPosCallback = NULL; memset(&window->callbacks, 0, sizeof(window->callbacks));
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;
// The window's context must not be current on another thread when the // The window's context must not be current on another thread when the
// window is destroyed // window is destroyed
@ -800,7 +789,7 @@ GLFWAPI void glfwSetWindowPosCallback(GLFWwindow* handle, GLFWwindowposfun cbfun
return; return;
} }
window->windowPosCallback = cbfun; window->callbacks.pos = cbfun;
} }
@ -818,7 +807,7 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow* handle, GLFWwindowsizefun cbf
return; return;
} }
window->windowSizeCallback = cbfun; window->callbacks.size = cbfun;
} }
@ -836,7 +825,7 @@ GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow* handle, GLFWwindowclosefun c
return; return;
} }
window->windowCloseCallback = cbfun; window->callbacks.close = cbfun;
} }
@ -854,7 +843,7 @@ GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow* handle, GLFWwindowrefreshf
return; return;
} }
window->windowRefreshCallback = cbfun; window->callbacks.refresh = cbfun;
} }
@ -872,7 +861,7 @@ GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow* handle, GLFWwindowfocusfun c
return; return;
} }
window->windowFocusCallback = cbfun; window->callbacks.focus = cbfun;
} }
@ -890,7 +879,7 @@ GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow* handle, GLFWwindowiconifyf
return; return;
} }
window->windowIconifyCallback = cbfun; window->callbacks.iconify = cbfun;
} }