Improved OS X implementation

It makes sure the notifications sent to SFOpenGLView are only from its window.
This commit is contained in:
Marco Antognini 2014-05-26 15:31:45 +02:00
parent 7d4235a38f
commit 3f61214571
4 changed files with 50 additions and 25 deletions

View File

@ -69,6 +69,8 @@ namespace sf {
/// NB: -initWithFrame: is also implemented to default isFullscreen to NO
/// in case SFOpenGLView is created with the standard message.
///
/// To finish the initialization -finishInit should be called too.
///
/// \param frameRect dimension of the view
/// \param isFullscreen fullscreen flag
///
@ -77,6 +79,14 @@ namespace sf {
////////////////////////////////////////////////////////////
-(id)initWithFrame:(NSRect)frameRect fullscreen:(BOOL)isFullscreen;
////////////////////////////////////////////////////////////
/// \brief Finish the creation of the SFML OpenGL view
///
/// This method should be called after the view was added to a window
///
////////////////////////////////////////////////////////////
-(void)finishInit;
////////////////////////////////////////////////////////////
/// \brief Apply the given requester to the view
///

View File

@ -160,8 +160,27 @@ BOOL isValidTextUnicode(NSEvent* event);
[self addTrackingArea:m_trackingArea];
m_fullscreen = isFullscreen;
[self updateScaleFactor];
m_scaleFactor = 1.0; // Default value; it will be updated in finishInit
// Create a hidden text view for parsing key down event properly
m_silentResponder = [[SFSilentResponder alloc] init];
m_hiddenTextView = [[NSTextView alloc] initWithFrame:NSZeroRect];
[m_hiddenTextView setNextResponder:m_silentResponder];
// Request high resolution on high DPI displays
[self setWantsBestResolutionOpenGLSurface:YES];
// At that point, the view isn't attached to a window. We defer the rest of
// the initialization process to later.
}
return self;
}
////////////////////////////////////////////////////////
-(void)finishInit
{
// Register for window focus events
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(windowDidBecomeKey:)
@ -186,16 +205,8 @@ BOOL isValidTextUnicode(NSEvent* event);
name:NSWindowDidChangeScreenProfileNotification
object:[self window]];
// Create a hidden text view for parsing key down event properly
m_silentResponder = [[SFSilentResponder alloc] init];
m_hiddenTextView = [[NSTextView alloc] initWithFrame:NSZeroRect];
[m_hiddenTextView setNextResponder:m_silentResponder];
// Request high resolution on high DPI displays
[self setWantsBestResolutionOpenGLSurface:YES];
}
return self;
// Now that we have a window, set up correctly the scale factor
[self updateScaleFactor];
}

View File

@ -71,6 +71,8 @@
[m_view addSubview:m_oglView];
[m_oglView setAutoresizingMask:[m_view autoresizingMask]];
[m_oglView finishInit];
}
return self;

View File

@ -149,6 +149,8 @@
[self setupFullscreenViewWithMode:mode];
else
[self setupWindowWithMode:mode andStyle:style];
[m_oglView finishInit];
}
return self;
}