mirror of
https://github.com/glfw/glfw.git
synced 2024-11-14 02:31:46 +00:00
Added window position callback.
This commit is contained in:
parent
fc69721807
commit
1a3d47d06d
@ -706,6 +706,16 @@ typedef void* GLFWwindow;
|
|||||||
*/
|
*/
|
||||||
typedef void (* GLFWerrorfun)(int,const char*);
|
typedef void (* GLFWerrorfun)(int,const char*);
|
||||||
|
|
||||||
|
/*! @brief The function signature for window position callbacks.
|
||||||
|
* @param[in] window The window that the user moved.
|
||||||
|
* @param[in] x The new x-coordinate, in pixels, of the upper-left corner of
|
||||||
|
* the client area of the window.
|
||||||
|
* @param[in] y The new y-coordinate, in pixels, of the upper-left corner of
|
||||||
|
* the client area of the window.
|
||||||
|
* @ingroup window
|
||||||
|
*/
|
||||||
|
typedef void (* GLFWwindowposfun)(GLFWwindow,int,int);
|
||||||
|
|
||||||
/*! @brief The function signature for window resize callbacks.
|
/*! @brief The function signature for window resize callbacks.
|
||||||
* @param[in] window The window that the user resized.
|
* @param[in] window The window that the user resized.
|
||||||
* @param[in] width The new width, in pixels, of the window.
|
* @param[in] width The new width, in pixels, of the window.
|
||||||
@ -1274,6 +1284,14 @@ GLFWAPI void glfwSetWindowUserPointer(GLFWwindow window, void* pointer);
|
|||||||
*/
|
*/
|
||||||
GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window);
|
GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window);
|
||||||
|
|
||||||
|
/*! @brief Sets the position callback for the specified window.
|
||||||
|
* @param[in] window The window whose callback to set.
|
||||||
|
* @param[in] cbfun The new callback, or @c NULL to remove the currently set
|
||||||
|
* callback.
|
||||||
|
* @ingroup window
|
||||||
|
*/
|
||||||
|
GLFWAPI void glfwSetWindowPosCallback(GLFWwindow window, GLFWwindowposfun cbfun);
|
||||||
|
|
||||||
/*! @brief Sets the size callback for the specified window.
|
/*! @brief Sets the size callback for the specified window.
|
||||||
* @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 @c NULL to remove the currently set
|
* @param[in] cbfun The new callback, or @c NULL to remove the currently set
|
||||||
|
@ -274,7 +274,7 @@ version of GLFW.</p>
|
|||||||
<li>Added <code>glfwSetErrorCallback</code> function and <code>GLFWerrorfun</code> type for receiving more specific and/or nested errors</li>
|
<li>Added <code>glfwSetErrorCallback</code> function and <code>GLFWerrorfun</code> type for receiving more specific and/or nested errors</li>
|
||||||
<li>Added <code>glfwSetWindowUserPointer</code> and <code>glfwGetWindowUserPointer</code> functions for per-window user pointers</li>
|
<li>Added <code>glfwSetWindowUserPointer</code> and <code>glfwGetWindowUserPointer</code> functions for per-window user pointers</li>
|
||||||
<li>Added <code>glfwGetVersionString</code> function for determining which code paths were enabled at compile time</li>
|
<li>Added <code>glfwGetVersionString</code> function for determining which code paths were enabled at compile time</li>
|
||||||
<li>Added <code>glfwGetWindowPos</code> function for querying the position of the specified window</li>
|
<li>Added <code>glfwSetWindowPosCallback</code> function and <code>GLFWwindowposfun</code> type for reciving window position events</li>
|
||||||
<li>Added <code>glfwSetWindowFocusCallback</code> function and <code>GLFWwindowfocusfun</code> type for receiving window focus events</li>
|
<li>Added <code>glfwSetWindowFocusCallback</code> function and <code>GLFWwindowfocusfun</code> type for receiving window focus events</li>
|
||||||
<li>Added <code>glfwSetWindowIconifyCallback</code> function and <code>GLFWwindowiconifyfun</code> type for receiving window iconification events</li>
|
<li>Added <code>glfwSetWindowIconifyCallback</code> function and <code>GLFWwindowiconifyfun</code> type for receiving window iconification events</li>
|
||||||
<li>Added <code>glfwGetClipboardString</code> and <code>glfwSetClipboardString</code> functions for interacting with the system clipboard</li>
|
<li>Added <code>glfwGetClipboardString</code> and <code>glfwSetClipboardString</code> functions for interacting with the system clipboard</li>
|
||||||
@ -284,6 +284,7 @@ version of GLFW.</p>
|
|||||||
<li>Added <code>GLFW_OPENGL_REVISION</code> window parameter to make up for removal of <code>glfwGetGLVersion</code></li>
|
<li>Added <code>GLFW_OPENGL_REVISION</code> window parameter to make up for removal of <code>glfwGetGLVersion</code></li>
|
||||||
<li>Added <code>GLFW_INCLUDE_GLCOREARB</code> macro for including <code>glcorearb.h</code> instead of <code>gl.h</code></li>
|
<li>Added <code>GLFW_INCLUDE_GLCOREARB</code> macro for including <code>glcorearb.h</code> instead of <code>gl.h</code></li>
|
||||||
<li>Added <code>GLFW_VISIBLE</code> window hint and parameter for controlling and polling window visibility</li>
|
<li>Added <code>GLFW_VISIBLE</code> window hint and parameter for controlling and polling window visibility</li>
|
||||||
|
<li>Added <code>GLFW_POSITION_X</code> and <code>GLFW_POSITION_Y</code> window hints and parameter for controlling and polling window position</li>
|
||||||
<li>Added <code>windows</code> simple multi-window test program</li>
|
<li>Added <code>windows</code> simple multi-window test program</li>
|
||||||
<li>Added <code>sharing</code> simple OpenGL object sharing test program</li>
|
<li>Added <code>sharing</code> simple OpenGL object sharing test program</li>
|
||||||
<li>Added <code>modes</code> video mode enumeration and setting test program</li>
|
<li>Added <code>modes</code> video mode enumeration and setting test program</li>
|
||||||
|
@ -199,6 +199,7 @@ struct _GLFWwindow
|
|||||||
int glRobustness;
|
int glRobustness;
|
||||||
PFNGLGETSTRINGIPROC GetStringi;
|
PFNGLGETSTRINGIPROC GetStringi;
|
||||||
|
|
||||||
|
GLFWwindowposfun windowPosCallback;
|
||||||
GLFWwindowsizefun windowSizeCallback;
|
GLFWwindowsizefun windowSizeCallback;
|
||||||
GLFWwindowclosefun windowCloseCallback;
|
GLFWwindowclosefun windowCloseCallback;
|
||||||
GLFWwindowrefreshfun windowRefreshCallback;
|
GLFWwindowrefreshfun windowRefreshCallback;
|
||||||
|
24
src/window.c
24
src/window.c
@ -119,8 +119,14 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
|
|||||||
|
|
||||||
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
|
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
|
||||||
{
|
{
|
||||||
|
if (window->positionX == x && window->positionY == y)
|
||||||
|
return;
|
||||||
|
|
||||||
window->positionX = x;
|
window->positionX = x;
|
||||||
window->positionY = y;
|
window->positionY = y;
|
||||||
|
|
||||||
|
if (window->windowPosCallback)
|
||||||
|
window->windowPosCallback(window, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -764,6 +770,24 @@ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Set callback function for window position changes
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
GLFWAPI void glfwSetWindowPosCallback(GLFWwindow handle, GLFWwindowposfun cbfun)
|
||||||
|
{
|
||||||
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
|
|
||||||
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window->windowPosCallback = cbfun;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set callback function for window size changes
|
// Set callback function for window size changes
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -218,6 +218,15 @@ static const char* get_character_string(int character)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void window_pos_callback(GLFWwindow window, int x, int y)
|
||||||
|
{
|
||||||
|
printf("%08x at %0.3f: Window position: %i %i\n",
|
||||||
|
counter++,
|
||||||
|
glfwGetTime(),
|
||||||
|
x,
|
||||||
|
y);
|
||||||
|
}
|
||||||
|
|
||||||
static void window_size_callback(GLFWwindow window, int width, int height)
|
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||||
{
|
{
|
||||||
printf("%08x at %0.3f: Window size: %i %i\n",
|
printf("%08x at %0.3f: Window size: %i %i\n",
|
||||||
@ -354,6 +363,7 @@ int main(void)
|
|||||||
|
|
||||||
printf("Window opened\n");
|
printf("Window opened\n");
|
||||||
|
|
||||||
|
glfwSetWindowPosCallback(window, window_pos_callback);
|
||||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||||
glfwSetWindowCloseCallback(window, window_close_callback);
|
glfwSetWindowCloseCallback(window, window_close_callback);
|
||||||
glfwSetWindowRefreshCallback(window, window_refresh_callback);
|
glfwSetWindowRefreshCallback(window, window_refresh_callback);
|
||||||
|
Loading…
Reference in New Issue
Block a user