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
29#import "GameController.h"
30
31#if OOLITE_SDL
32
33#import "MyOpenGLView.h"
34#import "Universe.h"
36
37
38@implementation GameController (FullScreen)
39
40- (void) setUpDisplayModes
41{
42 NSArray *modes = [gameView getScreenSizeArray];
43 NSDictionary *mode = nil;
44 unsigned int modeIndex, modeCount;
45 unsigned int modeWidth, modeHeight;
46
47 displayModes = [[NSMutableArray alloc] init];
48 modeCount = [modes count];
49 for (modeIndex = 0; modeIndex < modeCount; modeIndex++)
50 {
51 mode = [modes objectAtIndex: modeIndex];
52 modeWidth = [[mode objectForKey: kOODisplayWidth] intValue];
53 modeHeight = [[mode objectForKey: kOODisplayHeight] intValue];
54
55 if (modeWidth < DISPLAY_MIN_WIDTH ||
56 modeWidth > DISPLAY_MAX_WIDTH ||
57 modeHeight < DISPLAY_MIN_HEIGHT ||
58 modeHeight > DISPLAY_MAX_HEIGHT)
59 continue;
60 [displayModes addObject: mode];
61 }
62
63 NSDictionary *currentMode = [gameView currentScreenMode];
64 if (currentMode)
65 {
66 width = [[currentMode objectForKey: kOODisplayWidth] intValue];
67 height = [[currentMode objectForKey: kOODisplayHeight] intValue];
68 refresh = [[currentMode objectForKey: kOODisplayRefreshRate] intValue];
69 }
70 else
71 {
72 NSSize fsmSize = [gameView currentScreenSize];
73 width = fsmSize.width;
74 height = fsmSize.height;
75 }
76}
77
78
79- (void) setFullScreenMode:(BOOL)fsm
80{
81 fullscreen = fsm;
82}
83
84
85- (void) exitFullScreenMode
86{
87 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"fullscreen"];
88 stayInFullScreenMode = NO;
89}
90
91
92- (BOOL) inFullScreenMode
93{
94 return [gameView inFullScreenMode];
95}
96
97
98- (BOOL) setDisplayWidth:(unsigned int) d_width Height:(unsigned int) d_height Refresh:(unsigned int) d_refresh
99{
100 NSDictionary *d_mode = [self findDisplayModeForWidth: d_width Height: d_height Refresh: d_refresh];
101 if (d_mode)
102 {
103 width = d_width;
104 height = d_height;
105 refresh = d_refresh;
106 fullscreenDisplayMode = d_mode;
107
108 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
109
110 [userDefaults setInteger:width forKey:@"display_width"];
111 [userDefaults setInteger:height forKey:@"display_height"];
112 [userDefaults setInteger:refresh forKey:@"display_refresh"];
113
114 // Manual synchronization is required for SDL And doesn't hurt much for OS X.
115 [userDefaults synchronize];
116
117 return YES;
118 }
119 return NO;
120}
121
122
123- (NSDictionary *) findDisplayModeForWidth:(unsigned int) d_width Height:(unsigned int) d_height Refresh:(unsigned int) d_refresh
124{
125 int i, modeCount;
126 NSDictionary *mode;
127 unsigned int modeWidth, modeHeight, modeRefresh;
128
129 modeCount = [displayModes count];
130
131 for (i = 0; i < modeCount; i++)
132 {
133 mode = [displayModes objectAtIndex: i];
134 modeWidth = [[mode objectForKey:kOODisplayWidth] intValue];
135 modeHeight = [[mode objectForKey:kOODisplayHeight] intValue];
136 modeRefresh = [[mode objectForKey:kOODisplayRefreshRate] intValue];
137 if ((modeWidth == d_width)&&(modeHeight == d_height)&&(modeRefresh == d_refresh))
138 {
139 return mode;
140 }
141 }
142 return nil;
143}
144
145
146- (NSArray *) displayModes
147{
148 return [NSArray arrayWithArray:displayModes];
149}
150
151
152- (NSUInteger) indexOfCurrentDisplayMode
153{
154 NSDictionary *mode;
155
156 mode = [self findDisplayModeForWidth: width Height: height Refresh: refresh];
157 if (mode == nil)
158 return NSNotFound;
159 else
160 return [displayModes indexOfObject:mode];
161
162 return NSNotFound;
163}
164
165
166- (void) pauseFullScreenModeToPerform:(SEL) selector onTarget:(id) target
167{
168 pauseSelector = selector;
169 pauseTarget = target;
170 stayInFullScreenMode = NO;
171}
172
173@end
174
175#endif
#define DISPLAY_MAX_WIDTH
#define DISPLAY_MAX_HEIGHT
#define DISPLAY_MIN_HEIGHT
#define DISPLAY_MIN_WIDTH
return nil
const char int mode
Definition ioapi.h:133