1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 02:38:52 -05:00

Added pointer swap macro for callback setters.

This commit is contained in:
Camilla Berglund 2013-07-30 14:43:01 +02:00
parent 9d0e102135
commit f7282e86c0
5 changed files with 39 additions and 86 deletions

View File

@ -192,8 +192,7 @@ GLFWAPI const char* glfwGetVersionString(void)
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
{
GLFWerrorfun previous = _glfwErrorCallback;
_glfwErrorCallback = cbfun;
return previous;
_GLFW_SWAP_POINTERS(_glfwErrorCallback, cbfun);
return cbfun;
}

View File

@ -349,76 +349,52 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWkeyfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.key;
window->callbacks.key = cbfun;
return previous;
_GLFW_SWAP_POINTERS(window->callbacks.key, cbfun);
return cbfun;
}
GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWcharfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.character;
window->callbacks.character = cbfun;
return previous;
_GLFW_SWAP_POINTERS(window->callbacks.character, cbfun);
return cbfun;
}
GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* handle,
GLFWmousebuttonfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWmousebuttonfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.mouseButton;
window->callbacks.mouseButton = cbfun;
return previous;
_GLFW_SWAP_POINTERS(window->callbacks.mouseButton, cbfun);
return cbfun;
}
GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* handle,
GLFWcursorposfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWcursorposfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.cursorPos;
window->callbacks.cursorPos = cbfun;
return previous;
_GLFW_SWAP_POINTERS(window->callbacks.cursorPos, cbfun);
return cbfun;
}
GLFWAPI GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* handle,
GLFWcursorenterfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWcursorenterfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.cursorEnter;
window->callbacks.cursorEnter = cbfun;
return previous;
_GLFW_SWAP_POINTERS(window->callbacks.cursorEnter, cbfun);
return cbfun;
}
GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* handle,
GLFWscrollfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWscrollfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.scroll;
window->callbacks.scroll = cbfun;
return previous;
_GLFW_SWAP_POINTERS(window->callbacks.scroll, cbfun);
return cbfun;
}

View File

@ -120,6 +120,15 @@ typedef struct _GLFWmonitor _GLFWmonitor;
return x; \
}
// Swaps the provided pointers
#define _GLFW_SWAP_POINTERS(x, y) \
{ \
void* t; \
t = x; \
x = y; \
y = t; \
}
//========================================================================
// Internal types

View File

@ -328,12 +328,9 @@ GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* handle)
GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun)
{
GLFWmonitorfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = _glfw.monitorCallback;
_glfw.monitorCallback = cbfun;
return previous;
_GLFW_SWAP_POINTERS(_glfw.monitorCallback, cbfun);
return cbfun;
}
GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count)

View File

@ -604,91 +604,63 @@ GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* handle,
GLFWwindowposfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWwindowposfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.pos;
window->callbacks.pos = cbfun;
return previous;
_GLFW_SWAP_POINTERS(window->callbacks.pos, cbfun);
return cbfun;
}
GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* handle,
GLFWwindowsizefun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWwindowsizefun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.size;
window->callbacks.size = cbfun;
return previous;
_GLFW_SWAP_POINTERS(window->callbacks.size, cbfun);
return cbfun;
}
GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* handle,
GLFWwindowclosefun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWwindowclosefun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.close;
window->callbacks.close = cbfun;
return previous;
_GLFW_SWAP_POINTERS(window->callbacks.close, cbfun);
return cbfun;
}
GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* handle,
GLFWwindowrefreshfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWwindowrefreshfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.refresh;
window->callbacks.refresh = cbfun;
return previous;
_GLFW_SWAP_POINTERS(window->callbacks.refresh, cbfun);
return cbfun;
}
GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* handle,
GLFWwindowfocusfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWwindowfocusfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.focus;
window->callbacks.focus = cbfun;
return previous;
_GLFW_SWAP_POINTERS(window->callbacks.focus, cbfun);
return cbfun;
}
GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* handle,
GLFWwindowiconifyfun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWwindowiconifyfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.iconify;
window->callbacks.iconify = cbfun;
return previous;
_GLFW_SWAP_POINTERS(window->callbacks.iconify, cbfun);
return cbfun;
}
GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* handle,
GLFWframebuffersizefun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWframebuffersizefun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.fbsize;
window->callbacks.fbsize = cbfun;
return previous;
_GLFW_SWAP_POINTERS(window->callbacks.fbsize, cbfun);
return cbfun;
}
GLFWAPI void glfwPollEvents(void)