author | rubidium |
Sat, 21 Jun 2008 13:40:17 +0000 | |
branch | noai |
changeset 11044 | 097ea3e7ec56 |
parent 10455 | 22c441f5adf9 |
permissions | -rw-r--r-- |
9722 | 1 |
/* $Id$ */ |
2 |
||
3 |
/****************************************************************************** |
|
4 |
* Cocoa video driver * |
|
5 |
* Known things left to do: * |
|
6 |
* Nothing at the moment. * |
|
7 |
******************************************************************************/ |
|
8 |
||
9 |
#ifdef WITH_COCOA |
|
10 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
11 |
#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_3 |
9722 | 12 |
#include <AvailabilityMacros.h> |
13 |
||
14 |
#import <Cocoa/Cocoa.h> |
|
15 |
#import <sys/time.h> /* gettimeofday */ |
|
16 |
#import <sys/param.h> /* for MAXPATHLEN */ |
|
17 |
#import <unistd.h> |
|
18 |
||
19 |
/** |
|
20 |
* Important notice regarding all modifications!!!!!!! |
|
21 |
* There are certain limitations because the file is objective C++. |
|
22 |
* gdb has limitations. |
|
23 |
* C++ and objective C code can't be joined in all cases (classes stuff). |
|
24 |
* Read http://developer.apple.com/releasenotes/Cocoa/Objective-C++.html for more information. |
|
25 |
*/ |
|
26 |
||
27 |
||
28 |
/* Portions of CPS.h */ |
|
29 |
struct CPSProcessSerNum { |
|
30 |
UInt32 lo; |
|
31 |
UInt32 hi; |
|
32 |
}; |
|
33 |
||
34 |
extern "C" OSErr CPSGetCurrentProcess(CPSProcessSerNum* psn); |
|
35 |
extern "C" OSErr CPSEnableForegroundOperation(CPSProcessSerNum* psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); |
|
36 |
extern "C" OSErr CPSSetFrontProcess(CPSProcessSerNum* psn); |
|
37 |
||
38 |
/* Disables a warning. This is needed since the method exists but has been dropped from the header, supposedly as of 10.4. */ |
|
39 |
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) |
|
40 |
@interface NSApplication(NSAppleMenu) |
|
41 |
- (void)setAppleMenu:(NSMenu *)menu; |
|
42 |
@end |
|
43 |
#endif |
|
44 |
||
45 |
||
46 |
/* Defined in stdbool.h */ |
|
47 |
#ifndef __cplusplus |
|
48 |
# ifndef __BEOS__ |
|
49 |
# undef bool |
|
50 |
# undef false |
|
51 |
# undef true |
|
52 |
# endif |
|
53 |
#endif |
|
54 |
||
55 |
||
56 |
#include "../../stdafx.h" |
|
57 |
#include "../../openttd.h" |
|
58 |
#include "../../debug.h" |
|
59 |
#include "../../variables.h" |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
60 |
#include "../../core/geometry_type.hpp" |
9722 | 61 |
#include "cocoa_v.h" |
62 |
#include "../../blitter/factory.hpp" |
|
63 |
#include "../../fileio.h" |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
64 |
#include "../../gfx_func.h" |
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9723
diff
changeset
|
65 |
#include "../../functions.h" |
9722 | 66 |
|
67 |
||
68 |
@interface OTTDMain : NSObject |
|
69 |
@end |
|
70 |
||
71 |
||
72 |
static NSAutoreleasePool *_ottd_autorelease_pool; |
|
73 |
static OTTDMain *_ottd_main; |
|
74 |
static bool _cocoa_video_started = false; |
|
75 |
static bool _cocoa_video_dialog = false; |
|
76 |
||
77 |
CocoaSubdriver* _cocoa_subdriver = NULL; |
|
78 |
||
79 |
||
80 |
||
81 |
/* The main class of the application, the application's delegate */ |
|
82 |
@implementation OTTDMain |
|
83 |
/* Called when the internal event loop has just started running */ |
|
84 |
- (void) applicationDidFinishLaunching: (NSNotification*) note |
|
85 |
{ |
|
86 |
/* Hand off to main application code */ |
|
87 |
QZ_GameLoop(); |
|
88 |
||
89 |
/* We're done, thank you for playing */ |
|
90 |
[ NSApp stop:_ottd_main ]; |
|
91 |
} |
|
92 |
||
93 |
/* Display the in game quit confirmation dialog */ |
|
94 |
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender |
|
95 |
{ |
|
96 |
||
97 |
HandleExitGameRequest(); |
|
98 |
||
99 |
return NSTerminateCancel; // NSTerminateLater ? |
|
100 |
} |
|
101 |
@end |
|
102 |
||
103 |
static void setApplicationMenu() |
|
104 |
{ |
|
105 |
/* warning: this code is very odd */ |
|
106 |
NSMenu *appleMenu; |
|
107 |
NSMenuItem *menuItem; |
|
108 |
NSString *title; |
|
109 |
NSString *appName; |
|
110 |
||
111 |
appName = @"OTTD"; |
|
112 |
appleMenu = [[NSMenu alloc] initWithTitle:appName]; |
|
113 |
||
114 |
/* Add menu items */ |
|
115 |
title = [@"About " stringByAppendingString:appName]; |
|
116 |
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; |
|
117 |
||
118 |
[appleMenu addItem:[NSMenuItem separatorItem]]; |
|
119 |
||
120 |
title = [@"Hide " stringByAppendingString:appName]; |
|
121 |
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; |
|
122 |
||
123 |
menuItem = (NSMenuItem*)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; |
|
124 |
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; |
|
125 |
||
126 |
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; |
|
127 |
||
128 |
[appleMenu addItem:[NSMenuItem separatorItem]]; |
|
129 |
||
130 |
title = [@"Quit " stringByAppendingString:appName]; |
|
131 |
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; |
|
132 |
||
133 |
||
134 |
/* Put menu into the menubar */ |
|
135 |
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; |
|
136 |
[menuItem setSubmenu:appleMenu]; |
|
137 |
[[NSApp mainMenu] addItem:menuItem]; |
|
138 |
||
139 |
/* Tell the application object that this is now the application menu */ |
|
140 |
[NSApp setAppleMenu:appleMenu]; |
|
141 |
||
142 |
/* Finally give up our references to the objects */ |
|
143 |
[appleMenu release]; |
|
144 |
[menuItem release]; |
|
145 |
} |
|
146 |
||
147 |
/* Create a window menu */ |
|
148 |
static void setupWindowMenu() |
|
149 |
{ |
|
150 |
NSMenu* windowMenu; |
|
151 |
NSMenuItem* windowMenuItem; |
|
152 |
NSMenuItem* menuItem; |
|
153 |
||
154 |
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; |
|
155 |
||
156 |
/* "Minimize" item */ |
|
157 |
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; |
|
158 |
[windowMenu addItem:menuItem]; |
|
159 |
[menuItem release]; |
|
160 |
||
161 |
/* Put menu into the menubar */ |
|
162 |
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; |
|
163 |
[windowMenuItem setSubmenu:windowMenu]; |
|
164 |
[[NSApp mainMenu] addItem:windowMenuItem]; |
|
165 |
||
166 |
/* Tell the application object that this is now the window menu */ |
|
167 |
[NSApp setWindowsMenu:windowMenu]; |
|
168 |
||
169 |
/* Finally give up our references to the objects */ |
|
170 |
[windowMenu release]; |
|
171 |
[windowMenuItem release]; |
|
172 |
} |
|
173 |
||
174 |
static void setupApplication() |
|
175 |
{ |
|
176 |
CPSProcessSerNum PSN; |
|
177 |
||
178 |
/* Ensure the application object is initialised */ |
|
179 |
[NSApplication sharedApplication]; |
|
180 |
||
181 |
/* Tell the dock about us */ |
|
182 |
if (!CPSGetCurrentProcess(&PSN) && |
|
183 |
!CPSEnableForegroundOperation(&PSN, 0x03, 0x3C, 0x2C, 0x1103) && |
|
184 |
!CPSSetFrontProcess(&PSN)) { |
|
185 |
[NSApplication sharedApplication]; |
|
186 |
} |
|
187 |
||
188 |
/* Set up the menubar */ |
|
189 |
[NSApp setMainMenu:[[NSMenu alloc] init]]; |
|
190 |
setApplicationMenu(); |
|
191 |
setupWindowMenu(); |
|
192 |
||
193 |
/* Create OTTDMain and make it the app delegate */ |
|
194 |
_ottd_main = [[OTTDMain alloc] init]; |
|
195 |
[NSApp setDelegate:_ottd_main]; |
|
196 |
} |
|
197 |
||
198 |
||
199 |
static void QZ_UpdateVideoModes() |
|
200 |
{ |
|
201 |
uint i, count; |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
202 |
OTTD_Point modes[32]; |
9722 | 203 |
|
204 |
assert(_cocoa_subdriver != NULL); |
|
205 |
||
206 |
count = _cocoa_subdriver->ListModes(modes, lengthof(modes)); |
|
207 |
||
208 |
for (i = 0; i < count; i++) { |
|
11044
097ea3e7ec56
(svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents:
10455
diff
changeset
|
209 |
_resolutions[i].width = modes[i].x; |
097ea3e7ec56
(svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents:
10455
diff
changeset
|
210 |
_resolutions[i].height = modes[i].y; |
9722 | 211 |
} |
212 |
||
213 |
_num_resolutions = count; |
|
214 |
} |
|
215 |
||
216 |
||
217 |
void QZ_GameSizeChanged() |
|
218 |
{ |
|
219 |
if (_cocoa_subdriver == NULL) return; |
|
220 |
||
221 |
/* Tell the game that the resolution has changed */ |
|
222 |
_screen.width = _cocoa_subdriver->GetWidth(); |
|
223 |
_screen.height = _cocoa_subdriver->GetHeight(); |
|
224 |
_screen.pitch = _cocoa_subdriver->GetWidth(); |
|
225 |
_fullscreen = _cocoa_subdriver->IsFullscreen(); |
|
226 |
||
227 |
GameSizeChanged(); |
|
228 |
} |
|
229 |
||
230 |
||
231 |
static CocoaSubdriver *QZ_CreateWindowSubdriver(int width, int height, int bpp) |
|
232 |
{ |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
233 |
CocoaSubdriver *ret; |
9722 | 234 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
235 |
#ifdef ENABLE_COCOA_QUARTZ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
236 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
237 |
/* The reason for the version mismatch is due to the fact that the 10.4 binary needs to work on 10.5 as well. */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
238 |
if (MacOSVersionIsAtLeast(10, 5, 0)) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
239 |
ret = QZ_CreateWindowQuartzSubdriver(width, height, bpp); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
240 |
if (ret != NULL) return ret; |
9722 | 241 |
} |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
242 |
#endif |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
243 |
#endif |
9722 | 244 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
245 |
#ifdef ENABLE_COCOA_QUICKDRAW |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
246 |
ret = QZ_CreateWindowQuickdrawSubdriver(width, height, bpp); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
247 |
if (ret != NULL) return ret; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
248 |
#endif |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
249 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
250 |
#ifdef ENABLE_COCOA_QUARTZ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
251 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
252 |
/* |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
253 |
* If we get here we are running 10.4 or earlier and either openttd was compiled without the quickdraw driver |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
254 |
* or it failed to load for some reason. Fall back to Quartz if possible even though that driver is slower. |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
255 |
*/ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
256 |
if (MacOSVersionIsAtLeast(10, 4, 0)) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
257 |
ret = QZ_CreateWindowQuartzSubdriver(width, height, bpp); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
258 |
if (ret != NULL) return ret; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
259 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
260 |
#endif |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
261 |
#endif |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
262 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
263 |
return NULL; |
9722 | 264 |
} |
265 |
||
266 |
||
267 |
static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool fullscreen, bool fallback) |
|
268 |
{ |
|
269 |
CocoaSubdriver *ret; |
|
270 |
||
271 |
ret = fullscreen ? QZ_CreateFullscreenSubdriver(width, height, bpp) : QZ_CreateWindowSubdriver(width, height, bpp); |
|
272 |
if (ret != NULL) return ret; |
|
273 |
||
274 |
if (!fallback) return NULL; |
|
275 |
||
276 |
/* Try again in 640x480 windowed */ |
|
277 |
DEBUG(driver, 0, "Setting video mode failed, falling back to 640x480 windowed mode."); |
|
278 |
ret = QZ_CreateWindowSubdriver(640, 480, bpp); |
|
279 |
if (ret != NULL) return ret; |
|
280 |
||
281 |
#ifdef _DEBUG |
|
282 |
/* Try fullscreen too when in debug mode */ |
|
283 |
DEBUG(driver, 0, "Setting video mode failed, falling back to 640x480 fullscreen mode."); |
|
284 |
ret = QZ_CreateFullscreenSubdriver(640, 480, bpp); |
|
285 |
if (ret != NULL) return ret; |
|
286 |
#endif |
|
287 |
||
288 |
return NULL; |
|
289 |
} |
|
290 |
||
291 |
||
292 |
static FVideoDriver_Cocoa iFVideoDriver_Cocoa; |
|
293 |
||
294 |
void VideoDriver_Cocoa::Stop() |
|
295 |
{ |
|
296 |
if (!_cocoa_video_started) return; |
|
297 |
||
298 |
delete _cocoa_subdriver; |
|
299 |
_cocoa_subdriver = NULL; |
|
300 |
||
301 |
[_ottd_main release]; |
|
302 |
||
303 |
_cocoa_video_started = false; |
|
304 |
} |
|
305 |
||
306 |
const char *VideoDriver_Cocoa::Start(const char * const *parm) |
|
307 |
{ |
|
308 |
int width, height, bpp; |
|
309 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
310 |
if (!MacOSVersionIsAtLeast(10, 3, 0)) return "The Cocoa video driver requires Mac OS X 10.3 or later."; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
311 |
|
9722 | 312 |
if (_cocoa_video_started) return "Already started"; |
313 |
_cocoa_video_started = true; |
|
314 |
||
315 |
setupApplication(); |
|
316 |
||
317 |
/* Don't create a window or enter fullscreen if we're just going to show a dialog. */ |
|
318 |
if (_cocoa_video_dialog) return NULL; |
|
319 |
||
11044
097ea3e7ec56
(svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents:
10455
diff
changeset
|
320 |
width = _cur_resolution.width; |
097ea3e7ec56
(svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents:
10455
diff
changeset
|
321 |
height = _cur_resolution.height; |
9722 | 322 |
bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); |
323 |
||
324 |
_cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, _fullscreen, true); |
|
325 |
if (_cocoa_subdriver == NULL) { |
|
326 |
Stop(); |
|
327 |
return "Could not create subdriver"; |
|
328 |
} |
|
329 |
||
330 |
QZ_GameSizeChanged(); |
|
331 |
||
332 |
QZ_UpdateVideoModes(); |
|
333 |
||
334 |
return NULL; |
|
335 |
} |
|
336 |
||
337 |
void VideoDriver_Cocoa::MakeDirty(int left, int top, int width, int height) |
|
338 |
{ |
|
339 |
assert(_cocoa_subdriver != NULL); |
|
340 |
||
341 |
_cocoa_subdriver->MakeDirty(left, top, width, height); |
|
342 |
} |
|
343 |
||
344 |
void VideoDriver_Cocoa::MainLoop() |
|
345 |
{ |
|
346 |
/* Start the main event loop */ |
|
347 |
[NSApp run]; |
|
348 |
} |
|
349 |
||
350 |
bool VideoDriver_Cocoa::ChangeResolution(int w, int h) |
|
351 |
{ |
|
352 |
bool ret; |
|
353 |
||
354 |
assert(_cocoa_subdriver != NULL); |
|
355 |
||
356 |
ret = _cocoa_subdriver->ChangeResolution(w, h); |
|
357 |
||
358 |
QZ_GameSizeChanged(); |
|
359 |
||
360 |
QZ_UpdateVideoModes(); |
|
361 |
||
362 |
return ret; |
|
363 |
} |
|
364 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
365 |
bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen) |
9722 | 366 |
{ |
367 |
bool oldfs; |
|
368 |
||
369 |
assert(_cocoa_subdriver != NULL); |
|
370 |
||
371 |
oldfs = _cocoa_subdriver->IsFullscreen(); |
|
372 |
if (full_screen != oldfs) { |
|
373 |
int width = _cocoa_subdriver->GetWidth(); |
|
374 |
int height = _cocoa_subdriver->GetHeight(); |
|
375 |
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); |
|
376 |
||
377 |
delete _cocoa_subdriver; |
|
378 |
_cocoa_subdriver = NULL; |
|
379 |
||
380 |
_cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, full_screen, false); |
|
381 |
if (_cocoa_subdriver == NULL) { |
|
382 |
_cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, oldfs, true); |
|
383 |
if (_cocoa_subdriver == NULL) error("Cocoa: Failed to create subdriver"); |
|
384 |
} |
|
385 |
} |
|
386 |
||
387 |
QZ_GameSizeChanged(); |
|
388 |
||
389 |
QZ_UpdateVideoModes(); |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
390 |
return _cocoa_subdriver->IsFullscreen() == full_screen; |
9722 | 391 |
} |
392 |
||
393 |
||
394 |
/* This is needed since sometimes assert is called before the videodriver is initialized */ |
|
395 |
void CocoaDialog(const char* title, const char* message, const char* buttonLabel) |
|
396 |
{ |
|
397 |
bool wasstarted; |
|
398 |
||
399 |
_cocoa_video_dialog = true; |
|
400 |
||
401 |
wasstarted = _cocoa_video_started; |
|
402 |
if (_video_driver == NULL) { |
|
403 |
setupApplication(); // Setup application before showing dialog |
|
404 |
} else if (!_cocoa_video_started && _video_driver->Start(NULL) != NULL) { |
|
405 |
fprintf(stderr, "%s: %s\n", title, message); |
|
406 |
return; |
|
407 |
} |
|
408 |
||
409 |
NSRunAlertPanel([NSString stringWithCString: title], [NSString stringWithCString: message], [NSString stringWithCString: buttonLabel], nil, nil); |
|
410 |
||
411 |
if (!wasstarted && _video_driver != NULL) _video_driver->Stop(); |
|
412 |
||
413 |
_cocoa_video_dialog = false; |
|
414 |
} |
|
415 |
||
416 |
/* This is needed since OS X application bundles do not have a |
|
417 |
* current directory and the data files are 'somewhere' in the bundle */ |
|
418 |
void cocoaSetApplicationBundleDir() |
|
419 |
{ |
|
420 |
char tmp[MAXPATHLEN]; |
|
421 |
CFURLRef url = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); |
|
422 |
if (CFURLGetFileSystemRepresentation(url, true, (unsigned char*)tmp, MAXPATHLEN)) { |
|
423 |
AppendPathSeparator(tmp, lengthof(tmp)); |
|
424 |
_searchpaths[SP_APPLICATION_BUNDLE_DIR] = strdup(tmp); |
|
425 |
} else { |
|
426 |
_searchpaths[SP_APPLICATION_BUNDLE_DIR] = NULL; |
|
427 |
} |
|
428 |
||
429 |
CFRelease(url); |
|
430 |
} |
|
431 |
||
432 |
/* These are called from main() to prevent a _NSAutoreleaseNoPool error when |
|
433 |
* exiting before the cocoa video driver has been loaded |
|
434 |
*/ |
|
435 |
void cocoaSetupAutoreleasePool() |
|
436 |
{ |
|
437 |
_ottd_autorelease_pool = [[NSAutoreleasePool alloc] init]; |
|
438 |
} |
|
439 |
||
440 |
void cocoaReleaseAutoreleasePool() |
|
441 |
{ |
|
442 |
[_ottd_autorelease_pool release]; |
|
443 |
} |
|
444 |
||
445 |
#endif /* WITH_COCOA */ |