Oolite
Loading...
Searching...
No Matches
GameController+SDLFullScreen.m
Go to the documentation of this file.
1/*
2
3GameController+SDLFullScreen.m
4
5Full-screen rendering support for SDL targets.
6
7
8Oolite
9Copyright (C) 2004-2013 Giles C Williams and contributors
10
11This program is free software; you can redistribute it and/or
12modify it under the terms of the GNU General Public License
13as published by the Free Software Foundation; either version 2
14of the License, or (at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software
23Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24MA 02110-1301, USA.
25
26*/
27
28#import "GameController.h"
29
30#if OOLITE_SDL
31
32#import "MyOpenGLView.h"
34#import "Universe.h"
35
36@implementation GameController (FullScreen)
37
39{
40 NSArray* modes = [gameView getScreenSizeArray];
41 NSDictionary* mode = nil;
42 unsigned int modeIndex, modeCount;
43 unsigned int modeWidth, modeHeight;
44
45 displayModes = [[NSMutableArray alloc] init];
46 modeCount = [modes count];
47 for (modeIndex = 0; modeIndex < modeCount; modeIndex++) {
48 mode = [modes objectAtIndex:modeIndex];
49 modeWidth = [[mode objectForKey:kOODisplayWidth] intValue];
50 modeHeight = [[mode objectForKey:kOODisplayHeight] intValue];
51
52 if (modeWidth < DISPLAY_MIN_WIDTH || modeWidth > DISPLAY_MAX_WIDTH || modeHeight < DISPLAY_MIN_HEIGHT || modeHeight > DISPLAY_MAX_HEIGHT)
53 continue;
54 [displayModes addObject:mode];
55 }
56
57 NSDictionary* currentMode = [gameView currentScreenMode];
58 if (currentMode) {
59 width = [[currentMode objectForKey:kOODisplayWidth] intValue];
60 height = [[currentMode objectForKey:kOODisplayHeight] intValue];
61 refresh = [[currentMode objectForKey:kOODisplayRefreshRate] intValue];
62 } else {
63 NSSize fsmSize = [gameView currentScreenSize];
64 width = fsmSize.width;
65 height = fsmSize.height;
66 }
67}
68
69- (void)setFullScreenMode:(BOOL)fsm
70{
71 fullscreen = fsm;
72}
73
75{
76 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"fullscreen"];
77 stayInFullScreenMode = NO;
78}
79
80- (BOOL)inFullScreenMode
81{
82 return [gameView inFullScreenMode];
83}
84
85- (BOOL)setDisplayWidth:(unsigned int)d_width Height:(unsigned int)d_height Refresh:(unsigned int)d_refresh
86{
87 NSDictionary* d_mode = [self findDisplayModeForWidth:d_width Height:d_height Refresh:d_refresh];
88 if (d_mode) {
89 width = d_width;
90 height = d_height;
91 refresh = d_refresh;
92 fullscreenDisplayMode = d_mode;
93
94 NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
95
96 [userDefaults setInteger:width forKey:@"display_width"];
97 [userDefaults setInteger:height forKey:@"display_height"];
98 [userDefaults setInteger:refresh forKey:@"display_refresh"];
99
100 // Manual synchronization is required for SDL And doesn't hurt much for OS X.
101 [userDefaults synchronize];
102
103 return YES;
104 }
105 return NO;
106}
107
108- (NSDictionary*)findDisplayModeForWidth:(unsigned int)d_width Height:(unsigned int)d_height Refresh:(unsigned int)d_refresh
109{
110 int i, modeCount;
111 NSDictionary* mode;
112 unsigned int modeWidth, modeHeight, modeRefresh;
113
114 modeCount = [displayModes count];
115
116 for (i = 0; i < modeCount; i++) {
117 mode = [displayModes objectAtIndex:i];
118 modeWidth = [[mode objectForKey:kOODisplayWidth] intValue];
119 modeHeight = [[mode objectForKey:kOODisplayHeight] intValue];
120 modeRefresh = [[mode objectForKey:kOODisplayRefreshRate] intValue];
121 if ((modeWidth == d_width) && (modeHeight == d_height) && (modeRefresh == d_refresh)) {
122 return mode;
123 }
124 }
125 return nil;
126}
127
128- (NSArray*)displayModes
129{
130 return [NSArray arrayWithArray:displayModes];
131}
132
133- (NSUInteger)indexOfCurrentDisplayMode
134{
135 NSDictionary* mode;
136
137 mode = [self findDisplayModeForWidth:width Height:height Refresh:refresh];
138 if (mode == nil)
139 return NSNotFound;
140 else
141 return [displayModes indexOfObject:mode];
142
143 return NSNotFound;
144}
145
146- (void)pauseFullScreenModeToPerform:(SEL)selector onTarget:(id)target
147{
148 pauseSelector = selector;
149 pauseTarget = target;
150 stayInFullScreenMode = NO;
151}
152
153@end
154
155#endif
#define DISPLAY_MAX_WIDTH
#define DISPLAY_MAX_HEIGHT
return nil
NSUInteger indexOfCurrentDisplayMode()
const char int mode
Definition ioapi.h:125