Improved mouse events on OS X (close #213, related to #277)

This commit is contained in:
Marco Antognini 2013-06-29 19:39:22 +02:00
parent aa4203fd54
commit 833837b427
2 changed files with 17 additions and 17 deletions

View File

@ -41,6 +41,8 @@ namespace sf {
/// ///
/// Handle event and send them back to the requester. /// 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 /// In order to send correct mouse coordonate to the requester when
/// the window is in fullscreen we use m_realSize to represent the /// the window is in fullscreen we use m_realSize to represent the
/// back buffer size (see SFWindowController). If 'm_realSize' is /// back buffer size (see SFWindowController). If 'm_realSize' is
@ -54,8 +56,8 @@ namespace sf {
@interface SFOpenGLView : NSOpenGLView { @interface SFOpenGLView : NSOpenGLView {
sf::priv::WindowImplCocoa* m_requester; sf::priv::WindowImplCocoa* m_requester;
BOOL m_useKeyRepeat; BOOL m_useKeyRepeat;
NSTrackingRectTag m_trackingTag;
BOOL m_mouseIsIn; BOOL m_mouseIsIn;
NSTrackingArea* m_trackingArea;
NSSize m_realSize; NSSize m_realSize;
// Hidden text view used to convert key event to actual chars. // Hidden text view used to convert key event to actual chars.

View File

@ -102,12 +102,14 @@ BOOL isValidTextUnicode(NSEvent* event);
[self enableKeyRepeat]; [self enableKeyRepeat];
m_realSize = NSZeroSize; m_realSize = NSZeroSize;
// Register for mouse-move event // Register for mouse move event
m_mouseIsIn = [self isMouseInside]; m_mouseIsIn = [self isMouseInside];
m_trackingTag = [self addTrackingRect:[self frame] NSUInteger opts = (NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingEnabledDuringMouseDrag);
owner:self m_trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
userData:nil options:opts
assumeInside:m_mouseIsIn]; owner:self
userInfo:nil];
[self addTrackingArea:m_trackingArea];
// Register for resize event // Register for resize event
NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
@ -194,13 +196,6 @@ BOOL isValidTextUnicode(NSEvent* event);
// Update mouse internal state. // Update mouse internal state.
[self updateMouseState]; [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. // Update the OGL view to fit the new size.
[self update]; [self update];
@ -249,14 +244,17 @@ BOOL isValidTextUnicode(NSEvent* event);
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
-(void)dealloc -(void)dealloc
{ {
// Unregister
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self removeTrackingArea:m_trackingArea];
// Release attributes // Release attributes
[m_hiddenTextView release]; [m_hiddenTextView release];
[m_silentResponder release]; [m_silentResponder release];
[m_trackingArea release];
[self setRequesterTo:0];
// Unregister
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self removeTrackingRect:m_trackingTag];
[super dealloc]; [super dealloc];
} }