- Main Page
- Namespaces
- Classes
- Files

- File List

# WindowController.mm

    00001
    00002 //
    00003 // SFML - Simple and Fast Multimedia Library
    00004 // Copyright (C) 2007-2008 Lucas Soltic (elmerod@gmail.com) and Laurent Gomila (laurent.gom@gmail.com)
    00005 //
    00006 // This software is provided 'as-is', without any express or implied warranty.
    00007 // In no event will the authors be held liable for any damages arising from the use of this software.
    00008 //
    00009 // Permission is granted to anyone to use this software for any purpose,
    00010 // including commercial applications, and to alter it and redistribute it freely,
    00011 // subject to the following restrictions:
    00012 //
    00013 // 1. The origin of this software must not be misrepresented;
    00014 //    you must not claim that you wrote the original software.
    00015 //    If you use this software in a product, an acknowledgment
    00016 //    in the product documentation would be appreciated but is not required.
    00017 //
    00018 // 2. Altered source versions must be plainly marked as such,
    00019 //    and must not be misrepresented as being the original software.
    00020 //
    00021 // 3. This notice may not be removed or altered from any source distribution.
    00022 //
    00024
    00025
    00027 // Headers
    00029 #import <SFML/Window/Cocoa/WindowController.h>
    00030 #import <SFML/Window/Cocoa/WindowImplCocoa.hpp>
    00031 #import <SFML/Window/Cocoa/AppController.h>
    00032 #import <OpenGL/gl.h>
    00033 #import <iostream>
    00034
    00035 @implementation WindowController
    00036
    00040 - (id)init
    00041 {
    00042     return [self initWithWindow:NULL];
    00043 }
    00044
    00049 - (WindowController *)initWithWindow:(sf::priv::WindowImplCocoa *)window
    00050 {
    00051     if (window == NULL) {
    00052         std::cerr << "-[WindowController initWithWindow:NULL] -- initialization without any linked window is forbidden ; nil returned" << std::endl;
    00053         [self release];
    00054         return nil;
    00055     }
    00056
    00057     self = [super init];
    00058
    00059     if (self != nil) {
    00060         parentWindow = window;
    00061     }
    00062
    00063     return self;
    00064 }
    00065
    00070 + (WindowController *)controllerWithWindow:(sf::priv::WindowImplCocoa *)window
    00071 {
    00072     WindowController *ctrl =
    00073     massert([WindowController alloc]);
    00074     return [[ctrl initWithWindow:window] autorelease];
    00075 }
    00076
    00080 - (void)pushEvent:(sf::Event)sfEvent
    00081 {
    00082     if (parentWindow != NULL) {
    00083         parentWindow->HandleNotifiedEvent(sfEvent);
    00084     }
    00085 }
    00086
    00090 - (void)viewFrameDidChange:(NSNotification *)notification
    00091 {
    00092     NSOpenGLView *glView = [notification object];
    00093     [[glView openGLContext] update];
    00094
    00095     sf::Event ev;
    00096     ev.Type = sf::Event::Resized;
    00097     ev.Size.Width = (unsigned) [glView frame].size.width;
    00098     ev.Size.Height = (unsigned) [glView frame].size.height;
    00099
    00100     [self pushEvent:ev];
    00101 }
    00102
    00106 - (void)windowDidBecomeMain:(NSNotification *)notification
    00107 {
    00108     sf::Event ev;
    00109     ev.Type = sf::Event::GainedFocus;
    00110
    00111     [self pushEvent:ev];
    00112 }
    00113
    00117 - (void)windowDidResignMain:(NSNotification *)notification
    00118 {
    00119     sf::Event ev;
    00120     ev.Type = sf::Event::LostFocus;
    00121
    00122     [self pushEvent:ev];
    00123 }
    00124
    00128 - (void)windowWillClose:(NSNotification *)notification
    00129 {
    00130     sf::Event ev;
    00131     ev.Type = sf::Event::Closed;
    00132
    00133     [self pushEvent:ev];
    00134 }
    00135
    00136 - (void)windowDidMove:(NSNotification *)notification
    00137 {
    00138     NSWindow *sender = [notification object];
    00139
    00140     if (!([sender styleMask] & NSTitledWindowMask))
    00141         [sender center];
    00142 }
    00143
    00144 @end
    00145
    00146
    00147 @implementation SFWindow
    00148 - (BOOL)canBecomeKeyWindow
    00149 {
    00150     return YES;
    00151 }
    00152
    00153 - (BOOL)canBecomeMainWindow
    00154 {
    00155     return YES;
    00156 }
    00157 @end

:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::