mirror of
https://github.com/glfw/glfw.git
synced 2024-11-10 09:01:46 +00:00
Add GLFW_CURSOR_HIDDEN.
Uses addCursorRect:cursor: as discussed.. well, too long ago. Anyhow, this will effectively hide the cursor while it is inside a window with GLFW_CURSOR_HIDDEN or GLFW_CURSOR_CAPTURED enabled. This shouldn't mess up cursor retain counts either, unlike previous uses of the hide/unhide methods on NSCursor. It does allocate a small, single-pixel image for an invisible cursor, as well as the cursor itself, but that shouldn't be too much trouble.
This commit is contained in:
parent
1f148f2bd6
commit
1ba8fd05c0
@ -309,6 +309,8 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
// Content view class for the GLFW window
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
static NSCursor *emptyCursor = nil;
|
||||
|
||||
@interface GLFWContentView : NSView
|
||||
{
|
||||
_GLFWwindow* window;
|
||||
@ -321,6 +323,16 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
@implementation GLFWContentView
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
if (self == [GLFWContentView class])
|
||||
{
|
||||
NSImage *emptyImage = [[NSImage alloc] initWithSize:NSMakeSize(1, 1)];
|
||||
emptyCursor = [[NSCursor alloc] initWithImage:emptyImage hotSpot:NSZeroPoint];
|
||||
[emptyImage release];
|
||||
}
|
||||
}
|
||||
|
||||
- (id)initWithGlfwWindow:(_GLFWwindow *)initWindow
|
||||
{
|
||||
self = [super init];
|
||||
@ -494,6 +506,11 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
_glfwInputScroll(window, deltaX, deltaY);
|
||||
}
|
||||
|
||||
- (void)resetCursorRects
|
||||
{
|
||||
[self addCursorRect:[self bounds] cursor:emptyCursor];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@ -929,16 +946,21 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
|
||||
|
||||
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
||||
{
|
||||
// Unhide the cursor if the last mode was CAPTURED.
|
||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED) {
|
||||
CGAssociateMouseAndMouseCursorPosition(true);
|
||||
}
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case GLFW_CURSOR_NORMAL:
|
||||
[NSCursor unhide];
|
||||
CGAssociateMouseAndMouseCursorPosition(true);
|
||||
[window->ns.object disableCursorRects];
|
||||
break;
|
||||
case GLFW_CURSOR_HIDDEN:
|
||||
[window->ns.object enableCursorRects];
|
||||
break;
|
||||
case GLFW_CURSOR_CAPTURED:
|
||||
[NSCursor hide];
|
||||
[window->ns.object enableCursorRects];
|
||||
CGAssociateMouseAndMouseCursorPosition(false);
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user