From 833837b4278e6e9da980ce4130d8a18a89117267 Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Sat, 29 Jun 2013 19:39:22 +0200 Subject: [PATCH] Improved mouse events on OS X (close #213, related to #277) --- src/SFML/Window/OSX/SFOpenGLView.h | 4 +++- src/SFML/Window/OSX/SFOpenGLView.mm | 30 ++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/SFML/Window/OSX/SFOpenGLView.h b/src/SFML/Window/OSX/SFOpenGLView.h index 6cb15895e..a09d0df56 100644 --- a/src/SFML/Window/OSX/SFOpenGLView.h +++ b/src/SFML/Window/OSX/SFOpenGLView.h @@ -41,6 +41,8 @@ namespace sf { /// /// Handle event and send them back to the requester. /// +/// NSTrackingArea is used to keep track of mouse events. +/// /// In order to send correct mouse coordonate to the requester when /// the window is in fullscreen we use m_realSize to represent the /// back buffer size (see SFWindowController). If 'm_realSize' is @@ -54,8 +56,8 @@ namespace sf { @interface SFOpenGLView : NSOpenGLView { sf::priv::WindowImplCocoa* m_requester; BOOL m_useKeyRepeat; - NSTrackingRectTag m_trackingTag; BOOL m_mouseIsIn; + NSTrackingArea* m_trackingArea; NSSize m_realSize; // Hidden text view used to convert key event to actual chars. diff --git a/src/SFML/Window/OSX/SFOpenGLView.mm b/src/SFML/Window/OSX/SFOpenGLView.mm index 0e5d6f456..2f15524a9 100644 --- a/src/SFML/Window/OSX/SFOpenGLView.mm +++ b/src/SFML/Window/OSX/SFOpenGLView.mm @@ -102,12 +102,14 @@ BOOL isValidTextUnicode(NSEvent* event); [self enableKeyRepeat]; m_realSize = NSZeroSize; - // Register for mouse-move event + // Register for mouse move event m_mouseIsIn = [self isMouseInside]; - m_trackingTag = [self addTrackingRect:[self frame] - owner:self - userData:nil - assumeInside:m_mouseIsIn]; + NSUInteger opts = (NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingEnabledDuringMouseDrag); + m_trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds] + options:opts + owner:self + userInfo:nil]; + [self addTrackingArea:m_trackingArea]; // Register for resize event NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; @@ -194,13 +196,6 @@ BOOL isValidTextUnicode(NSEvent* event); // Update mouse internal state. [self updateMouseState]; - // Adapt tracking area for mouse mouse event. - [self removeTrackingRect:m_trackingTag]; - m_trackingTag = [self addTrackingRect:[self frame] - owner:self - userData:nil - assumeInside:m_mouseIsIn]; - // Update the OGL view to fit the new size. [self update]; @@ -249,14 +244,17 @@ BOOL isValidTextUnicode(NSEvent* event); //////////////////////////////////////////////////////// -(void)dealloc { + // Unregister + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [self removeTrackingArea:m_trackingArea]; + // Release attributes [m_hiddenTextView release]; [m_silentResponder release]; + [m_trackingArea release]; + + [self setRequesterTo:0]; - // Unregister - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [self removeTrackingRect:m_trackingTag]; - [super dealloc]; }