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 @end
#endif #endif
#define ENABLE_FADE_OPERATIONS 1
@implementation NSApplication (SFML) @implementation NSApplication (SFML)
- (void)setRunning:(BOOL)flag - (void)setRunning:(BOOL)flag
@ -388,7 +390,7 @@ static AppController *shared = nil;
- (void)setFullscreenWindow:(WindowWrapper *)aWrapper mode:(sf::VideoMode *)fullscreenMode - (void)setFullscreenWindow:(WindowWrapper *)aWrapper mode:(sf::VideoMode *)fullscreenMode
{ {
// If we have a fullscreen window and want to remove it // 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 // Get the CoreGraphics display mode according to the desktop mode
CFDictionaryRef displayMode = CGDisplayBestModeForParameters (kCGDirectMainDisplay, CFDictionaryRef displayMode = CGDisplayBestModeForParameters (kCGDirectMainDisplay,
@ -397,8 +399,10 @@ static AppController *shared = nil;
myDesktopMode.Height, myDesktopMode.Height,
NULL); NULL);
#if ENABLE_FADE_OPERATIONS
// Fade to black screen // Fade to black screen
[self doFadeOperation:FillScreen time:0.2f sync:true]; [self doFadeOperation:FillScreen time:0.2f sync:true];
#endif
// Switch to the desktop display mode // Switch to the desktop display mode
CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode); CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode);
@ -409,13 +413,15 @@ static AppController *shared = nil;
// Show the menu bar // Show the menu bar
[NSMenu setMenuBarVisible:YES]; [NSMenu setMenuBarVisible:YES];
#if ENABLE_FADE_OPERATIONS
// Fade to normal screen // Fade to normal screen
[self doFadeOperation:CleanScreen time:0.5f sync:true]; [self doFadeOperation:CleanScreen time:0.5f sync:true];
#endif
// Release the saved window wrapper // Release the saved window wrapper
[myFullscreenWrapper release], myFullscreenWrapper = nil; myFullscreenWrapper = nil;
} }
else if (myFullscreenWrapper == nil && aWrapper) else if (aWrapper)
{ {
assert(fullscreenMode != NULL); assert(fullscreenMode != NULL);
@ -426,24 +432,39 @@ static AppController *shared = nil;
fullscreenMode->Height, fullscreenMode->Height,
NULL); NULL);
#if ENABLE_FADE_OPERATIONS
// Fade to a black screen // Fade to a black screen
[self doFadeOperation:FillScreen time:0.5f sync:true]; [self doFadeOperation:FillScreen time:0.5f sync:true];
#endif
// Hide to the main menu bar if (!myFullscreenWrapper)
[NSMenu setMenuBarVisible:NO]; {
// Hide the main menu bar
[NSMenu setMenuBarVisible:NO];
}
// Switch to the wished display mode if (myPrevMode != *fullscreenMode)
CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode); {
// Switch to the wished display mode
CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode);
}
if (myFullscreenWrapper)
{
[[myFullscreenWrapper window] close];
}
// Open and center the window // Open and center the window
[[aWrapper window] makeKeyAndOrderFront:nil]; [[aWrapper window] makeKeyAndOrderFront:nil];
[[aWrapper window] center]; [[aWrapper window] center];
#if ENABLE_FADE_OPERATIONS
// Fade to normal screen // Fade to normal screen
[self doFadeOperation:CleanScreen time:0.2f sync:false]; [self doFadeOperation:CleanScreen time:0.2f sync:false];
#endif
// Save the fullscreen wrapper // Save the fullscreen wrapper
myFullscreenWrapper = [aWrapper retain]; myFullscreenWrapper = aWrapper;
} }
else else
{ {
@ -453,7 +474,7 @@ static AppController *shared = nil;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Perform fade operation where 'operation' is one of { FillScreen, CleanScreen} /// Perform fade operation where 'operation' is one of {FillScreen, CleanScreen}
/// and 'time' is the time during which you wish the operation to be performed. /// and 'time' is the time during which you wish the operation to be performed.
/// Set 'sync' to true if you do not want the method to end before the end /// Set 'sync' to true if you do not want the method to end before the end
/// of the fade operation. Pass the last used token or a new one if you are /// of the fade operation. Pass the last used token or a new one if you are

View File

@ -502,37 +502,39 @@ static GLContext *sharedCtx = nil;
NSRect frame = NSMakeRect (0.0f, 0.0f, (float) mode.Width, (float) mode.Height); NSRect frame = NSMakeRect (0.0f, 0.0f, (float) mode.Width, (float) mode.Height);
unsigned int mask = 0; unsigned int mask = 0;
if (style & sf::Style::Fullscreen) {
myIsFullscreen = true;
// Check display mode and put new values in 'mode' if needed
boolean_t exact = true;
CFDictionaryRef properties = CGDisplayBestModeForParameters(kCGDirectMainDisplay, mode.BitsPerPixel,
mode.Width, mode.Height, &exact);
if (!properties) {
std::cerr << "Unable to get a display mode with the given parameters" << std::endl;
[self autorelease];
return nil;
}
if (exact == false) {
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayWidth),
kCFNumberIntType, &mode.Width);
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayHeight),
kCFNumberIntType, &mode.Height);
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayBitsPerPixel),
kCFNumberIntType, &mode.BitsPerPixel);
}
}
// We grab options from WindowStyle and add them to our window mask // We grab options from WindowStyle and add them to our window mask
if (style & sf::Style::None || style & sf::Style::Fullscreen) { if (style & sf::Style::None || style & sf::Style::Fullscreen) {
mask |= NSBorderlessWindowMask; mask |= NSBorderlessWindowMask;
if (style & sf::Style::Fullscreen) {
myIsFullscreen = true;
// Check display mode and put new values in 'mode' if needed
boolean_t exact = true;
CFDictionaryRef properties = CGDisplayBestModeForParameters(kCGDirectMainDisplay, mode.BitsPerPixel,
mode.Width, mode.Height, &exact);
if (!properties) {
std::cerr << "Unable to get a display mode with the given parameters" << std::endl;
[self autorelease];
return nil;
}
if (exact == false) {
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayWidth),
kCFNumberIntType, &mode.Width);
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayHeight),
kCFNumberIntType, &mode.Height);
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayBitsPerPixel),
kCFNumberIntType, &mode.BitsPerPixel);
}
}
} else { } else {
if (style & sf::Style::Titlebar) { if (style & sf::Style::Titlebar) {
@ -638,9 +640,8 @@ static GLContext *sharedCtx = nil;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
- (void)dealloc - (void)dealloc
{ {
// Remove the notification observer // Remove the notification observer
if (myView)
[[NSNotificationCenter defaultCenter] removeObserver:myView];
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
// Close the window // Close the window

View File

@ -93,21 +93,30 @@ myWheelStatus(0.0f)
{ {
if (Handle) if (Handle)
{ {
// We create the window according to the given handle if (![(NSWindow *)Handle isKindOfClass:[NSWindow class]])
myWrapper = [[WindowWrapper alloc] initWithWindow:(NSWindow *)Handle std::cerr << "Cannot import this Window Handle because it is not a <NSWindow *> object"
settings:params << "(or one of its subclasses). You gave a <"
delegate:this]; << [[(NSWindow *)Handle className] UTF8String]
<< "> object." << std::endl;
if (myWrapper) else
{ {
// initial mouse state
myMouseIn = [myWrapper mouseInside];
// We set the myWidth and myHeight members to the correct values // We create the window according to the given handle
myWidth = (int) [[myWrapper glView] frame].size.width; myWrapper = [[WindowWrapper alloc] initWithWindow:(NSWindow *)Handle
myHeight = (int) [[myWrapper glView] frame].size.height; settings:params
} else { delegate:this];
std::cerr << "Failed to make the public window" << std::endl;
if (myWrapper)
{
// initial mouse state
myMouseIn = [myWrapper mouseInside];
// We set the myWidth and myHeight members to the correct values
myWidth = (int) [[myWrapper glView] frame].size.width;
myHeight = (int) [[myWrapper glView] frame].size.height;
} else {
std::cerr << "Failed to make the public window" << std::endl;
}
} }
} }
} }