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.
///
/// 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.

View File

@ -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]
NSUInteger opts = (NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingEnabledDuringMouseDrag);
m_trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
options:opts
owner:self
userData:nil
assumeInside:m_mouseIsIn];
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,13 +244,16 @@ 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];
// Unregister
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self removeTrackingRect:m_trackingTag];
[self setRequesterTo:0];
[super dealloc];
}