Back to index

libsfml  1.6+dfsg2
Public Member Functions | Private Member Functions | Private Attributes
sfPrivOwnedWindow Class Reference

Class for creating new SFML windows from informations /////////////////////////////////////////////////////////. More...

#import <GLKit.h>

Inheritance diagram for sfPrivOwnedWindow:
Inheritance graph
[legend]
Collaboration diagram for sfPrivOwnedWindow:
Collaboration graph
[legend]

List of all members.

Public Member Functions

(id) - initWithVideoMode:settings:style:title:
 Creates and returns a new SFML window handler with the given parameters /////////////////////////////////////////////////////////.
(BOOL) - isFullscreen
 Returns the window's fullscreen state /////////////////////////////////////////////////////////.
(void) - dealloc [implementation]
(void) - windowDidMove: [implementation]
 Notification method receiver when the window finish moving /////////////////////////////////////////////////////////.
(void) - show: [implementation]
 Close or open the window /////////////////////////////////////////////////////////.
(void) - setPosition: [implementation]
 Forward call to set the window position on screen /////////////////////////////////////////////////////////.
(void) - setSize: [implementation]
 Forward call to set the window size /////////////////////////////////////////////////////////.
(NSWindow *) - window
 Return a reference to the internal Cocoa window /////////////////////////////////////////////////////////.
(sfPrivGLView *) - view
 Return a reference to the internal Cocoa OpenGL view /////////////////////////////////////////////////////////.
(void) - setDelegate:
 Sets as the window delegate /////////////////////////////////////////////////////////.
(sf::priv::WindowImplCocoa *) - delegate
 Returns the window delegate /////////////////////////////////////////////////////////.
(NSPoint) - mouseLocation
 Return the mouse location relative to the internal window /////////////////////////////////////////////////////////.
(BOOL) - mouseInside
 Return whether the mouse is on our window /////////////////////////////////////////////////////////.
(void) - enableVerticalSync:
 Forward call to en/disable the OpenGL view vertical synchronization /////////////////////////////////////////////////////////.
(void) - setActive:
 Forward 'setActive' call the the OpenGL view /////////////////////////////////////////////////////////.
(void) - flushBuffer
 Forward call to flush the OpenGL view /////////////////////////////////////////////////////////.
(void) - setWindow: [implementation]
 Registers a reference to the internal Cocoa window /////////////////////////////////////////////////////////.
(void) - putOpenGLView: [implementation]
 Registers the the OpenGL view and adds it to its parent container /////////////////////////////////////////////////////////.
(void) - setView: [implementation]
 Registers a reference to the internal Cocoa OpenGL view /////////////////////////////////////////////////////////.
(void) - windowDidBecomeMain: [implementation]
 Notification method receiver when the window gains focus /////////////////////////////////////////////////////////.
(void) - windowDidResignMain: [implementation]
 Notification method receiver when the window loses focus /////////////////////////////////////////////////////////.
(void) - windowWillClose: [implementation]
 Notification method receiver when the window closes /////////////////////////////////////////////////////////.

Private Member Functions

(void) - setFullscreen: [implementation]
 Sets the window's fullscreen state /////////////////////////////////////////////////////////.

Private Attributes

sf::VideoMode myFullscreenMode
bool myIsFullscreen

Detailed Description

Class for creating new SFML windows from informations /////////////////////////////////////////////////////////.

Definition at line 179 of file GLKit.h.


Member Function Documentation

- (void) dealloc [implementation]

Reimplemented from sfPrivWindow.

Definition at line 914 of file GLKit.mm.

{
       [[NSNotificationCenter defaultCenter]
        removeObserver:self 
        name:NSWindowDidMoveNotification
        object:[self window]];
       [super dealloc];
}

Here is the call graph for this function:

- sf:

Returns the window delegate /////////////////////////////////////////////////////////.

Definition at line 627 of file GLKit.mm.

{
       return [[self view] delegate];
}

Here is the call graph for this function:

- (void) enableVerticalSync: (bool)  flag

Forward call to en/disable the OpenGL view vertical synchronization /////////////////////////////////////////////////////////.

Definition at line 718 of file GLKit.mm.

                          :(bool)flag
{
       NSAssert([self view] != nil, @"expected valid OpenGL view");
       [[self view] enableVerticalSync:flag];
}

Here is the call graph for this function:

- (void) flushBuffer

Forward call to flush the OpenGL view /////////////////////////////////////////////////////////.

Definition at line 736 of file GLKit.mm.

{
       NSAssert([self view] != nil, @"expected valid OpenGL view");
       [[self view] flushBuffer];
}

Here is the call graph for this function:

- (id) initWithVideoMode: (sf::VideoMode&)  aMode
settings: (sf::WindowSettings&)  someSettings
style: (unsigned long)  aStyle
title: (NSString *)  aTitle 

Creates and returns a new SFML window handler with the given parameters /////////////////////////////////////////////////////////.

Definition at line 783 of file GLKit.mm.

                       :(sf::VideoMode&)aMode
                        settings:(sf::WindowSettings&)someSettings
                              style:(unsigned long)aStyle
                              title:(NSString *)aTitle
{
       self = [super init];
       if (self)
       {
              if (aStyle & sf::Style::Fullscreen) {
                     [self setFullscreen:YES];
              }
              
              NSRect frame = NSMakeRect (0.0f, 0.0f, (float) aMode.Width, (float) aMode.Height);
              unsigned int mask = 0;
              
              if (aStyle & sf::Style::Fullscreen) {
                     // Check display mode and put new values in 'mode' if needed
                     boolean_t exact = true;
                     
                     CFDictionaryRef properties =
                     CGDisplayBestModeForParameters([sfPrivAppController primaryScreen],
                                                                         aMode.BitsPerPixel,
                                                                         aMode.Width,
                                                                         aMode.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, &aMode.Width);
                            
                            CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties,
                                                                                                                       kCGDisplayHeight),
                                                         kCFNumberIntType, &aMode.Height);
                            
                            CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties,
                                                                                                                       kCGDisplayBitsPerPixel),
                                                         kCFNumberIntType, &aMode.BitsPerPixel);
                            
                     }
              }
              
              // We grab options from WindowStyle and add them to our window mask
              if (aStyle & sf::Style::None || aStyle & sf::Style::Fullscreen) {
                     mask |= NSBorderlessWindowMask;
              } else {
                     if (aStyle & sf::Style::Titlebar) {
                            mask |= NSTitledWindowMask;
                            mask |= NSMiniaturizableWindowMask;
                     }
                     
                     if (aStyle & sf::Style::Resize) {
                            mask |= NSTitledWindowMask;
                            mask |= NSMiniaturizableWindowMask;
                            mask |= NSResizableWindowMask;
                     }
                     
                     if (aStyle & sf::Style::Close) {
                            mask |= NSTitledWindowMask;
                            mask |= NSClosableWindowMask;
                            mask |= NSMiniaturizableWindowMask;
                     }
              }
              
              // Now we make the window with the values we got
              // Note: defer flag set to NO to be able to use OpenGL in our window
              NSWindow *newWindow = [[NSWindow alloc]
                                                    initWithContentRect:frame
                                                    styleMask:mask
                                                    backing:NSBackingStoreBuffered
                                                    defer:NO];
              
              if (newWindow) {
                     [self setWindow:[newWindow autorelease]];
              } else {
                     std::cerr << "Unable to create the Cocoa window" << std::endl;
                     [self autorelease];
                     return nil;
              }
              
              // We set title and window position
              [[self window] setTitle:aTitle != nil ? aTitle : @""];
              [[self window] center];
              
              // Make the OpenGL view
              sfPrivGLView *newView = [[sfPrivGLView alloc]
                                             initWithFrame:[[[self window] contentView] frame]
                                             mode:aMode
                                             settings:someSettings];
              
              if (!newView) {
                     std::cerr << "Unable to create the OpenGL view" << std::endl;
                     [self autorelease];
                     return nil;
              }
              
              // Put our view in the window 
              [self putOpenGLView:[newView autorelease]];
              
              // I want to re-center the window if it's a full screen one and moved by Spaces
              [[NSNotificationCenter defaultCenter]
               addObserver:self
               selector:@selector(windowDidMove:)
               name:NSWindowDidMoveNotification
               object:[self window]];
              
              // Needed not to make application crash when releasing the window in our destructor
              // (I prefer to take control of everything :P)
              [[self window] setReleasedWhenClosed:NO];
              [[self window] setAcceptsMouseMovedEvents:YES];
              
              if ([self isFullscreen]) {
                     myFullscreenMode = aMode;
                     
                     // Using this because full screen window was not always
                     // in front of the other application windows when unhiding app
                     [[self window] setLevel:NSFloatingWindowLevel];
              }
       }
       return self;
}

Here is the call graph for this function:

- (BOOL) isFullscreen

Returns the window's fullscreen state /////////////////////////////////////////////////////////.

Definition at line 934 of file GLKit.mm.

{
       return myIsFullscreen;
}

Here is the caller graph for this function:

- (BOOL) mouseInside

Return whether the mouse is on our window /////////////////////////////////////////////////////////.

Definition at line 674 of file GLKit.mm.

{
       NSAssert([self window] != nil, @"expected valid window");
       NSAssert([self view] != nil, @"expected valid OpenGL view");
       
       BOOL flag = NO;
       
       if ([[self window] isVisible]) {
              NSPoint relativeToWindow = [[self window] mouseLocationOutsideOfEventStream];
              NSPoint relativeToView = [[self view] convertPoint:relativeToWindow fromView:nil];
              
              if (NSPointInRect (relativeToView, [[self view] bounds]))
              {
                     flag = YES;
              }
       }
       
       return flag;
}

Here is the call graph for this function:

- (NSPoint) mouseLocation

Return the mouse location relative to the internal window /////////////////////////////////////////////////////////.

Definition at line 660 of file GLKit.mm.

{
       NSAssert([self view] != nil, @"expected valid window");
       
       NSPoint windowPoint = [[self window] convertScreenToBase:[NSEvent mouseLocation]];
       NSPoint viewPoint = [[self view] convertPoint:windowPoint fromView:[[[self window] contentView] superview]];
       
       viewPoint.y = [[self view] frame].size.height - viewPoint.y;
       return viewPoint;
}

Here is the call graph for this function:

- (void) putOpenGLView: (sfPrivGLView *)  aView [implementation]

Registers the the OpenGL view and adds it to its parent container /////////////////////////////////////////////////////////.

Reimplemented in sfPrivImportedView.

Definition at line 586 of file GLKit.mm.

                     :(sfPrivGLView *)aView
{
       [self setView:aView];
       
       // Finish setting up the view and window
       // Add the view to our window and tell it to the view
       [[[self window] contentView] addSubview:[self view]];
       [[self view] finishInitialization];
}

Here is the call graph for this function:

Here is the caller graph for this function:

- (void) setActive: (bool)  flag

Forward 'setActive' call the the OpenGL view /////////////////////////////////////////////////////////.

Definition at line 727 of file GLKit.mm.

                 :(bool)flag
{
       NSAssert([self view] != nil, @"expected valid OpenGL view");
       [[self view] setActive:flag];
}

Here is the call graph for this function:

- (void) setDelegate: (sf::priv::WindowImplCocoa *)  aDelegate

Sets as the window delegate /////////////////////////////////////////////////////////.

Definition at line 619 of file GLKit.mm.

                   :(sf::priv::WindowImplCocoa *)aDelegate
{
       [[self view] setDelegate:aDelegate];
}

Here is the call graph for this function:

Here is the caller graph for this function:

- (void) setFullscreen: (BOOL)  aFlag [implementation]

Sets the window's fullscreen state /////////////////////////////////////////////////////////.

Definition at line 926 of file GLKit.mm.

                     :(BOOL)aFlag
{
       myIsFullscreen = aFlag;
}

Here is the caller graph for this function:

- (void) setPosition: (NSPoint)  aPosition [implementation]

Forward call to set the window position on screen /////////////////////////////////////////////////////////.

Reimplemented from sfPrivWindow.

Definition at line 985 of file GLKit.mm.

                   :(NSPoint)aPosition
{
       if (![self isFullscreen]) {
              [super setPosition:aPosition];
       }
}

Here is the call graph for this function:

- (void) setSize: (NSSize)  size [implementation]

Forward call to set the window size /////////////////////////////////////////////////////////.

Reimplemented from sfPrivWindow.

Definition at line 995 of file GLKit.mm.

               :(NSSize)size
{
       if (![self isFullscreen]) {
              [super setSize:size];
       }
}

Here is the call graph for this function:

- (void) setView: (sfPrivGLView *)  aView [implementation]

Registers a reference to the internal Cocoa OpenGL view /////////////////////////////////////////////////////////.

Definition at line 599 of file GLKit.mm.

               :(sfPrivGLView *)aView
{
       if (myView != aView)
       {
              [myView release];
              myView = [aView retain];
       }
}

Here is the caller graph for this function:

- (void) setWindow: (NSWindow *)  aWindow [implementation]

Registers a reference to the internal Cocoa window /////////////////////////////////////////////////////////.

Definition at line 530 of file GLKit.mm.

                 :(NSWindow *)aWindow
{
       if (myWindow != aWindow)
       {
              NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
              
              // Drop the observers on the previously set window
              if ([self window]) {
                     [nc removeObserver:self 
                                            name:NSWindowDidBecomeMainNotification
                                          object:[self window]];
                     [nc removeObserver:self 
                                            name:NSWindowDidResignMainNotification
                                          object:[self window]];
                     [nc removeObserver:self 
                                            name:NSWindowWillCloseNotification
                                          object:[self window]];
              }
              
              [myWindow release];
              myWindow = [aWindow retain];
              
              // Set the new observers
              // We want to know when our window got the focus
              [nc addObserver:self
                        selector:@selector(windowDidBecomeMain:)
                               name:NSWindowDidBecomeMainNotification
                             object:[self window]];
              
              // We want to know when our window lost the focus
              [nc addObserver:self
                        selector:@selector(windowDidResignMain:)
                               name:NSWindowDidResignMainNotification
                             object:[self window]];
              
              // We want to know when the user closes the window
              [nc addObserver:self
                        selector:@selector(windowWillClose:)
                               name:NSWindowWillCloseNotification
                             object:[self window]];
              
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

- (void) show: (bool)  flag [implementation]

Close or open the window /////////////////////////////////////////////////////////.

Reimplemented from sfPrivWindow.

Definition at line 953 of file GLKit.mm.

            :(bool)flag
{
       NSAssert([self window] != nil, @"expected valid window");
       
       if (flag && ![[self window] isVisible]) {
              // Wanna open the closed window
              
              if ([self isFullscreen]) {
                     [[sfPrivAppController sharedController]
                      setFullscreenWindow:self
                      mode:&myFullscreenMode];
              } else {
                     // Show the window
                     [[self window] makeKeyAndOrderFront:nil];
              }
       } else if (!flag && [[self window] isVisible]) {
              // Wanna close the opened window
              
              if ([self isFullscreen]) {
                     [[sfPrivAppController sharedController]
                      setFullscreenWindow:nil
                      mode:NULL];
              } else {
                     // Close the window
                     [[self window] close];
              }
       }      
}

Here is the call graph for this function:

Return a reference to the internal Cocoa OpenGL view /////////////////////////////////////////////////////////.

Definition at line 611 of file GLKit.mm.

{
       return [[myView retain] autorelease];
}

Here is the caller graph for this function:

Return a reference to the internal Cocoa window /////////////////////////////////////////////////////////.

Definition at line 577 of file GLKit.mm.

{
       return [[myWindow retain] autorelease];
}

Here is the caller graph for this function:

- (void) windowDidBecomeMain: (NSNotification *)  notification [implementation]

Notification method receiver when the window gains focus /////////////////////////////////////////////////////////.

Definition at line 745 of file GLKit.mm.

                           :(NSNotification *)notification
{
       sf::Event ev;
       ev.Type = sf::Event::GainedFocus;
       
       [[self view] pushEvent:ev];
}

Here is the call graph for this function:

- (void) windowDidMove: (NSNotification *)  notification [implementation]

Notification method receiver when the window finish moving /////////////////////////////////////////////////////////.

Definition at line 942 of file GLKit.mm.

                     :(NSNotification *)notification
{
       NSWindow *sender = [notification object];
       
       if (myIsFullscreen)
              [sender center];
}
- (void) windowDidResignMain: (NSNotification *)  notification [implementation]

Notification method receiver when the window loses focus /////////////////////////////////////////////////////////.

Definition at line 757 of file GLKit.mm.

                           :(NSNotification *)notification
{
       sf::Event ev;
       ev.Type = sf::Event::LostFocus;
       
       [[self view] pushEvent:ev];
}

Here is the call graph for this function:

- (void) windowWillClose: (NSNotification *)  notification [implementation]

Notification method receiver when the window closes /////////////////////////////////////////////////////////.

Definition at line 769 of file GLKit.mm.

                       :(NSNotification *)notification
{
       sf::Event ev;
       ev.Type = sf::Event::Closed;
       
       [[self view] pushEvent:ev];
}

Here is the call graph for this function:


Member Data Documentation

- sf: [private]

Definition at line 182 of file GLKit.h.

- (bool) myIsFullscreen [private]

Definition at line 183 of file GLKit.h.


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