mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-27 04:28:52 -05:00
Merge pull request #52 from nilium/osx-cursor-hidden-patch
Added support for hidden cursor mode on OS X.
This commit is contained in:
commit
dc58dd1bef
|
@ -48,6 +48,16 @@
|
||||||
|
|
||||||
@implementation GLFWWindowDelegate
|
@implementation GLFWWindowDelegate
|
||||||
|
|
||||||
|
static void resetMouseCursor(_GLFWwindow *window)
|
||||||
|
{
|
||||||
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
|
{
|
||||||
|
int width, height;
|
||||||
|
_glfwPlatformGetWindowSize(window, &width, &height);
|
||||||
|
_glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (id)initWithGlfwWindow:(_GLFWwindow *)initWindow
|
- (id)initWithGlfwWindow:(_GLFWwindow *)initWindow
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
@ -70,6 +80,8 @@
|
||||||
int width, height;
|
int width, height;
|
||||||
_glfwPlatformGetWindowSize(window, &width, &height);
|
_glfwPlatformGetWindowSize(window, &width, &height);
|
||||||
_glfwInputWindowSize(window, width, height);
|
_glfwInputWindowSize(window, width, height);
|
||||||
|
|
||||||
|
resetMouseCursor(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidMove:(NSNotification *)notification
|
- (void)windowDidMove:(NSNotification *)notification
|
||||||
|
@ -79,6 +91,8 @@
|
||||||
int x, y;
|
int x, y;
|
||||||
_glfwPlatformGetWindowPos(window, &x, &y);
|
_glfwPlatformGetWindowPos(window, &x, &y);
|
||||||
_glfwInputWindowPos(window, x, y);
|
_glfwInputWindowPos(window, x, y);
|
||||||
|
|
||||||
|
resetMouseCursor(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidMiniaturize:(NSNotification *)notification
|
- (void)windowDidMiniaturize:(NSNotification *)notification
|
||||||
|
@ -94,6 +108,8 @@
|
||||||
- (void)windowDidBecomeKey:(NSNotification *)notification
|
- (void)windowDidBecomeKey:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
_glfwInputWindowFocus(window, GL_TRUE);
|
_glfwInputWindowFocus(window, GL_TRUE);
|
||||||
|
|
||||||
|
resetMouseCursor(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidResignKey:(NSNotification *)notification
|
- (void)windowDidResignKey:(NSNotification *)notification
|
||||||
|
@ -293,6 +309,8 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
// Content view class for the GLFW window
|
// Content view class for the GLFW window
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static NSCursor *emptyCursor = nil;
|
||||||
|
|
||||||
@interface GLFWContentView : NSView
|
@interface GLFWContentView : NSView
|
||||||
{
|
{
|
||||||
_GLFWwindow* window;
|
_GLFWwindow* window;
|
||||||
|
@ -305,6 +323,16 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
|
|
||||||
@implementation GLFWContentView
|
@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
|
- (id)initWithGlfwWindow:(_GLFWwindow *)initWindow
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
@ -478,6 +506,11 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
_glfwInputScroll(window, deltaX, deltaY);
|
_glfwInputScroll(window, deltaX, deltaY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)resetCursorRects
|
||||||
|
{
|
||||||
|
[self addCursorRect:[self bounds] cursor:emptyCursor];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -913,16 +946,21 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
|
||||||
|
|
||||||
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
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)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case GLFW_CURSOR_NORMAL:
|
case GLFW_CURSOR_NORMAL:
|
||||||
[NSCursor unhide];
|
[window->ns.object disableCursorRects];
|
||||||
CGAssociateMouseAndMouseCursorPosition(true);
|
|
||||||
break;
|
break;
|
||||||
case GLFW_CURSOR_HIDDEN:
|
case GLFW_CURSOR_HIDDEN:
|
||||||
|
[window->ns.object enableCursorRects];
|
||||||
break;
|
break;
|
||||||
case GLFW_CURSOR_CAPTURED:
|
case GLFW_CURSOR_CAPTURED:
|
||||||
[NSCursor hide];
|
[window->ns.object enableCursorRects];
|
||||||
CGAssociateMouseAndMouseCursorPosition(false);
|
CGAssociateMouseAndMouseCursorPosition(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user