1 /***************************************************************************
2 PluginWindowController.m
5 Created by Gil Pedersen on Tue April 12 2004.
6 Copyright (c) 2004 Gil Pedersen.
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. See also the license.txt file for *
15 * additional informations. *
17 ***************************************************************************/
19 #import "PluginWindowController.h"
20 #import "PluginWindow.h"
21 #import "Carbon/Carbon.h"
22 #include "externals.h"
26 PluginWindowController *gameController;
29 @implementation PluginWindowController
33 if (gameWindow == nil) {
34 if (gameController == nil) {
35 gameController = [[PluginWindowController alloc] initWithWindowNibName:@"NetSfPeopsSoftGPUInterface"];
37 gameWindow = [gameController window];
40 if (windowFrame.size.width != 0) {
41 [gameWindow setFrame:windowFrame display:NO];
46 [gameWindow makeKeyAndOrderFront:nil];
47 [gameController showWindow:nil];
49 CGDirectDisplayID display = (CGDirectDisplayID)[[[[gameWindow screen] deviceDescription] objectForKey:@"NSScreenNumber"] longValue];
50 if (CGDisplayIsCaptured(display)) {
51 [gameController setFullscreen:YES];
54 return gameController;
57 - (PluginGLView *)getOpenGLView
59 return (PluginGLView *)glView;
65 [fullWindow orderOut:self];
66 [fullWindow autorelease];
70 windowFrame = [[self window] frame];
75 // forget keyDownEvents
76 - (void)keyDown:(NSEvent *)theEvent
78 // Not required any more
81 - (void)mouseDown:(NSEvent *)theEvent
83 if ([self fullscreen]) {
84 [self setFullscreen:NO];
90 return (fullWindow!=nil);
93 - (void)setFullscreen:(BOOL)flag
95 NSWindow *window = [self window];
96 NSScreen *screen = [window screen];
97 CGDirectDisplayID display = (CGDirectDisplayID)[[[screen deviceDescription] objectForKey:@"NSScreenNumber"] longValue];
99 NSDisableScreenUpdates();
102 if (!CGDisplayIsCaptured(display)) {
103 CGDisplayCapture(display);
105 CGDisplayCount count = 10;
106 CGDirectDisplayID displays[10];
107 CGGetActiveDisplayList(10, displays, &count);
109 CGDisplayHideCursor(display);
110 CGAssociateMouseAndMouseCursorPosition(NO);
113 //[window orderOut:self];
116 int width = CGDisplayPixelsWide(display);
117 int height = CGDisplayPixelsHigh(display);
119 // assume square pixel ratio on the monitor
120 if ((width*3)/4 < height) {
121 height = (width*3)/4;
123 width = (height*4)/3;
126 fullWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect((CGDisplayPixelsWide(display)-width)/2,
127 (CGDisplayPixelsHigh(display)-height)/2,
129 styleMask:NSBorderlessWindowMask
130 backing:NSBackingStoreRetained
134 //[[glView openGLContext] setFullScreen];
135 [[glView openGLContext] setView:[fullWindow contentView]];
137 //[[glView openGLContext] update];
138 //[fullWindow setContentView:glView];
140 [fullWindow setBackgroundColor:[NSColor blackColor]];
141 [fullWindow setHasShadow:NO];
142 [fullWindow setDelegate:self];
144 [fullWindow setLevel:CGShieldingWindowLevel()];
145 [fullWindow makeKeyAndOrderFront:self];
147 [[self window] makeKeyAndOrderFront:self];
149 CGDisplayRelease(display);
150 //CGReleaseAllDisplays();
152 CGAssociateMouseAndMouseCursorPosition(YES);
153 CGDisplayShowCursor(display);
156 [fullWindow orderOut:self];
157 [fullWindow autorelease];
160 [[glView openGLContext] setView:glView];
162 //[window setContentView:glView];
165 [[self window] makeKeyAndOrderFront:self];
168 NSEnableScreenUpdates();
171 - (BOOL)windowShouldZoom:(NSWindow *)sender toFrame:(NSRect)newFrame
173 [self setFullscreen:YES];
178 - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
180 if (!(([sender resizeFlags] & NSShiftKeyMask) == NSShiftKeyMask)) {
181 NSRect oldSize = [sender frame];
182 NSRect viewSize = [glView frame];
184 float xDiff = NSWidth(oldSize) - NSWidth(viewSize);
185 float yDiff = NSHeight(oldSize) - NSHeight(viewSize);
187 //if ((proposedFrameSize.height / proposedFrameSize.width) < (3.0/4.0))
188 // proposedFrameSize.height = ((proposedFrameSize.width - xDiff) * 3.0) / 4.0 + yDiff;
190 proposedFrameSize.width = ((proposedFrameSize.height - yDiff) * 4.0) / 3.0 + xDiff;
193 return proposedFrameSize;
196 - (void)windowWillMiniaturize:(NSNotification *)aNotification
198 [[NSNotificationCenter defaultCenter] postNotificationName:@"emuWindowWantPause" object:self];
201 - (void)windowDidDeminiaturize:(NSNotification *)aNotification
203 [[NSNotificationCenter defaultCenter] postNotificationName:@"emuWindowWantResume" object:self];
206 //- (void)windowDidBecomeMain:(NSNotification *)aNotification
207 /*- (void)windowDidBecomeKey:(NSNotification *)aNotification
209 if (iWindowMode==0) {
210 [self setFullscreen:YES];
214 - (BOOL)windowShouldClose:(id)sender
219 [[NSNotificationCenter defaultCenter] postNotificationName:@"emuWindowDidClose" object:self];
220 [gameController autorelease];
221 gameController = nil;