Back to index

libsfml  1.6+dfsg2
Public Member Functions | Static Public Member Functions | Protected Attributes
sfPrivAppController Class Reference

#import <AppController.h>

Collaboration diagram for sfPrivAppController:
Collaboration graph
[legend]

List of all members.

Public Member Functions

(void) - setNotifications
 Reset notifictions about application focus /////////////////////////////////////////////////////////.
(void) - makeMenuBar
 Make the menu bar /////////////////////////////////////////////////////////.
(void) - processEvents
 Process all the events and send them to the application No event is processed if the AppController instance is not the owner of the event loop (ie: user made his own loop) /////////////////////////////////////////////////////////.
(void) - setFullscreenWindow:mode:
 Set as the current fullscreen window Change the screen resolution if needed according to and /////////////////////////////////////////////////////////.
(void) - doFadeOperation:time:sync:
 Perform fade operation where 'operation' is one of { FillScreen, CleanScreen} 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 of the fade operation. /////////////////////////////////////////////////////////.
(const sf::VideoMode &) - desktopMode
 Return the desktop video mode (made at the instance initialization) /////////////////////////////////////////////////////////.
(id) - init [implementation]
 Return an initialized AppController instance Save the desktop mode Make the main autorelease pool Set the application observer /////////////////////////////////////////////////////////.
(void) - dealloc [implementation]
 Clean the controller /////////////////////////////////////////////////////////.
(void) - applicationWillDeactivate: [implementation]
 Hide all the fullscreen windows and switch back to the desktop display mode /////////////////////////////////////////////////////////.
(void) - applicationWillActivate: [implementation]
 Unhide all the fullscreen windows and switch to full screen display mode /////////////////////////////////////////////////////////.
(void) - applicationWillTerminate: [implementation]

Static Public Member Functions

(sfPrivAppController *) + sharedController
 Return the shared AppController instance. Make one if needed. /////////////////////////////////////////////////////////.
(CGDirectDisplayID) + primaryScreen
 Returns the primay computer's screen /////////////////////////////////////////////////////////.

Protected Attributes

BOOL myOwningEventLoop
sfPrivWindowmyFullscreenWrapper
NSAutoreleasePool * myMainPool
sf::VideoMode myDesktopMode
sf::VideoMode myPrevMode

Detailed Description

Definition at line 40 of file AppController.h.


Member Function Documentation

- (void) applicationWillActivate: (NSNotification *)  aNotification [implementation]

Unhide all the fullscreen windows and switch to full screen display mode /////////////////////////////////////////////////////////.

Definition at line 213 of file AppController.mm.

                               :(NSNotification *)aNotification
{
       if (myFullscreenWrapper) {
              CFDictionaryRef displayMode = CGDisplayBestModeForParameters ([sfPrivAppController primaryScreen],
                                                                                                                         myPrevMode.BitsPerPixel,
                                                                                                                         myPrevMode.Width,
                                                                                                                         myPrevMode.Height,
                                                                                                                         NULL);
              [NSMenu setMenuBarVisible:NO];
              
              // Switch to the wished display mode
              CGDisplaySwitchToMode([sfPrivAppController primaryScreen], displayMode);
              
              // Show the fullscreen window if existing
              if (myFullscreenWrapper)
              {
                     [[myFullscreenWrapper window] setAlphaValue:1.0f];
                     [[myFullscreenWrapper window] center];
                     [[myFullscreenWrapper window] makeKeyAndOrderFront:self];
              }
       }
}

Here is the call graph for this function:

- (void) applicationWillDeactivate: (NSNotification *)  aNotification [implementation]

Hide all the fullscreen windows and switch back to the desktop display mode /////////////////////////////////////////////////////////.

Definition at line 189 of file AppController.mm.

                                 :(NSNotification *)aNotification
{
       // Note: not using fading because it produces reactivation issues
       if (myFullscreenWrapper) {
              myPrevMode = sf::VideoMode::GetDesktopMode();
              
              CFDictionaryRef displayMode = CGDisplayBestModeForParameters ([sfPrivAppController primaryScreen],
                                                                                                                         myDesktopMode.BitsPerPixel,
                                                                                                                         myDesktopMode.Width,
                                                                                                                         myDesktopMode.Height,
                                                                                                                         NULL);
              
              // Make the full screen window unvisible
              [[myFullscreenWrapper window] setAlphaValue:0.0f];
              
              // Switch to the wished display mode
              CGDisplaySwitchToMode([sfPrivAppController primaryScreen], displayMode);
       }
}

Here is the call graph for this function:

- (void) applicationWillTerminate: (NSNotification *)  aNotification [implementation]

Definition at line 237 of file AppController.mm.

                                :(NSNotification *)aNotification
{
       if (myFullscreenWrapper)
              [self setFullscreenWindow:nil mode:NULL];
}

Here is the call graph for this function:

- (void) dealloc [implementation]

Clean the controller /////////////////////////////////////////////////////////.

Definition at line 121 of file AppController.mm.

{
       [[NSNotificationCenter defaultCenter] removeObserver:self];
       [myMainPool release];
       [super dealloc];
}
- (const VideoMode &) sfPrivAppController:

Return the desktop video mode (made at the instance initialization) /////////////////////////////////////////////////////////.

Definition at line 572 of file AppController.mm.

{
       return myDesktopMode;
}
- (void) doFadeOperation: (int)  operation
time: (float)  time
sync: (bool)  sync 

Perform fade operation where 'operation' is one of { FillScreen, CleanScreen} 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 of the fade operation. /////////////////////////////////////////////////////////.

Perform fade operation where 'operation' is one of {FillScreen, CleanScreen} 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 of the fade operation. Pass the last used token or a new one if you are using this method for the first time. This lets the method release some resources when doing CleanScreen operation. /////////////////////////////////////////////////////////.

Definition at line 503 of file AppController.mm.

                        :(int)operation time:(float)time sync:(bool)sync
{
       static CGDisplayFadeReservationToken prevToken = kCGDisplayFadeReservationInvalidToken;
       CGDisplayFadeReservationToken token = prevToken;
       
       CGError result = 0, capture = 0;
       
       if (operation == FillScreen) {
              // Get access for the fade operation
              result = CGAcquireDisplayFadeReservation((int)(3 + time), &token);
              
              if (!result) {
                     // Capture display but do not fill the screen with black
                     // so that we can see the fade operation
                     capture = CGDisplayCaptureWithOptions([sfPrivAppController primaryScreen], kCGCaptureNoFill);
                     
                     if (!capture) {
                            // Do the increasing fade operation
                            CGDisplayFade(token, time,
                                                   kCGDisplayBlendNormal,
                                                   kCGDisplayBlendSolidColor,
                                                   0.0f, 0.0f, 0.0f, sync);
                            
                            // Now, release the non black-filling capture
                            CGDisplayRelease([sfPrivAppController primaryScreen]);
                            
                            // And capture with filling
                            // so that we don't see the switching in the meantime
                            CGDisplayCaptureWithOptions([sfPrivAppController primaryScreen], kCGCaptureNoOptions);
                     }
                     
                     prevToken = token;
              }
       } else if (operation == CleanScreen) {
              // Get access for the fade operation
              if (token == kCGDisplayFadeReservationInvalidToken)
                     result = CGAcquireDisplayFadeReservation((int)(3 + time), &token);
              
              if (!result) {
                     if (!capture) {
                            // Release the black-filling capture
                            CGDisplayRelease([sfPrivAppController primaryScreen]);
                            
                            // Capture the display but do not fill with black (still for the fade operation)
                            CGDisplayCaptureWithOptions([sfPrivAppController primaryScreen], kCGCaptureNoFill);
                            
                            // Do the decreasing fading
                            CGDisplayFade(token, time,
                                                   kCGDisplayBlendSolidColor,
                                                   kCGDisplayBlendNormal,
                                                   0.0f, 0.0f, 0.0f, sync);
                            
                            // Release the fade operation token
                            CGReleaseDisplayFadeReservation(token);
                            
                            // Invalidate the given token
                            prevToken = kCGDisplayFadeReservationInvalidToken;
                     }
                     
                     // Release the captured display
                     CGDisplayRelease([sfPrivAppController primaryScreen]);
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

- (id) init [implementation]

Return an initialized AppController instance Save the desktop mode Make the main autorelease pool Set the application observer /////////////////////////////////////////////////////////.

Definition at line 69 of file AppController.mm.

{
       self = [super init];
       
       if (self != nil) {
              myOwningEventLoop = NO;
              
              // Save the desktop mode
              myDesktopMode = sf::VideoMode::GetDesktopMode();
              myPrevMode = myDesktopMode;
              
              // Make the app autorelease pool
              myMainPool = [[NSAutoreleasePool alloc] init];
              
              if (!myMainPool) {
                     [self release];
                     throw std::bad_alloc();
              }
              
              // Don't go on if the user handles the app
              if (![NSApp isRunning])
              {
                     // Force our application to appear in the Dock and make it able
                     // to get focus (even when it's a raw executable)
                     ProcessSerialNumber psn;
                     
                     if (!GetCurrentProcess(&psn)) {
                            TransformProcessType(&psn, kProcessTransformToForegroundApplication);
                            SetFrontProcess(&psn);
                     }
                     
                     // Make the app
                     if (![NSApplication sharedApplication]) {
                            [self release];
                            throw std::bad_alloc();
                     }
                     
                     [self setNotifications];
                     
                     if ([NSApp mainMenu] == nil) {
                            [self makeMenuBar];
                     }
              }
       }
       
       return self;
}

Here is the call graph for this function:

- (void) makeMenuBar

Make the menu bar /////////////////////////////////////////////////////////.

Make menu bar /////////////////////////////////////////////////////////.

Definition at line 246 of file AppController.mm.

{
       // Source taken from SDL 1.3
       NSString *appName = nil;
       NSString *title = nil;
       NSMenu *appleMenu = nil;
       NSMenu *fileMenu = nil;
       NSMenu *windowMenu = nil;
       NSMenuItem *menuItem = nil;
       NSMenuItem *quitMenuItem = nil;
       
       // Determine the application name
       appName = [[[NSBundle mainBundle] infoDictionary] objectForKey: @"CFBundleName"];
       
       if (![appName length])
              appName = [[NSProcessInfo processInfo] processName];
       
       
       // Create the main menu bar
       [NSApp setMainMenu:[[NSMenu alloc] init]];
       
       // Create the application menu
       appleMenu = [[NSMenu alloc] initWithTitle:@""];
       
       // Put menu items
       // + 'About' menu item
       title = [@"About " stringByAppendingString:appName];
       [appleMenu addItemWithTitle:title
                                           action:@selector(orderFrontStandardAboutPanel:)
                              keyEquivalent:@""];
       
       [appleMenu addItem:[NSMenuItem separatorItem]];
       
       // + 'Hide' menu item
       title = [@"Hide " stringByAppendingString:appName];
       [appleMenu addItemWithTitle:title
                                           action:@selector(hide:)
                              keyEquivalent:@"h"];
       
       // + 'Hide other' menu item
       menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others"
                                                                                      action:@selector(hideOtherApplications:)
                                                                         keyEquivalent:@"h"];
       [menuItem setKeyEquivalentModifierMask:NSAlternateKeyMask | NSCommandKeyMask];
       
       // + 'Show all' menu item
       [appleMenu addItemWithTitle:@"Show All"
                                           action:@selector(unhideAllApplications:)
                              keyEquivalent:@""];
       
       [appleMenu addItem:[NSMenuItem separatorItem]];
       
       // + 'Quit' menu item
       title = [@"Quit " stringByAppendingString:appName];
       quitMenuItem = [[[NSMenuItem alloc]
                                    initWithTitle:title 
                                    action:@selector(terminate:)
                                    keyEquivalent:@"q"] autorelease];
       //[quitMenuItem setTarget:self];
       [appleMenu addItem:quitMenuItem];
       
       // Put the menu into the menubar
       menuItem = [[NSMenuItem alloc]
                            initWithTitle:@""
                            action:nil
                            keyEquivalent:@""];
       [menuItem setSubmenu:appleMenu];
       [[NSApp mainMenu] addItem:menuItem];
       [menuItem release];
       
       // Tell the application object that this is now the application menu
       [NSApp setAppleMenu:appleMenu];
       [appleMenu release];
       
       // 'File' menu
       fileMenu = [[NSMenu alloc]
                            initWithTitle:@"File"];
       
       // + 'Close' menu item
       menuItem = [[NSMenuItem alloc]
                            initWithTitle:@"Close"
                            action:@selector(performClose:)
                            keyEquivalent:@"w"];
       [fileMenu addItem:menuItem];
       [menuItem release];
       
       // + 'File' menu item (head)
       menuItem = [[NSMenuItem alloc]
                            initWithTitle:@"File"
                            action:nil
                            keyEquivalent:@""];
       [menuItem setSubmenu:fileMenu];
       [[NSApp mainMenu] addItem:menuItem];
       [menuItem release];
       
       // 'Window' menu
       windowMenu = [[NSMenu alloc]
                              initWithTitle:@"Window"];
       
       // + 'Minimize' menu item
       menuItem = [[NSMenuItem alloc]
                            initWithTitle:@"Minimize"
                            action:@selector(performMiniaturize:)
                            keyEquivalent:@"m"];
       [windowMenu addItem:menuItem];
       [menuItem release];
       
       // + 'Window' menu item (head)
       menuItem = [[NSMenuItem alloc]
                            initWithTitle:@"Window"
                            action:nil keyEquivalent:@""];
       [menuItem setSubmenu:windowMenu];
       [[NSApp mainMenu] addItem:menuItem];
       [menuItem release];
       
       // Tell the application object that this is now the window menu
       [NSApp setWindowsMenu:windowMenu];
       [windowMenu release];
}

Here is the caller graph for this function:

+ (CGDirectDisplayID) primaryScreen

Returns the primay computer's screen /////////////////////////////////////////////////////////.

Definition at line 143 of file AppController.mm.

{
       static BOOL firstTime = YES;
       static CGDirectDisplayID screen = kCGNullDirectDisplay;
       
       if (firstTime) {
              CGDisplayCount numScr;
              CGDisplayErr err = CGGetDisplaysWithPoint(CGPointMake(0, 0), 1, &screen, &numScr);
              
              if (err != kCGErrorSuccess || numScr < 1) {
                     std::cerr << "Unable to get primary screen (error code " << err 
                     << " ). Using the main screen.";
                     screen = CGMainDisplayID();
              }
              firstTime = NO;
       }
       
       return screen;
}

Here is the caller graph for this function:

- (void) processEvents

Process all the events and send them to the application No event is processed if the AppController instance is not the owner of the event loop (ie: user made his own loop) /////////////////////////////////////////////////////////.

Definition at line 372 of file AppController.mm.

{
       // Check there is a run loop
       if (![NSApp isRunning])
       {
              // Get the ownershipt of event handling if not and run
              [NSApp finishLaunching];
              [NSApp setRunning:YES];
              myOwningEventLoop = YES;
       }
       
       NSEvent *event = nil;
       
       if (myOwningEventLoop)
       {
              // Clean the autorelease pool
              [myMainPool release];
              myMainPool = [[NSAutoreleasePool alloc] init];
              
              // Minimal event loop
              while (nil != (event = [NSApp nextEventMatchingMask:NSAnyEventMask
                                                                                      untilDate:nil
                                                                                            inMode:NSDefaultRunLoopMode
                                                                                           dequeue:YES]))
              {
                     [NSApp sendEvent:event];
              }
       }
}

Here is the caller graph for this function:

- (void) setFullscreenWindow: (sfPrivWindow *)  window
mode: (sf::VideoMode *)  fullscreenMode 

Set as the current fullscreen window Change the screen resolution if needed according to and /////////////////////////////////////////////////////////.

Definition at line 407 of file AppController.mm.

                           :(sfPrivWindow *)aWindow mode:(sf::VideoMode *)fullscreenMode
{
       // If we have a fullscreen window and want to remove it
       if (aWindow == nil && myFullscreenWrapper)
       {
              // Get the CoreGraphics display mode according to the desktop mode
              CFDictionaryRef displayMode = CGDisplayBestModeForParameters ([sfPrivAppController primaryScreen],
                                                                                                                         myDesktopMode.BitsPerPixel,
                                                                                                                         myDesktopMode.Width,
                                                                                                                         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([sfPrivAppController primaryScreen], displayMode);
              
              // Close the window
              [[myFullscreenWrapper window] close];
              
              // 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 = nil;
       }
       else if (aWindow)
       {
              // else if we want to SET fullscreen
              assert(fullscreenMode != NULL);
              
              // Get the CoreGraphics display mode according to the given sf mode
              CFDictionaryRef displayMode = CGDisplayBestModeForParameters ([sfPrivAppController primaryScreen],
                                                                                                                         fullscreenMode->BitsPerPixel,
                                                                                                                         fullscreenMode->Width,
                                                                                                                         fullscreenMode->Height,
                                                                                                                         NULL);
              
#if ENABLE_FADE_OPERATIONS
              // Fade to a black screen
              [self doFadeOperation:FillScreen time:0.5f sync:true];
#endif
              
              if (!myFullscreenWrapper)
              {
                     // Hide the main menu bar
                     [NSMenu setMenuBarVisible:NO];
              }
              
              if (myPrevMode != *fullscreenMode)
              {
                     // Switch to the wished display mode
                     myPrevMode = *fullscreenMode;
                     CGDisplaySwitchToMode([sfPrivAppController primaryScreen], displayMode);
              }
              
              if (myFullscreenWrapper)
              {
                     [[myFullscreenWrapper window] close];
              }
              
              // Open and center the window
              [[aWindow window] makeKeyAndOrderFront:nil];
              [[aWindow window] center];
              
#if ENABLE_FADE_OPERATIONS
              // Fade to normal screen
              [self doFadeOperation:CleanScreen time:0.2f sync:false];
#endif
              
              // Save the fullscreen wrapper
              myFullscreenWrapper = aWindow;
       }
       else
       {
              std::cerr << "Inconcistency error for arguments given to -[sfPrivAppController setFullscreenWindow:mode:]" << std::endl;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

- (void) setNotifications

Reset notifictions about application focus /////////////////////////////////////////////////////////.

Definition at line 167 of file AppController.mm.

{
       NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
       [nc addObserver:self
                 selector:@selector(applicationWillDeactivate:)
                        name:NSApplicationWillResignActiveNotification
                      object:NSApp];
       [nc addObserver:self
                 selector:@selector(applicationWillActivate:)
                        name:NSApplicationWillBecomeActiveNotification
                      object:NSApp];

       [nc addObserver:self
                 selector:@selector(applicationWillTerminate:)
                        name:NSApplicationWillTerminateNotification
                      object:NSApp];
}

Here is the caller graph for this function:

Return the shared AppController instance. Make one if needed. /////////////////////////////////////////////////////////.

Definition at line 132 of file AppController.mm.

{
       // AppController singleton object
       static sfPrivAppController *shared = [[sfPrivAppController alloc] init];
       return shared;
}

Here is the caller graph for this function:


Member Data Documentation

- sf: [protected]

Definition at line 44 of file AppController.h.

Definition at line 42 of file AppController.h.

- (NSAutoreleasePool*) myMainPool [protected]

Definition at line 43 of file AppController.h.

- (BOOL) myOwningEventLoop [protected]

Definition at line 41 of file AppController.h.

- sf: [protected]

Definition at line 45 of file AppController.h.


The documentation for this class was generated from the following files: