Improved mouse events on OS X regarding fullscreen mode

This commit is contained in:
Marco Antognini 2013-06-29 21:35:01 +02:00
parent 71f34600bc
commit eca4502424
3 changed files with 61 additions and 4 deletions

View File

@ -41,7 +41,10 @@ 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. /// NSTrackingArea is used to keep track of mouse events. We also
/// need to be able to ignore mouse event when exiting fullscreen.
/// The SFWindowController should call -[SFOpenGLView exitFullscreen]
/// and -[SFOpenGLView enterFullscreen] when appropriate.
/// ///
/// 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
@ -72,6 +75,13 @@ namespace sf {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
-(id)initWithFrame:(NSRect)frameRect; -(id)initWithFrame:(NSRect)frameRect;
////////////////////////////////////////////////////////////
/// Handle going in and out of fullscreen mode.
///
////////////////////////////////////////////////////////////
-(void)enterFullscreen;
-(void)exitFullscreen;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Apply the given resquester to the view. /// Apply the given resquester to the view.
/// ///

View File

@ -128,6 +128,39 @@ BOOL isValidTextUnicode(NSEvent* event);
} }
////////////////////////////////////////////////////////
-(void)enterFullscreen
{
// Remove the tracking area first,
// just to be sure we don't add it twice!
[self removeTrackingArea:m_trackingArea];
[self addTrackingArea:m_trackingArea];
// Fire an mouse entered event if needed
if (!m_mouseIsIn && m_requester != 0) {
m_requester->mouseMovedIn();
}
// Update status
m_mouseIsIn = YES;
}
////////////////////////////////////////////////////////
-(void)exitFullscreen
{
[self removeTrackingArea:m_trackingArea];
// Fire an mouse left event if needed
if (m_mouseIsIn && m_requester != 0) {
m_requester->mouseMovedOut();
}
// Update status
m_mouseIsIn = NO;
}
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
-(void)setRequesterTo:(sf::priv::WindowImplCocoa *)requester -(void)setRequesterTo:(sf::priv::WindowImplCocoa *)requester
{ {

View File

@ -211,9 +211,15 @@
} }
// If a fullscreen window was requested... // If a fullscreen window was requested...
if (style & sf::Style::Fullscreen && mode != sf::VideoMode::getDesktopMode()) { if (style & sf::Style::Fullscreen) {
/// ... we set the "real size" of the view (that is the back buffer size). /// ... we tell the OpenGL view
[m_oglView setRealSize:NSMakeSize(m_fullscreenMode->width, m_fullscreenMode->height)]; [m_oglView enterFullscreen];
// ... and if the resolution is not the default one...
if (mode != sf::VideoMode::getDesktopMode()) {
// ... we set the "real size" of the view (that is the back buffer size).
[m_oglView setRealSize:NSMakeSize(m_fullscreenMode->width, m_fullscreenMode->height)];
}
} }
// Set the view to the window as its content view. // Set the view to the window as its content view.
@ -496,6 +502,10 @@
if (m_requester == 0) return; if (m_requester == 0) return;
m_requester->windowGainedFocus(); m_requester->windowGainedFocus();
if (*m_fullscreenMode != sf::VideoMode()) {
[m_oglView enterFullscreen];
}
} }
@ -506,6 +516,10 @@
if (m_requester == 0) return; if (m_requester == 0) return;
m_requester->windowLostFocus(); m_requester->windowLostFocus();
if (*m_fullscreenMode != sf::VideoMode()) {
[m_oglView exitFullscreen];
}
} }