From e229ccd7c4ee2dcfab90d1e25feb3f3c90a3b228 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 9 Sep 2010 19:01:16 +0200 Subject: [PATCH] Added window parameter to callbacks, handled NULL argument to glfwIsWindow. --- include/GL/glfw.h | 16 ++++++++-------- lib/enable.c | 3 ++- lib/input.c | 4 ++-- lib/window.c | 15 +++++++++------ lib/x11/x11_window.c | 14 ++++++++------ 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/include/GL/glfw.h b/include/GL/glfw.h index 4647b7bf..5f433bc7 100644 --- a/include/GL/glfw.h +++ b/include/GL/glfw.h @@ -364,14 +364,14 @@ typedef struct { } GLFWvidmode; /* Function pointer types */ -typedef void (* GLFWwindowsizefun)(int,int); -typedef int (* GLFWwindowclosefun)(void); -typedef void (* GLFWwindowrefreshfun)(void); -typedef void (* GLFWmousebuttonfun)(int,int); -typedef void (* GLFWmouseposfun)(int,int); -typedef void (* GLFWmousewheelfun)(int); -typedef void (* GLFWkeyfun)(int,int); -typedef void (* GLFWcharfun)(int,int); +typedef void (* GLFWwindowsizefun)(GLFWwindow,int,int); +typedef int (* GLFWwindowclosefun)(GLFWwindow); +typedef void (* GLFWwindowrefreshfun)(GLFWwindow); +typedef void (* GLFWmousebuttonfun)(GLFWwindow,int,int); +typedef void (* GLFWmouseposfun)(GLFWwindow,int,int); +typedef void (* GLFWmousewheelfun)(GLFWwindow,int); +typedef void (* GLFWkeyfun)(GLFWwindow,int,int); +typedef void (* GLFWcharfun)(GLFWwindow,int,int); /************************************************************************* diff --git a/lib/enable.c b/lib/enable.c index e20f8942..a55e785f 100644 --- a/lib/enable.c +++ b/lib/enable.c @@ -61,7 +61,8 @@ static void enableMouseCursor(_GLFWwindow* window) if (window->mousePosCallback) { - window->mousePosCallback(window->mousePosX, + window->mousePosCallback(window, + window->mousePosX, window->mousePosY); } } diff --git a/lib/input.c b/lib/input.c index f75ede7b..f004dc9d 100644 --- a/lib/input.c +++ b/lib/input.c @@ -203,7 +203,7 @@ GLFWAPI void glfwSetMousePosCallback(GLFWwindow window, GLFWmouseposfun cbfun) // Call the callback function to let the application know the current // mouse position if (cbfun) - cbfun(window->mousePosX, window->mousePosY); + cbfun(window, window->mousePosX, window->mousePosY); } @@ -222,6 +222,6 @@ GLFWAPI void glfwSetMouseWheelCallback(GLFWwindow window, GLFWmousewheelfun cbfu // Call the callback function to let the application know the current // mouse wheel position if (cbfun) - cbfun(window->wheelPos); + cbfun(window, window->wheelPos); } diff --git a/lib/window.c b/lib/window.c index 5383e29f..67f93f1e 100644 --- a/lib/window.c +++ b/lib/window.c @@ -141,7 +141,7 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action) // Call user callback function if (window->keyCallback && (window->keyRepeat || !keyrepeat) ) - window->keyCallback(key, action); + window->keyCallback(window, key, action); } @@ -186,7 +186,7 @@ void _glfwInputChar(_GLFWwindow* window, int character, int action) } if (window->charCallback && (window->keyRepeat || !keyrepeat)) - window->charCallback(character, action); + window->charCallback(window, character, action); } @@ -206,7 +206,7 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action) window->mouseButton[button] = (char) action; if (window->mouseButtonCallback) - window->mouseButtonCallback(button, action); + window->mouseButtonCallback(window, button, action); } @@ -580,9 +580,12 @@ GLFWAPI void glfwMakeWindowCurrent(GLFWwindow window) GLFWAPI int glfwIsWindow(GLFWwindow window) { if (!_glfwInitialized) - return; + return GL_FALSE; - return window == _glfwLibrary.window; + if (window == NULL) + return GL_FALSE; + + return (window == _glfwLibrary.window) ? GL_TRUE : GL_FALSE; } @@ -873,7 +876,7 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfu // Call the callback function to let the application know the current // window size if (cbfun) - cbfun(window->width, window->height); + cbfun(window, window->width, window->height); } //======================================================================== diff --git a/lib/x11/x11_window.c b/lib/x11/x11_window.c index 35d1fc44..722939a9 100644 --- a/lib/x11/x11_window.c +++ b/lib/x11/x11_window.c @@ -1088,13 +1088,13 @@ static GLboolean processSingleEvent(void) { window->wheelPos++; // To verify: is this up or down? if (window->mouseWheelCallback) - window->mouseWheelCallback(window->wheelPos); + window->mouseWheelCallback(window, window->wheelPos); } else if (event.xbutton.button == Button5) { window->wheelPos--; if (window->mouseWheelCallback) - window->mouseWheelCallback(window->wheelPos); + window->mouseWheelCallback(window, window->wheelPos); } break; } @@ -1155,7 +1155,8 @@ static GLboolean processSingleEvent(void) if (window->mousePosCallback) { - window->mousePosCallback(window->mousePosX, + window->mousePosCallback(window, + window->mousePosX, window->mousePosY); } } @@ -1173,7 +1174,8 @@ static GLboolean processSingleEvent(void) window->height = event.xconfigure.height; if (window->windowSizeCallback) { - window->windowSizeCallback(window->width, + window->windowSizeCallback(window, + window->width, window->height); } } @@ -1252,7 +1254,7 @@ static GLboolean processSingleEvent(void) // The window's contents was damaged if (window->windowRefreshCallback) - window->windowRefreshCallback(); + window->windowRefreshCallback(window); break; } @@ -1697,7 +1699,7 @@ void _glfwPlatformPollEvents(void) } if (closeRequested && window->windowCloseCallback) - closeRequested = window->windowCloseCallback(); + closeRequested = window->windowCloseCallback(window); if (closeRequested) glfwCloseWindow(window);