Fixed problem with fullscreen/windowed display mode. Added check for Cocoa window import.

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1094 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
ceylo 2009-05-21 15:07:33 +00:00
parent 60e14e75b7
commit cb511644db
3 changed files with 82 additions and 51 deletions

View File

@ -44,6 +44,8 @@ static AppController *shared = nil;
@end
#endif
#define ENABLE_FADE_OPERATIONS 1
@implementation NSApplication (SFML)
- (void)setRunning:(BOOL)flag
@ -388,7 +390,7 @@ static AppController *shared = nil;
- (void)setFullscreenWindow:(WindowWrapper *)aWrapper mode:(sf::VideoMode *)fullscreenMode
{
// If we have a fullscreen window and want to remove it
if (myFullscreenWrapper && aWrapper == nil)
if (aWrapper == nil && myFullscreenWrapper)
{
// Get the CoreGraphics display mode according to the desktop mode
CFDictionaryRef displayMode = CGDisplayBestModeForParameters (kCGDirectMainDisplay,
@ -397,8 +399,10 @@ static AppController *shared = nil;
myDesktopMode.Height,
NULL);
#if ENABLE_FADE_OPERATIONS
// Fade to black screen
[self doFadeOperation:FillScreen time:0.2f sync:true];
#endif
// Switch to the desktop display mode
CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode);
@ -409,13 +413,15 @@ static AppController *shared = nil;
// Show the menu bar
[NSMenu setMenuBarVisible:YES];
#if ENABLE_FADE_OPERATIONS
// Fade to normal screen
[self doFadeOperation:CleanScreen time:0.5f sync:true];
#endif
// Release the saved window wrapper
[myFullscreenWrapper release], myFullscreenWrapper = nil;
myFullscreenWrapper = nil;
}
else if (myFullscreenWrapper == nil && aWrapper)
else if (aWrapper)
{
assert(fullscreenMode != NULL);
@ -426,24 +432,39 @@ static AppController *shared = nil;
fullscreenMode->Height,
NULL);
#if ENABLE_FADE_OPERATIONS
// Fade to a black screen
[self doFadeOperation:FillScreen time:0.5f sync:true];
#endif
// Hide to the main menu bar
if (!myFullscreenWrapper)
{
// Hide the main menu bar
[NSMenu setMenuBarVisible:NO];
}
if (myPrevMode != *fullscreenMode)
{
// Switch to the wished display mode
CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode);
}
if (myFullscreenWrapper)
{
[[myFullscreenWrapper window] close];
}
// Open and center the window
[[aWrapper window] makeKeyAndOrderFront:nil];
[[aWrapper window] center];
#if ENABLE_FADE_OPERATIONS
// Fade to normal screen
[self doFadeOperation:CleanScreen time:0.2f sync:false];
#endif
// Save the fullscreen wrapper
myFullscreenWrapper = [aWrapper retain];
myFullscreenWrapper = aWrapper;
}
else
{

View File

@ -502,10 +502,6 @@ static GLContext *sharedCtx = nil;
NSRect frame = NSMakeRect (0.0f, 0.0f, (float) mode.Width, (float) mode.Height);
unsigned int mask = 0;
// We grab options from WindowStyle and add them to our window mask
if (style & sf::Style::None || style & sf::Style::Fullscreen) {
mask |= NSBorderlessWindowMask;
if (style & sf::Style::Fullscreen) {
myIsFullscreen = true;
@ -534,6 +530,12 @@ static GLContext *sharedCtx = nil;
}
}
// We grab options from WindowStyle and add them to our window mask
if (style & sf::Style::None || style & sf::Style::Fullscreen) {
mask |= NSBorderlessWindowMask;
} else {
if (style & sf::Style::Titlebar) {
mask |= NSTitledWindowMask;
@ -638,9 +640,8 @@ static GLContext *sharedCtx = nil;
////////////////////////////////////////////////////////////
- (void)dealloc
{
// Remove the notification observer
if (myView)
[[NSNotificationCenter defaultCenter] removeObserver:myView];
[[NSNotificationCenter defaultCenter] removeObserver:self];
// Close the window

View File

@ -93,6 +93,14 @@ myWheelStatus(0.0f)
{
if (Handle)
{
if (![(NSWindow *)Handle isKindOfClass:[NSWindow class]])
std::cerr << "Cannot import this Window Handle because it is not a <NSWindow *> object"
<< "(or one of its subclasses). You gave a <"
<< [[(NSWindow *)Handle className] UTF8String]
<< "> object." << std::endl;
else
{
// We create the window according to the given handle
myWrapper = [[WindowWrapper alloc] initWithWindow:(NSWindow *)Handle
settings:params
@ -111,6 +119,7 @@ myWheelStatus(0.0f)
}
}
}
}
////////////////////////////////////////////////////////////