Add GLFW_CENTER_CURSOR

Adds a hint for controlling whether the cursor is centered over newly
created full screen windows.

Fixes #749.
Closes #842.
This commit is contained in:
Liam Middlebrook 2016-08-18 11:47:54 -04:00 committed by Camilla Löwy
parent 3af0c47c97
commit 72ac5badb0
8 changed files with 22 additions and 3 deletions

View File

@ -159,6 +159,7 @@ information on what to include when reporting a bug.
- [Cocoa] Bugfix: Windows created after the first were not cascaded (#195) - [Cocoa] Bugfix: Windows created after the first were not cascaded (#195)
- [EGL] Added support for `EGL_KHR_get_all_proc_addresses` (#871) - [EGL] Added support for `EGL_KHR_get_all_proc_addresses` (#871)
- [EGL] Bugfix: The test for `EGL_RGB_BUFFER` was invalid - [EGL] Bugfix: The test for `EGL_RGB_BUFFER` was invalid
- Added 'GLFW_CENTER_CURSOR' window hint for controlling cursor centering
## Contact ## Contact
@ -307,6 +308,7 @@ skills.
- Santi Zupancic - Santi Zupancic
- Jonas Ådahl - Jonas Ådahl
- Lasse Öörni - Lasse Öörni
- Liam Middlebrook
- All the unmentioned and anonymous contributors in the GLFW community, for bug - All the unmentioned and anonymous contributors in the GLFW community, for bug
reports, patches, feedback, testing and encouragement reports, patches, feedback, testing and encouragement

View File

@ -428,6 +428,7 @@ GLFW_FOCUSED | `GLFW_TRUE` | `GLFW_TRUE` or `GL
GLFW_AUTO_ICONIFY | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` GLFW_AUTO_ICONIFY | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_FLOATING | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE` GLFW_FLOATING | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_MAXIMIZED | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE` GLFW_MAXIMIZED | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_CENTER_CURSOR | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
GLFW_RED_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE` GLFW_RED_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
GLFW_GREEN_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE` GLFW_GREEN_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
GLFW_BLUE_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE` GLFW_BLUE_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
@ -1041,6 +1042,10 @@ __GLFW_MAXIMIZED__ indicates whether the specified window is maximized. See
__GLFW_VISIBLE__ indicates whether the specified window is visible. See @ref __GLFW_VISIBLE__ indicates whether the specified window is visible. See @ref
window_hide for details. window_hide for details.
`GLFW_CENTER_CURSOR` indicates whether the cursor should be moved to the center
of the full screen window during creation. This is ignored for windowed mode
windows.
@anchor GLFW_RESIZABLE_attrib @anchor GLFW_RESIZABLE_attrib
__GLFW_RESIZABLE__ indicates whether the specified window is resizable _by the __GLFW_RESIZABLE__ indicates whether the specified window is resizable _by the
user_. This can be set before creation with the user_. This can be set before creation with the

View File

@ -686,6 +686,7 @@ extern "C" {
* [window attribute](@ref GLFW_MAXIMIZED_attrib). * [window attribute](@ref GLFW_MAXIMIZED_attrib).
*/ */
#define GLFW_MAXIMIZED 0x00020008 #define GLFW_MAXIMIZED 0x00020008
#define GLFW_CENTER_CURSOR 0x00020009
/*! @brief Framebuffer bit depth hint. /*! @brief Framebuffer bit depth hint.
* *

View File

@ -1096,6 +1096,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (!acquireMonitor(window)) if (!acquireMonitor(window))
return GLFW_FALSE; return GLFW_FALSE;
if (wndconfig->centerCursor)
centerCursor(window); centerCursor(window);
} }

View File

@ -277,6 +277,7 @@ struct _GLFWwndconfig
GLFWbool autoIconify; GLFWbool autoIconify;
GLFWbool floating; GLFWbool floating;
GLFWbool maximized; GLFWbool maximized;
GLFWbool centerCursor;
struct { struct {
GLFWbool retina; GLFWbool retina;
GLFWbool frame; GLFWbool frame;

View File

@ -1037,8 +1037,11 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (!acquireMonitor(window)) if (!acquireMonitor(window))
return GLFW_FALSE; return GLFW_FALSE;
if (wndconfig->centerCursor)
{
centerCursor(window); centerCursor(window);
} }
}
return GLFW_TRUE; return GLFW_TRUE;
} }

View File

@ -345,6 +345,9 @@ GLFWAPI void glfwWindowHint(int hint, int value)
case GLFW_COCOA_FRAME_AUTOSAVE: case GLFW_COCOA_FRAME_AUTOSAVE:
_glfw.hints.window.ns.frame = value ? GLFW_TRUE : GLFW_FALSE; _glfw.hints.window.ns.frame = value ? GLFW_TRUE : GLFW_FALSE;
break; break;
case GLFW_CENTER_CURSOR:
_glfw.hints.window.centerCursor = value ? GLFW_TRUE : GLFW_FALSE;
break;
case GLFW_CLIENT_API: case GLFW_CLIENT_API:
_glfw.hints.context.client = value; _glfw.hints.context.client = value;
break; break;

View File

@ -1597,8 +1597,11 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (!acquireMonitor(window)) if (!acquireMonitor(window))
return GLFW_FALSE; return GLFW_FALSE;
if(wndconfig->centerCursor)
{
centerCursor(window); centerCursor(window);
} }
}
XFlush(_glfw.x11.display); XFlush(_glfw.x11.display);
return GLFW_TRUE; return GLFW_TRUE;