From 8e4e70d7a476d285dc4c46ee03b8766aa75eab5b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 14:46:42 +0200 Subject: [PATCH] Implemented cursor enter/leave for OS X. --- src/cocoa_window.m | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 98c220ed..5cd7ee3e 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -292,6 +292,7 @@ static int convertMacKeyCode(unsigned int macKeyCode) @interface GLFWContentView : NSView { _GLFWwindow* window; + NSTrackingArea* trackingArea; } - (id)initWithGlfwWindow:(_GLFWwindow *)initWindow; @@ -304,11 +305,22 @@ static int convertMacKeyCode(unsigned int macKeyCode) { self = [super init]; if (self != nil) + { window = initWindow; + trackingArea = nil; + + [self updateTrackingAreas]; + } return self; } +-(void)dealloc +{ + [trackingArea release]; + [super dealloc]; +} + - (BOOL)isOpaque { return YES; @@ -384,6 +396,36 @@ static int convertMacKeyCode(unsigned int macKeyCode) _glfwInputMouseClick(window, [event buttonNumber], GLFW_RELEASE); } +- (void)mouseExited:(NSEvent *)event +{ + _glfwInputCursorEnter(window, GL_FALSE); +} + +- (void)mouseEntered:(NSEvent *)event +{ + _glfwInputCursorEnter(window, GL_TRUE); +} + +- (void)updateTrackingAreas +{ + if (trackingArea != nil) + { + [self removeTrackingArea:trackingArea]; + [trackingArea release]; + } + + NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | + NSTrackingActiveAlways | + NSTrackingInVisibleRect; + + trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds] + options:options + owner:self + userInfo:nil]; + + [self addTrackingArea:trackingArea]; +} + - (void)keyDown:(NSEvent *)event { NSUInteger i, length;