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:
parent
9d0e102135
commit
f7282e86c0
|
@ -192,8 +192,7 @@ GLFWAPI const char* glfwGetVersionString(void)
|
||||||
|
|
||||||
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
|
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
|
||||||
{
|
{
|
||||||
GLFWerrorfun previous = _glfwErrorCallback;
|
_GLFW_SWAP_POINTERS(_glfwErrorCallback, cbfun);
|
||||||
_glfwErrorCallback = cbfun;
|
return cbfun;
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
48
src/input.c
48
src/input.c
|
@ -349,76 +349,52 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
|
||||||
GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun)
|
GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
GLFWkeyfun previous;
|
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.key, cbfun);
|
||||||
previous = window->callbacks.key;
|
return cbfun;
|
||||||
window->callbacks.key = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun)
|
GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
GLFWcharfun previous;
|
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.character, cbfun);
|
||||||
previous = window->callbacks.character;
|
return cbfun;
|
||||||
window->callbacks.character = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* handle,
|
GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* handle,
|
||||||
GLFWmousebuttonfun cbfun)
|
GLFWmousebuttonfun cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
GLFWmousebuttonfun previous;
|
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.mouseButton, cbfun);
|
||||||
previous = window->callbacks.mouseButton;
|
return cbfun;
|
||||||
window->callbacks.mouseButton = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* handle,
|
GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* handle,
|
||||||
GLFWcursorposfun cbfun)
|
GLFWcursorposfun cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
GLFWcursorposfun previous;
|
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.cursorPos, cbfun);
|
||||||
previous = window->callbacks.cursorPos;
|
return cbfun;
|
||||||
window->callbacks.cursorPos = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* handle,
|
GLFWAPI GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* handle,
|
||||||
GLFWcursorenterfun cbfun)
|
GLFWcursorenterfun cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
GLFWcursorenterfun previous;
|
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.cursorEnter, cbfun);
|
||||||
previous = window->callbacks.cursorEnter;
|
return cbfun;
|
||||||
window->callbacks.cursorEnter = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* handle,
|
GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* handle,
|
||||||
GLFWscrollfun cbfun)
|
GLFWscrollfun cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
GLFWscrollfun previous;
|
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.scroll, cbfun);
|
||||||
previous = window->callbacks.scroll;
|
return cbfun;
|
||||||
window->callbacks.scroll = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,15 @@ typedef struct _GLFWmonitor _GLFWmonitor;
|
||||||
return x; \
|
return x; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Swaps the provided pointers
|
||||||
|
#define _GLFW_SWAP_POINTERS(x, y) \
|
||||||
|
{ \
|
||||||
|
void* t; \
|
||||||
|
t = x; \
|
||||||
|
x = y; \
|
||||||
|
y = t; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Internal types
|
// Internal types
|
||||||
|
|
|
@ -328,12 +328,9 @@ GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* handle)
|
||||||
|
|
||||||
GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun)
|
GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun)
|
||||||
{
|
{
|
||||||
GLFWmonitorfun previous;
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(_glfw.monitorCallback, cbfun);
|
||||||
previous = _glfw.monitorCallback;
|
return cbfun;
|
||||||
_glfw.monitorCallback = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count)
|
GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count)
|
||||||
|
|
56
src/window.c
56
src/window.c
|
@ -604,91 +604,63 @@ GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* handle,
|
||||||
GLFWwindowposfun cbfun)
|
GLFWwindowposfun cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
GLFWwindowposfun previous;
|
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.pos, cbfun);
|
||||||
previous = window->callbacks.pos;
|
return cbfun;
|
||||||
window->callbacks.pos = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* handle,
|
GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* handle,
|
||||||
GLFWwindowsizefun cbfun)
|
GLFWwindowsizefun cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
GLFWwindowsizefun previous;
|
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.size, cbfun);
|
||||||
previous = window->callbacks.size;
|
return cbfun;
|
||||||
window->callbacks.size = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* handle,
|
GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* handle,
|
||||||
GLFWwindowclosefun cbfun)
|
GLFWwindowclosefun cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
GLFWwindowclosefun previous;
|
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.close, cbfun);
|
||||||
previous = window->callbacks.close;
|
return cbfun;
|
||||||
window->callbacks.close = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* handle,
|
GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* handle,
|
||||||
GLFWwindowrefreshfun cbfun)
|
GLFWwindowrefreshfun cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
GLFWwindowrefreshfun previous;
|
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.refresh, cbfun);
|
||||||
previous = window->callbacks.refresh;
|
return cbfun;
|
||||||
window->callbacks.refresh = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* handle,
|
GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* handle,
|
||||||
GLFWwindowfocusfun cbfun)
|
GLFWwindowfocusfun cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
GLFWwindowfocusfun previous;
|
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.focus, cbfun);
|
||||||
previous = window->callbacks.focus;
|
return cbfun;
|
||||||
window->callbacks.focus = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* handle,
|
GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* handle,
|
||||||
GLFWwindowiconifyfun cbfun)
|
GLFWwindowiconifyfun cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
GLFWwindowiconifyfun previous;
|
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.iconify, cbfun);
|
||||||
previous = window->callbacks.iconify;
|
return cbfun;
|
||||||
window->callbacks.iconify = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* handle,
|
GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* handle,
|
||||||
GLFWframebuffersizefun cbfun)
|
GLFWframebuffersizefun cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
GLFWframebuffersizefun previous;
|
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
_GLFW_SWAP_POINTERS(window->callbacks.fbsize, cbfun);
|
||||||
previous = window->callbacks.fbsize;
|
return cbfun;
|
||||||
window->callbacks.fbsize = cbfun;
|
|
||||||
return previous;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI void glfwPollEvents(void)
|
GLFWAPI void glfwPollEvents(void)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user