Improved OS X implementation
It makes sure the notifications sent to SFOpenGLView are only from its window.
This commit is contained in:
parent
7d4235a38f
commit
3f61214571
@ -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
|
||||
///
|
||||
|
@ -160,31 +160,7 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
[self addTrackingArea:m_trackingArea];
|
||||
|
||||
m_fullscreen = isFullscreen;
|
||||
[self updateScaleFactor];
|
||||
|
||||
// Register for window focus events
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(windowDidBecomeKey:)
|
||||
name:NSWindowDidBecomeKeyNotification
|
||||
object:[self window]];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(windowDidResignKey:)
|
||||
name:NSWindowDidResignKeyNotification
|
||||
object:[self window]];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(windowDidResignKey:)
|
||||
name:NSWindowWillCloseNotification
|
||||
object:[self window]];
|
||||
|
||||
// Register for changed screen and changed screen's profile events
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(updateScaleFactor)
|
||||
name:NSWindowDidChangeScreenNotification
|
||||
object:[self window]];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(updateScaleFactor)
|
||||
name:NSWindowDidChangeScreenProfileNotification
|
||||
object:[self window]];
|
||||
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];
|
||||
@ -193,12 +169,47 @@ BOOL isValidTextUnicode(NSEvent* event);
|
||||
|
||||
// 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:)
|
||||
name:NSWindowDidBecomeKeyNotification
|
||||
object:[self window]];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(windowDidResignKey:)
|
||||
name:NSWindowDidResignKeyNotification
|
||||
object:[self window]];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(windowDidResignKey:)
|
||||
name:NSWindowWillCloseNotification
|
||||
object:[self window]];
|
||||
|
||||
// Register for changed screen and changed screen's profile events
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(updateScaleFactor)
|
||||
name:NSWindowDidChangeScreenNotification
|
||||
object:[self window]];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(updateScaleFactor)
|
||||
name:NSWindowDidChangeScreenProfileNotification
|
||||
object:[self window]];
|
||||
|
||||
// Now that we have a window, set up correctly the scale factor
|
||||
[self updateScaleFactor];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
-(void)setRequesterTo:(sf::priv::WindowImplCocoa*)requester
|
||||
{
|
||||
|
@ -71,6 +71,8 @@
|
||||
[m_view addSubview:m_oglView];
|
||||
|
||||
[m_oglView setAutoresizingMask:[m_view autoresizingMask]];
|
||||
|
||||
[m_oglView finishInit];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -149,6 +149,8 @@
|
||||
[self setupFullscreenViewWithMode:mode];
|
||||
else
|
||||
[self setupWindowWithMode:mode andStyle:style];
|
||||
|
||||
[m_oglView finishInit];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user