Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
GameController+FullScreen.m
Go to the documentation of this file.
1/*
2
3GameController+FullScreen.m
4
5
6Oolite
7Copyright (C) 2004-2013 Giles C Williams and contributors
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22MA 02110-1301, USA.
23
24*/
25
26
27#import "GameController.h"
28#import "MyOpenGLView.h"
30
31
32#if OOLITE_MAC_OS_X // TEMP, should be used for SDL too
33
34#if OOLITE_MAC_OS_X
35
38#import "OOPrimaryWindow.h"
39
40
41@interface GameController (OOPrimaryWindowDelegate) <OOPrimaryWindowDelegate>
42@end
43
44#endif
45
46
47@implementation GameController (FullScreen)
48
49- (void) setUpDisplayModes
50{
51#if OOLITE_MAC_OS_X
52 OOFullScreenController *fullScreenController = nil;
53
54#if OO_MAC_SUPPORT_SYSTEM_STANDARD_FULL_SCREEN
55 if ([OOMacSystemStandardFullScreenController shouldUseSystemStandardFullScreenController])
56 {
57 fullScreenController = [[OOMacSystemStandardFullScreenController alloc] initWithGameView:gameView];
58 }
59#endif
60
61 if (fullScreenController == nil)
62 {
63 fullScreenController = [[OOMacSnowLeopardFullScreenController alloc] initWithGameView:gameView];
64 }
65#endif
66
67 // Load preferred display mode, falling back to current mode if no preferences set.
68 NSDictionary *currentMode = [fullScreenController currentDisplayMode];
69 NSUInteger width = [currentMode oo_unsignedIntegerForKey:kOODisplayWidth];
70 NSUInteger height = [currentMode oo_unsignedIntegerForKey:kOODisplayHeight];
71 NSUInteger refresh = [currentMode oo_unsignedIntegerForKey:kOODisplayRefreshRate];
72
73 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
74 width = [userDefaults oo_unsignedIntegerForKey:@"display_width" defaultValue:width];
75 height = [userDefaults oo_unsignedIntegerForKey:@"display_height" defaultValue:height];
76 refresh = [userDefaults oo_unsignedIntegerForKey:@"display_refresh" defaultValue:refresh];
77
78 [fullScreenController setDisplayWidth:width height:height refreshRate:refresh];
79
80 _fullScreenController = fullScreenController;
81}
82
83
84#if OOLITE_MAC_OS_X
85
86- (IBAction) toggleFullScreenAction:(id)sender
87{
88 [self setFullScreenMode:![self inFullScreenMode]];
89}
90
91
92- (void) toggleFullScreenCalledForWindow:(OOPrimaryWindow *)window withSender:(id)sender
93{
94 [self toggleFullScreenAction:sender];
95}
96
97#endif
98
99
100- (BOOL) inFullScreenMode
101{
102 return [_fullScreenController inFullScreenMode];
103}
104
105
106- (void) setFullScreenMode:(BOOL)value
107{
108 if (value == [self inFullScreenMode]) return;
109
110 [[NSUserDefaults standardUserDefaults] setBool:value forKey:@"fullscreen"];
111
112 if (value)
113 {
114 [_fullScreenController setFullScreenMode:YES];
115 }
116 else
117 {
118 [_fullScreenController setFullScreenMode:NO];
119 }
120}
121
122
123- (void) exitFullScreenMode
124{
125 [self setFullScreenMode:NO];
126}
127
128
129- (BOOL) setDisplayWidth:(unsigned int)width Height:(unsigned int)height Refresh:(unsigned int)refreshRate
130{
131 if ([_fullScreenController setDisplayWidth:width height:height refreshRate:refreshRate])
132 {
133 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
134
135 [userDefaults setInteger:width forKey:@"display_width"];
136 [userDefaults setInteger:height forKey:@"display_height"];
137 [userDefaults setInteger:refreshRate forKey:@"display_refresh"];
138
139 [userDefaults synchronize];
140
141 return YES;
142 }
143 else
144 {
145 return NO;
146 }
147}
148
149
150- (NSDictionary *) findDisplayModeForWidth:(unsigned int)d_width Height:(unsigned int)d_height Refresh:(unsigned int)d_refresh
151{
152 return [_fullScreenController findDisplayModeForWidth:d_width height:d_height refreshRate:d_refresh];
153}
154
155
156- (NSArray *) displayModes
157{
158 return [_fullScreenController displayModes];
159}
160
161
162- (NSUInteger) indexOfCurrentDisplayMode
163{
164 return [_fullScreenController indexOfCurrentDisplayMode];
165}
166
167
168- (void) pauseFullScreenModeToPerform:(SEL)selector onTarget:(id)target
169{
170 [target performSelector:selector];
171}
172
173@end
174
175#endif
return nil
BOOL setDisplayWidth:height:refreshRate:(NSUInteger width,[height] NSUInteger height,[refreshRate] NSUInteger refresh)