From 48f5a7e76375e836655bb3e2249a68d41702ce70 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 9 Sep 2010 22:44:38 +0200 Subject: [PATCH] Added per-window user pointers. --- include/GL/glfw.h | 2 ++ readme.html | 1 + src/internal.h | 1 + src/window.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/include/GL/glfw.h b/include/GL/glfw.h index cc35328e..484adea2 100644 --- a/include/GL/glfw.h +++ b/include/GL/glfw.h @@ -421,6 +421,8 @@ GLFWAPI void glfwSetWindowPos(GLFWwindow, int x, int y); GLFWAPI void glfwIconifyWindow(GLFWwindow window); GLFWAPI void glfwRestoreWindow(GLFWwindow window); GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param); +GLFWAPI void glfwSetWindowUserPointer(GLFWwindow window, void* pointer); +GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window); GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun); GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun); GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun); diff --git a/readme.html b/readme.html index adea6e02..5e3083ee 100644 --- a/readme.html +++ b/readme.html @@ -265,6 +265,7 @@ version of GLFW.

  • Added glfwIsWindow function for verifying that a given window handle is (still) valid
  • Added glfwMakeWindowCurrent function for making the context of the specified window current
  • Added glfwGetError and glfwErrorString error reporting functions and a number of error tokens
  • +
  • Added glfwSetWindowUserPointer and glfwGetWindowUserPointer functions for per-window user pointers
  • Changed buffer bit depth parameters of glfwOpenWindow to window hints
  • Renamed lib source code directory to src
  • Replaced ad hoc build system with CMake
  • diff --git a/src/internal.h b/src/internal.h index db9a182c..665001e2 100644 --- a/src/internal.h +++ b/src/internal.h @@ -158,6 +158,7 @@ typedef struct _GLFWwindow GLboolean sysKeysDisabled; // system keys disabled flag GLboolean windowNoResize; // resize- and maximize gadgets disabled flag int refreshRate; // monitor refresh rate + void* userPointer; // Window input state GLboolean stickyKeys; diff --git a/src/window.c b/src/window.c index 22e1e864..5644b452 100644 --- a/src/window.c +++ b/src/window.c @@ -944,6 +944,38 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param) } +//======================================================================== +// Set the user pointer for the specified window +//======================================================================== + +GLFWAPI void glfwSetWindowUserPointer(GLFWwindow window, void* pointer) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED); + return; + } + + window->userPointer = pointer; +} + + +//======================================================================== +// Get the user pointer for the specified window +//======================================================================== + +GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED); + return; + } + + return window->userPointer; +} + + //======================================================================== // Set callback function for window size changes //========================================================================