// // // OSX GLEssentials // // Copied from the Apple GLEssentials // // #import "WindowController.h" #import "FullscreenWindow.h" #import "GLView.h" @interface WindowController () { FullscreenWindow *fullscreenWindow; // Fullscreen window NSWindow* standardWindow; // Non-Fullscreen window (also the initial window) } @end @implementation WindowController - (id)initWithWindow:(NSWindow *) window{ if (self = [super initWithWindow:window]){ fullscreenWindow = nil; } return self; } - (void)goFullscreen{ if(fullscreenWindow){ return; } // Allocate a new fullscreen window fullscreenWindow = [[FullscreenWindow alloc] init]; // Resize the view to screensize view.frame = fullscreenWindow.frame; // Set the view in the fullscreen window fullscreenWindow.contentView = view; // keep a referene to the old window standardWindow = self.window; // Hide non-fullscreen window so it doesn't show up when switching out // of this app (i.e. with CMD-TAB) [standardWindow orderOut:self]; // Set controller to the fullscreen window so that all input will go to // this controller (self) self.window = fullscreenWindow; // Show the window and make it the key window for input [fullscreenWindow makeKeyAndOrderFront:self]; } - (void)goWindow{ if(!fullscreenWindow){ return; } // Resize the view to the window size view.frame = standardWindow.frame; // Set controller to the standard window so that all input will go to // this controller (self) self.window = standardWindow; // Set the content of the orginal window to the view self.window.contentView = view; // Show the window and make it the key window for input [[self window] makeKeyAndOrderFront:self]; // release fullscreenWindow fullscreenWindow = nil; } - (void)keyDown:(NSEvent *)event{ unichar c = [[event charactersIgnoringModifiers] characterAtIndex:0]; switch (c){ // Handle [ESC] key case 27: if(fullscreenWindow){ [self goWindow]; } return; // Have f key toggle fullscreen case 'f': if(fullscreenWindow){ [self goWindow]; } else { [self goFullscreen]; } return; } // Allow other character to be handled (or not and beep) [super keyDown:event]; } @end