mirror of
https://github.com/glfw/glfw.git
synced 2026-09-19 23:43:15 +00:00
Made window-related callbacks per-window.
This makes polymorphic behaviour easier to implement and avoids the problem of events being triggered before the GLFW window object is fully usable.
This commit is contained in:
+38
-26
@@ -172,8 +172,8 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
||||
}
|
||||
|
||||
// Call user callback function
|
||||
if (_glfwLibrary.keyCallback && (window->keyRepeat || !repeated))
|
||||
_glfwLibrary.keyCallback(window, key, action);
|
||||
if (window->keyCallback && (window->keyRepeat || !repeated))
|
||||
window->keyCallback(window, key, action);
|
||||
}
|
||||
|
||||
|
||||
@@ -187,8 +187,8 @@ void _glfwInputChar(_GLFWwindow* window, int character)
|
||||
if (!((character >= 32 && character <= 126) || character >= 160))
|
||||
return;
|
||||
|
||||
if (_glfwLibrary.charCallback)
|
||||
_glfwLibrary.charCallback(window, character);
|
||||
if (window->charCallback)
|
||||
window->charCallback(window, character);
|
||||
}
|
||||
|
||||
|
||||
@@ -201,8 +201,8 @@ void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)
|
||||
window->scrollX += xoffset;
|
||||
window->scrollY += yoffset;
|
||||
|
||||
if (_glfwLibrary.scrollCallback)
|
||||
_glfwLibrary.scrollCallback(window, xoffset, yoffset);
|
||||
if (window->scrollCallback)
|
||||
window->scrollCallback(window, xoffset, yoffset);
|
||||
}
|
||||
|
||||
|
||||
@@ -221,8 +221,8 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
|
||||
else
|
||||
window->mouseButton[button] = (char) action;
|
||||
|
||||
if (_glfwLibrary.mouseButtonCallback)
|
||||
_glfwLibrary.mouseButtonCallback(window, button, action);
|
||||
if (window->mouseButtonCallback)
|
||||
window->mouseButtonCallback(window, button, action);
|
||||
}
|
||||
|
||||
|
||||
@@ -249,11 +249,11 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
|
||||
window->cursorPosY = y;
|
||||
}
|
||||
|
||||
if (_glfwLibrary.cursorPosCallback)
|
||||
if (window->cursorPosCallback)
|
||||
{
|
||||
_glfwLibrary.cursorPosCallback(window,
|
||||
window->cursorPosX,
|
||||
window->cursorPosY);
|
||||
window->cursorPosCallback(window,
|
||||
window->cursorPosX,
|
||||
window->cursorPosY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,8 +264,8 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
|
||||
|
||||
void _glfwInputCursorEnter(_GLFWwindow* window, int entered)
|
||||
{
|
||||
if (_glfwLibrary.cursorEnterCallback)
|
||||
_glfwLibrary.cursorEnterCallback(window, entered);
|
||||
if (window->cursorEnterCallback)
|
||||
window->cursorEnterCallback(window, entered);
|
||||
}
|
||||
|
||||
|
||||
@@ -494,15 +494,17 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, double* xoffset, double* yof
|
||||
// Set callback function for keyboard input
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun)
|
||||
GLFWAPI void glfwSetKeyCallback(GLFWwindow handle, GLFWkeyfun cbfun)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwLibrary.keyCallback = cbfun;
|
||||
window->keyCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@@ -510,15 +512,17 @@ GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun)
|
||||
// Set callback function for character input
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun)
|
||||
GLFWAPI void glfwSetCharCallback(GLFWwindow handle, GLFWcharfun cbfun)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwLibrary.charCallback = cbfun;
|
||||
window->charCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@@ -526,15 +530,17 @@ GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun)
|
||||
// Set callback function for mouse clicks
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun)
|
||||
GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow handle, GLFWmousebuttonfun cbfun)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwLibrary.mouseButtonCallback = cbfun;
|
||||
window->mouseButtonCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@@ -542,15 +548,17 @@ GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun)
|
||||
// Set callback function for mouse moves
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetCursorPosCallback(GLFWcursorposfun cbfun)
|
||||
GLFWAPI void glfwSetCursorPosCallback(GLFWwindow handle, GLFWcursorposfun cbfun)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwLibrary.cursorPosCallback = cbfun;
|
||||
window->cursorPosCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@@ -558,15 +566,17 @@ GLFWAPI void glfwSetCursorPosCallback(GLFWcursorposfun cbfun)
|
||||
// Set callback function for cursor enter/leave events
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun)
|
||||
GLFWAPI void glfwSetCursorEnterCallback(GLFWwindow handle, GLFWcursorenterfun cbfun)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwLibrary.cursorEnterCallback = cbfun;
|
||||
window->cursorEnterCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@@ -574,14 +584,16 @@ GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun)
|
||||
// Set callback function for scroll events
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun)
|
||||
GLFWAPI void glfwSetScrollCallback(GLFWwindow handle, GLFWscrollfun cbfun)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwLibrary.scrollCallback = cbfun;
|
||||
window->scrollCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -197,6 +197,18 @@ struct _GLFWwindow
|
||||
int glRobustness;
|
||||
PFNGLGETSTRINGIPROC GetStringi;
|
||||
|
||||
GLFWwindowsizefun windowSizeCallback;
|
||||
GLFWwindowclosefun windowCloseCallback;
|
||||
GLFWwindowrefreshfun windowRefreshCallback;
|
||||
GLFWwindowfocusfun windowFocusCallback;
|
||||
GLFWwindowiconifyfun windowIconifyCallback;
|
||||
GLFWmousebuttonfun mouseButtonCallback;
|
||||
GLFWcursorposfun cursorPosCallback;
|
||||
GLFWcursorenterfun cursorEnterCallback;
|
||||
GLFWscrollfun scrollCallback;
|
||||
GLFWkeyfun keyCallback;
|
||||
GLFWcharfun charCallback;
|
||||
|
||||
// These are defined in the current port's platform.h
|
||||
_GLFW_PLATFORM_WINDOW_STATE;
|
||||
_GLFW_PLATFORM_CONTEXT_STATE;
|
||||
@@ -213,18 +225,6 @@ struct _GLFWlibrary
|
||||
_GLFWwindow* windowListHead;
|
||||
_GLFWwindow* activeWindow;
|
||||
|
||||
GLFWwindowsizefun windowSizeCallback;
|
||||
GLFWwindowclosefun windowCloseCallback;
|
||||
GLFWwindowrefreshfun windowRefreshCallback;
|
||||
GLFWwindowfocusfun windowFocusCallback;
|
||||
GLFWwindowiconifyfun windowIconifyCallback;
|
||||
GLFWmousebuttonfun mouseButtonCallback;
|
||||
GLFWcursorposfun cursorPosCallback;
|
||||
GLFWcursorenterfun cursorEnterCallback;
|
||||
GLFWscrollfun scrollCallback;
|
||||
GLFWkeyfun keyCallback;
|
||||
GLFWcharfun charCallback;
|
||||
|
||||
GLFWgammaramp currentRamp;
|
||||
GLFWgammaramp originalRamp;
|
||||
int originalRampSize;
|
||||
|
||||
+32
-22
@@ -80,8 +80,8 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated)
|
||||
{
|
||||
_glfwLibrary.activeWindow = window;
|
||||
|
||||
if (_glfwLibrary.windowFocusCallback)
|
||||
_glfwLibrary.windowFocusCallback(window, activated);
|
||||
if (window->windowFocusCallback)
|
||||
window->windowFocusCallback(window, activated);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -106,8 +106,8 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated)
|
||||
|
||||
_glfwLibrary.activeWindow = NULL;
|
||||
|
||||
if (_glfwLibrary.windowFocusCallback)
|
||||
_glfwLibrary.windowFocusCallback(window, activated);
|
||||
if (window->windowFocusCallback)
|
||||
window->windowFocusCallback(window, activated);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,8 +136,8 @@ void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
|
||||
window->width = width;
|
||||
window->height = height;
|
||||
|
||||
if (_glfwLibrary.windowSizeCallback)
|
||||
_glfwLibrary.windowSizeCallback(window, width, height);
|
||||
if (window->windowSizeCallback)
|
||||
window->windowSizeCallback(window, width, height);
|
||||
}
|
||||
|
||||
|
||||
@@ -152,8 +152,8 @@ void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
|
||||
|
||||
window->iconified = iconified;
|
||||
|
||||
if (_glfwLibrary.windowIconifyCallback)
|
||||
_glfwLibrary.windowIconifyCallback(window, iconified);
|
||||
if (window->windowIconifyCallback)
|
||||
window->windowIconifyCallback(window, iconified);
|
||||
}
|
||||
|
||||
|
||||
@@ -173,8 +173,8 @@ void _glfwInputWindowVisibility(_GLFWwindow* window, int visible)
|
||||
|
||||
void _glfwInputWindowDamage(_GLFWwindow* window)
|
||||
{
|
||||
if (_glfwLibrary.windowRefreshCallback)
|
||||
_glfwLibrary.windowRefreshCallback(window);
|
||||
if (window->windowRefreshCallback)
|
||||
window->windowRefreshCallback(window);
|
||||
}
|
||||
|
||||
|
||||
@@ -184,8 +184,8 @@ void _glfwInputWindowDamage(_GLFWwindow* window)
|
||||
|
||||
void _glfwInputWindowCloseRequest(_GLFWwindow* window)
|
||||
{
|
||||
if (_glfwLibrary.windowCloseCallback)
|
||||
window->closeRequested = _glfwLibrary.windowCloseCallback(window);
|
||||
if (window->windowCloseCallback)
|
||||
window->closeRequested = window->windowCloseCallback(window);
|
||||
else
|
||||
window->closeRequested = GL_TRUE;
|
||||
}
|
||||
@@ -810,15 +810,17 @@ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow handle)
|
||||
// Set callback function for window size changes
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun)
|
||||
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow handle, GLFWwindowsizefun cbfun)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwLibrary.windowSizeCallback = cbfun;
|
||||
window->windowSizeCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@@ -826,15 +828,17 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun)
|
||||
// Set callback function for window close events
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindowclosefun cbfun)
|
||||
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow handle, GLFWwindowclosefun cbfun)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwLibrary.windowCloseCallback = cbfun;
|
||||
window->windowCloseCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@@ -842,15 +846,17 @@ GLFWAPI void glfwSetWindowCloseCallback(GLFWwindowclosefun cbfun)
|
||||
// Set callback function for window refresh events
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindowrefreshfun cbfun)
|
||||
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow handle, GLFWwindowrefreshfun cbfun)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwLibrary.windowRefreshCallback = cbfun;
|
||||
window->windowRefreshCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@@ -858,15 +864,17 @@ GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindowrefreshfun cbfun)
|
||||
// Set callback function for window focus events
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindowfocusfun cbfun)
|
||||
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow handle, GLFWwindowfocusfun cbfun)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwLibrary.windowFocusCallback = cbfun;
|
||||
window->windowFocusCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@@ -874,15 +882,17 @@ GLFWAPI void glfwSetWindowFocusCallback(GLFWwindowfocusfun cbfun)
|
||||
// Set callback function for window iconification events
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindowiconifyfun cbfun)
|
||||
GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow handle, GLFWwindowiconifyfun cbfun)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwLibrary.windowIconifyCallback = cbfun;
|
||||
window->windowIconifyCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user