Oolite 1.91.0.7645-241119-222d325
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 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
74
75- (void) exitFullScreenMode
76{
77 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"fullscreen"];
78 stayInFullScreenMode = NO;
79}
80
81
82- (BOOL) inFullScreenMode
83{
84 return [gameView inFullScreenMode];
85}
86
87
88- (BOOL) setDisplayWidth:(unsigned int) d_width Height:(unsigned int) d_height Refresh:(unsigned int) d_refresh
89{
90 NSDictionary *d_mode = [self findDisplayModeForWidth: d_width Height: d_height Refresh: d_refresh];
91 if (d_mode)
92 {
93 width = d_width;
94 height = d_height;
95 refresh = d_refresh;
96 fullscreenDisplayMode = d_mode;
97
98 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
99
100 [userDefaults setInteger:width forKey:@"display_width"];
101 [userDefaults setInteger:height forKey:@"display_height"];
102 [userDefaults setInteger:refresh forKey:@"display_refresh"];
103
104 // Manual synchronization is required for SDL And doesn't hurt much for OS X.
105 [userDefaults synchronize];
106
107 return YES;
108 }
109 return NO;
110}
111
112
113- (NSDictionary *) findDisplayModeForWidth:(unsigned int) d_width Height:(unsigned int) d_height Refresh:(unsigned int) d_refresh
114{
115 int i, modeCount;
116 NSDictionary *mode;
117 unsigned int modeWidth, modeHeight, modeRefresh;
118
119 modeCount = [displayModes count];
120
121 for (i = 0; i < modeCount; i++)
122 {
123 mode = [displayModes objectAtIndex: i];
124 modeWidth = [[mode objectForKey:kOODisplayWidth] intValue];
125 modeHeight = [[mode objectForKey:kOODisplayHeight] intValue];
126 modeRefresh = [[mode objectForKey:kOODisplayRefreshRate] intValue];
127 if ((modeWidth == d_width)&&(modeHeight == d_height)&&(modeRefresh == d_refresh))
128 {
129 return mode;
130 }
131 }
132 return nil;
133}
134
135
136- (NSArray *) displayModes
137{
138 return [NSArray arrayWithArray:displayModes];
139}
140
141
142- (NSUInteger) indexOfCurrentDisplayMode
143{
144 NSDictionary *mode;
145
146 mode = [self findDisplayModeForWidth: width Height: height Refresh: refresh];
147 if (mode == nil)
148 return NSNotFound;
149 else
150 return [displayModes indexOfObject:mode];
151
152 return NSNotFound;
153}
154
155
156- (void) pauseFullScreenModeToPerform:(SEL) selector onTarget:(id) target
157{
158 pauseSelector = selector;
159 pauseTarget = target;
160 stayInFullScreenMode = NO;
161}
162
163@end
164
165#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