Added return by setters of previous callback.

This commit is contained in:
Camilla Berglund 2013-04-08 21:21:21 +02:00
parent 37a137559e
commit 11a27de3d3
5 changed files with 147 additions and 41 deletions

View File

@ -908,6 +908,8 @@ GLFWAPI const char* glfwGetVersionString(void);
* @param[in] cbfun The new callback, or `NULL` to remove the currently set * @param[in] cbfun The new callback, or `NULL` to remove the currently set
* callback. * callback.
* *
* @return The previously set callback, or `NULL` if an error occurred.
*
* @remarks This function may be called before @ref glfwInit. * @remarks This function may be called before @ref glfwInit.
* *
* @note The error callback is called by the thread where the error was * @note The error callback is called by the thread where the error was
@ -921,7 +923,7 @@ GLFWAPI const char* glfwGetVersionString(void);
* *
* @ingroup error * @ingroup error
*/ */
GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun); GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun);
/*! @brief Returns the currently connected monitors. /*! @brief Returns the currently connected monitors.
* *
@ -1005,12 +1007,13 @@ GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* monitor);
* *
* @param[in] cbfun The new callback, or `NULL` to remove the currently set * @param[in] cbfun The new callback, or `NULL` to remove the currently set
* callback. * callback.
* @return The previously set callback, or `NULL` if an error occurred.
* *
* @bug This callback is not yet called on monitor configuration changes. * @bug This callback is not yet called on monitor configuration changes.
* *
* @ingroup monitor * @ingroup monitor
*/ */
GLFWAPI void glfwSetMonitorCallback(GLFWmonitorfun cbfun); GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun);
/*! @brief Returns the available video modes for the specified monitor. /*! @brief Returns the available video modes for the specified monitor.
* *
@ -1502,9 +1505,11 @@ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* window);
* @param[in] cbfun The new callback, or `NULL` to remove the currently set * @param[in] cbfun The new callback, or `NULL` to remove the currently set
* callback. * callback.
* *
* @return The previously set callback, or `NULL` if an error occurred.
*
* @ingroup window * @ingroup window
*/ */
GLFWAPI void glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun cbfun); GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun cbfun);
/*! @brief Sets the size callback for the specified window. /*! @brief Sets the size callback for the specified window.
* *
@ -1516,9 +1521,11 @@ GLFWAPI void glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun cbfun
* @param[in] cbfun The new callback, or `NULL` to remove the currently set * @param[in] cbfun The new callback, or `NULL` to remove the currently set
* callback. * callback.
* *
* @return The previously set callback, or `NULL` if an error occurred.
*
* @ingroup window * @ingroup window
*/ */
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun cbfun); GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun cbfun);
/*! @brief Sets the close callback for the specified window. /*! @brief Sets the close callback for the specified window.
* *
@ -1536,12 +1543,14 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun cbf
* @remarks Calling @ref glfwDestroyWindow does not cause this callback to be * @remarks Calling @ref glfwDestroyWindow does not cause this callback to be
* called. * called.
* *
* @return The previously set callback, or `NULL` if an error occurred.
*
* @remarks **Mac OS X:** Selecting Quit from the application menu will * @remarks **Mac OS X:** Selecting Quit from the application menu will
* trigger the close callback for all windows. * trigger the close callback for all windows.
* *
* @ingroup window * @ingroup window
*/ */
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun cbfun); GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun cbfun);
/*! @brief Sets the refresh callback for the specified window. /*! @brief Sets the refresh callback for the specified window.
* *
@ -1556,10 +1565,15 @@ GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun c
* @param[in] window The window whose callback to set. * @param[in] window The window whose callback to set.
* @param[in] cbfun The new callback, or `NULL` to remove the currently set * @param[in] cbfun The new callback, or `NULL` to remove the currently set
* callback. * callback.
* @return The previously set callback, or `NULL` if an error occurred.
*
* @note On compositing window systems such as Aero, Compiz or Aqua, where the
* window contents are saved off-screen, this callback may be called only very
* infrequently or never at all.
* *
* @ingroup window * @ingroup window
*/ */
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun cbfun); GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun cbfun);
/*! @brief Sets the focus callback for the specified window. /*! @brief Sets the focus callback for the specified window.
* *
@ -1570,9 +1584,11 @@ GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshf
* @param[in] cbfun The new callback, or `NULL` to remove the currently set * @param[in] cbfun The new callback, or `NULL` to remove the currently set
* callback. * callback.
* *
* @return The previously set callback, or `NULL` if an error occurred.
*
* @ingroup window * @ingroup window
*/ */
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun cbfun); GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun cbfun);
/*! @brief Sets the iconify callback for the specified window. /*! @brief Sets the iconify callback for the specified window.
* *
@ -1583,9 +1599,11 @@ GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun c
* @param[in] cbfun The new callback, or `NULL` to remove the currently set * @param[in] cbfun The new callback, or `NULL` to remove the currently set
* callback. * callback.
* *
* @return The previously set callback, or `NULL` if an error occurred.
*
* @ingroup window * @ingroup window
*/ */
GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun cbfun); GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun cbfun);
/*! @brief Processes all pending events. /*! @brief Processes all pending events.
* *
@ -1786,9 +1804,11 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos);
* @param[in] cbfun The new key callback, or `NULL` to remove the currently * @param[in] cbfun The new key callback, or `NULL` to remove the currently
* set callback. * set callback.
* *
* @return The previously set callback, or `NULL` if an error occurred.
*
* @ingroup input * @ingroup input
*/ */
GLFWAPI void glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun cbfun); GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun cbfun);
/*! @brief Sets the Unicode character callback. /*! @brief Sets the Unicode character callback.
* *
@ -1803,9 +1823,11 @@ GLFWAPI void glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun cbfun);
* @param[in] cbfun The new callback, or `NULL` to remove the currently set * @param[in] cbfun The new callback, or `NULL` to remove the currently set
* callback. * callback.
* *
* @return The previously set callback, or `NULL` if an error occurred.
*
* @ingroup input * @ingroup input
*/ */
GLFWAPI void glfwSetCharCallback(GLFWwindow* window, GLFWcharfun cbfun); GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow* window, GLFWcharfun cbfun);
/*! @brief Sets the mouse button callback. /*! @brief Sets the mouse button callback.
* *
@ -1816,9 +1838,11 @@ GLFWAPI void glfwSetCharCallback(GLFWwindow* window, GLFWcharfun cbfun);
* @param[in] cbfun The new callback, or `NULL` to remove the currently set * @param[in] cbfun The new callback, or `NULL` to remove the currently set
* callback. * callback.
* *
* @return The previously set callback, or `NULL` if an error occurred.
*
* @ingroup input * @ingroup input
*/ */
GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun cbfun); GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun cbfun);
/*! @brief Sets the cursor position callback. /*! @brief Sets the cursor position callback.
* *
@ -1830,9 +1854,11 @@ GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun c
* @param[in] cbfun The new callback, or `NULL` to remove the currently set * @param[in] cbfun The new callback, or `NULL` to remove the currently set
* callback. * callback.
* *
* @return The previously set callback, or `NULL` if an error occurred.
*
* @ingroup input * @ingroup input
*/ */
GLFWAPI void glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun cbfun); GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun cbfun);
/*! @brief Sets the cursor enter/exit callback. /*! @brief Sets the cursor enter/exit callback.
* *
@ -1844,9 +1870,11 @@ GLFWAPI void glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun cbfun
* @param[in] cbfun The new callback, or `NULL` to remove the currently set * @param[in] cbfun The new callback, or `NULL` to remove the currently set
* callback. * callback.
* *
* @return The previously set callback, or `NULL` if an error occurred.
*
* @ingroup input * @ingroup input
*/ */
GLFWAPI void glfwSetCursorEnterCallback(GLFWwindow* window, GLFWcursorenterfun cbfun); GLFWAPI GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* window, GLFWcursorenterfun cbfun);
/*! @brief Sets the scroll callback. /*! @brief Sets the scroll callback.
* *
@ -1861,9 +1889,11 @@ GLFWAPI void glfwSetCursorEnterCallback(GLFWwindow* window, GLFWcursorenterfun c
* @remarks This receives all scrolling input, like that from a mouse wheel or * @remarks This receives all scrolling input, like that from a mouse wheel or
* a touchpad scrolling area. * a touchpad scrolling area.
* *
* @return The previously set callback, or `NULL` if an error occurred.
*
* @ingroup input * @ingroup input
*/ */
GLFWAPI void glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cbfun); GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cbfun);
/*! @brief Returns a parameter of the specified joystick. /*! @brief Returns a parameter of the specified joystick.
* *

View File

@ -190,8 +190,10 @@ GLFWAPI const char* glfwGetVersionString(void)
return _glfwPlatformGetVersionString(); return _glfwPlatformGetVersionString();
} }
GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun) GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
{ {
GLFWerrorfun previous = _glfwErrorCallback;
_glfwErrorCallback = cbfun; _glfwErrorCallback = cbfun;
return previous;
} }

View File

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

View File

@ -289,10 +289,14 @@ GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* handle)
return monitor->name; return monitor->name;
} }
GLFWAPI void glfwSetMonitorCallback(GLFWmonitorfun cbfun) GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun)
{ {
_GLFW_REQUIRE_INIT(); GLFWmonitorfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = _glfw.monitorCallback;
_glfw.monitorCallback = cbfun; _glfw.monitorCallback = cbfun;
return previous;
} }
GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count) GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count)

View File

@ -582,46 +582,82 @@ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* handle)
return window->userPointer; return window->userPointer;
} }
GLFWAPI void glfwSetWindowPosCallback(GLFWwindow* handle, GLFWwindowposfun cbfun) GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* handle,
GLFWwindowposfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT(); GLFWwindowposfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.pos;
window->callbacks.pos = cbfun; window->callbacks.pos = cbfun;
return previous;
} }
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow* handle, GLFWwindowsizefun cbfun) GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* handle,
GLFWwindowsizefun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT(); GLFWwindowsizefun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.size;
window->callbacks.size = cbfun; window->callbacks.size = cbfun;
return previous;
} }
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow* handle, GLFWwindowclosefun cbfun) GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* handle,
GLFWwindowclosefun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT(); GLFWwindowclosefun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.close;
window->callbacks.close = cbfun; window->callbacks.close = cbfun;
return previous;
} }
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow* handle, GLFWwindowrefreshfun cbfun) GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* handle,
GLFWwindowrefreshfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT(); GLFWwindowrefreshfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.refresh;
window->callbacks.refresh = cbfun; window->callbacks.refresh = cbfun;
return previous;
} }
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow* handle, GLFWwindowfocusfun cbfun) GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* handle,
GLFWwindowfocusfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT(); GLFWwindowfocusfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.focus;
window->callbacks.focus = cbfun; window->callbacks.focus = cbfun;
return previous;
} }
GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow* handle, GLFWwindowiconifyfun cbfun) GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* handle,
GLFWwindowiconifyfun cbfun)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT(); GLFWwindowiconifyfun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.iconify;
window->callbacks.iconify = cbfun; window->callbacks.iconify = cbfun;
return previous;
} }
GLFWAPI void glfwPollEvents(void) GLFWAPI void glfwPollEvents(void)