author | rubidium |
Wed, 09 Jan 2008 18:11:12 +0000 | |
branch | noai |
changeset 9723 | eee46cb39750 |
parent 9722 | ebf0ece7d8f6 |
child 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" |
9722 | 65 |
|
66 |
||
67 |
@interface OTTDMain : NSObject |
|
68 |
@end |
|
69 |
||
70 |
||
71 |
static NSAutoreleasePool *_ottd_autorelease_pool; |
|
72 |
static OTTDMain *_ottd_main; |
|
73 |
static bool _cocoa_video_started = false; |
|
74 |
static bool _cocoa_video_dialog = false; |
|
75 |
||
76 |
CocoaSubdriver* _cocoa_subdriver = NULL; |
|
77 |
||
78 |
||
79 |
||
80 |
/* The main class of the application, the application's delegate */ |
|
81 |
@implementation OTTDMain |
|
82 |
/* Called when the internal event loop has just started running */ |
|
83 |
- (void) applicationDidFinishLaunching: (NSNotification*) note |
|
84 |
{ |
|
85 |
/* Hand off to main application code */ |
|
86 |
QZ_GameLoop(); |
|
87 |
||
88 |
/* We're done, thank you for playing */ |
|
89 |
[ NSApp stop:_ottd_main ]; |
|
90 |
} |
|
91 |
||
92 |
/* Display the in game quit confirmation dialog */ |
|
93 |
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender |
|
94 |
{ |
|
95 |
||
96 |
HandleExitGameRequest(); |
|
97 |
||
98 |
return NSTerminateCancel; // NSTerminateLater ? |
|
99 |
} |
|
100 |
@end |
|
101 |
||
102 |
static void setApplicationMenu() |
|
103 |
{ |
|
104 |
/* warning: this code is very odd */ |
|
105 |
NSMenu *appleMenu; |
|
106 |
NSMenuItem *menuItem; |
|
107 |
NSString *title; |
|
108 |
NSString *appName; |
|
109 |
||
110 |
appName = @"OTTD"; |
|
111 |
appleMenu = [[NSMenu alloc] initWithTitle:appName]; |
|
112 |
||
113 |
/* Add menu items */ |
|
114 |
title = [@"About " stringByAppendingString:appName]; |
|
115 |
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; |
|
116 |
||
117 |
[appleMenu addItem:[NSMenuItem separatorItem]]; |
|
118 |
||
119 |
title = [@"Hide " stringByAppendingString:appName]; |
|
120 |
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; |
|
121 |
||
122 |
menuItem = (NSMenuItem*)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; |
|
123 |
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; |
|
124 |
||
125 |
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; |
|
126 |
||
127 |
[appleMenu addItem:[NSMenuItem separatorItem]]; |
|
128 |
||
129 |
title = [@"Quit " stringByAppendingString:appName]; |
|
130 |
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; |
|
131 |
||
132 |
||
133 |
/* Put menu into the menubar */ |
|
134 |
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; |
|
135 |
[menuItem setSubmenu:appleMenu]; |
|
136 |
[[NSApp mainMenu] addItem:menuItem]; |
|
137 |
||
138 |
/* Tell the application object that this is now the application menu */ |
|
139 |
[NSApp setAppleMenu:appleMenu]; |
|
140 |
||
141 |
/* Finally give up our references to the objects */ |
|
142 |
[appleMenu release]; |
|
143 |
[menuItem release]; |
|
144 |
} |
|
145 |
||
146 |
/* Create a window menu */ |
|
147 |
static void setupWindowMenu() |
|
148 |
{ |
|
149 |
NSMenu* windowMenu; |
|
150 |
NSMenuItem* windowMenuItem; |
|
151 |
NSMenuItem* menuItem; |
|
152 |
||
153 |
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; |
|
154 |
||
155 |
/* "Minimize" item */ |
|
156 |
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; |
|
157 |
[windowMenu addItem:menuItem]; |
|
158 |
[menuItem release]; |
|
159 |
||
160 |
/* Put menu into the menubar */ |
|
161 |
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; |
|
162 |
[windowMenuItem setSubmenu:windowMenu]; |
|
163 |
[[NSApp mainMenu] addItem:windowMenuItem]; |
|
164 |
||
165 |
/* Tell the application object that this is now the window menu */ |
|
166 |
[NSApp setWindowsMenu:windowMenu]; |
|
167 |
||
168 |
/* Finally give up our references to the objects */ |
|
169 |
[windowMenu release]; |
|
170 |
[windowMenuItem release]; |
|
171 |
} |
|
172 |
||
173 |
static void setupApplication() |
|
174 |
{ |
|
175 |
CPSProcessSerNum PSN; |
|
176 |
||
177 |
/* Ensure the application object is initialised */ |
|
178 |
[NSApplication sharedApplication]; |
|
179 |
||
180 |
/* Tell the dock about us */ |
|
181 |
if (!CPSGetCurrentProcess(&PSN) && |
|
182 |
!CPSEnableForegroundOperation(&PSN, 0x03, 0x3C, 0x2C, 0x1103) && |
|
183 |
!CPSSetFrontProcess(&PSN)) { |
|
184 |
[NSApplication sharedApplication]; |
|
185 |
} |
|
186 |
||
187 |
/* Set up the menubar */ |
|
188 |
[NSApp setMainMenu:[[NSMenu alloc] init]]; |
|
189 |
setApplicationMenu(); |
|
190 |
setupWindowMenu(); |
|
191 |
||
192 |
/* Create OTTDMain and make it the app delegate */ |
|
193 |
_ottd_main = [[OTTDMain alloc] init]; |
|
194 |
[NSApp setDelegate:_ottd_main]; |
|
195 |
} |
|
196 |
||
197 |
||
198 |
static void QZ_UpdateVideoModes() |
|
199 |
{ |
|
200 |
uint i, count; |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
201 |
OTTD_Point modes[32]; |
9722 | 202 |
|
203 |
assert(_cocoa_subdriver != NULL); |
|
204 |
||
205 |
count = _cocoa_subdriver->ListModes(modes, lengthof(modes)); |
|
206 |
||
207 |
for (i = 0; i < count; i++) { |
|
208 |
_resolutions[i][0] = modes[i].x; |
|
209 |
_resolutions[i][1] = modes[i].y; |
|
210 |
} |
|
211 |
||
212 |
_num_resolutions = count; |
|
213 |
} |
|
214 |
||
215 |
||
216 |
void QZ_GameSizeChanged() |
|
217 |
{ |
|
218 |
if (_cocoa_subdriver == NULL) return; |
|
219 |
||
220 |
/* Tell the game that the resolution has changed */ |
|
221 |
_screen.width = _cocoa_subdriver->GetWidth(); |
|
222 |
_screen.height = _cocoa_subdriver->GetHeight(); |
|
223 |
_screen.pitch = _cocoa_subdriver->GetWidth(); |
|
224 |
_fullscreen = _cocoa_subdriver->IsFullscreen(); |
|
225 |
||
226 |
GameSizeChanged(); |
|
227 |
} |
|
228 |
||
229 |
||
230 |
static CocoaSubdriver *QZ_CreateWindowSubdriver(int width, int height, int bpp) |
|
231 |
{ |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
232 |
CocoaSubdriver *ret; |
9722 | 233 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
234 |
#ifdef ENABLE_COCOA_QUARTZ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
235 |
#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
|
236 |
/* 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
|
237 |
if (MacOSVersionIsAtLeast(10, 5, 0)) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
238 |
ret = QZ_CreateWindowQuartzSubdriver(width, height, bpp); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
239 |
if (ret != NULL) return ret; |
9722 | 240 |
} |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
241 |
#endif |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
242 |
#endif |
9722 | 243 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
244 |
#ifdef ENABLE_COCOA_QUICKDRAW |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
245 |
ret = QZ_CreateWindowQuickdrawSubdriver(width, height, bpp); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
246 |
if (ret != NULL) return ret; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
247 |
#endif |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
248 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
249 |
#ifdef ENABLE_COCOA_QUARTZ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
250 |
#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
|
251 |
/* |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
252 |
* 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
|
253 |
* 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
|
254 |
*/ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
255 |
if (MacOSVersionIsAtLeast(10, 4, 0)) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
256 |
ret = QZ_CreateWindowQuartzSubdriver(width, height, bpp); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
257 |
if (ret != NULL) return ret; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
258 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
259 |
#endif |
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 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
262 |
return NULL; |
9722 | 263 |
} |
264 |
||
265 |
||
266 |
static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool fullscreen, bool fallback) |
|
267 |
{ |
|
268 |
CocoaSubdriver *ret; |
|
269 |
||
270 |
ret = fullscreen ? QZ_CreateFullscreenSubdriver(width, height, bpp) : QZ_CreateWindowSubdriver(width, height, bpp); |
|
271 |
if (ret != NULL) return ret; |
|
272 |
||
273 |
if (!fallback) return NULL; |
|
274 |
||
275 |
/* Try again in 640x480 windowed */ |
|
276 |
DEBUG(driver, 0, "Setting video mode failed, falling back to 640x480 windowed mode."); |
|
277 |
ret = QZ_CreateWindowSubdriver(640, 480, bpp); |
|
278 |
if (ret != NULL) return ret; |
|
279 |
||
280 |
#ifdef _DEBUG |
|
281 |
/* Try fullscreen too when in debug mode */ |
|
282 |
DEBUG(driver, 0, "Setting video mode failed, falling back to 640x480 fullscreen mode."); |
|
283 |
ret = QZ_CreateFullscreenSubdriver(640, 480, bpp); |
|
284 |
if (ret != NULL) return ret; |
|
285 |
#endif |
|
286 |
||
287 |
return NULL; |
|
288 |
} |
|
289 |
||
290 |
||
291 |
static FVideoDriver_Cocoa iFVideoDriver_Cocoa; |
|
292 |
||
293 |
void VideoDriver_Cocoa::Stop() |
|
294 |
{ |
|
295 |
if (!_cocoa_video_started) return; |
|
296 |
||
297 |
delete _cocoa_subdriver; |
|
298 |
_cocoa_subdriver = NULL; |
|
299 |
||
300 |
[_ottd_main release]; |
|
301 |
||
302 |
_cocoa_video_started = false; |
|
303 |
} |
|
304 |
||
305 |
const char *VideoDriver_Cocoa::Start(const char * const *parm) |
|
306 |
{ |
|
307 |
int width, height, bpp; |
|
308 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
309 |
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
|
310 |
|
9722 | 311 |
if (_cocoa_video_started) return "Already started"; |
312 |
_cocoa_video_started = true; |
|
313 |
||
314 |
setupApplication(); |
|
315 |
||
316 |
/* Don't create a window or enter fullscreen if we're just going to show a dialog. */ |
|
317 |
if (_cocoa_video_dialog) return NULL; |
|
318 |
||
319 |
width = _cur_resolution[0]; |
|
320 |
height = _cur_resolution[1]; |
|
321 |
bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); |
|
322 |
||
323 |
_cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, _fullscreen, true); |
|
324 |
if (_cocoa_subdriver == NULL) { |
|
325 |
Stop(); |
|
326 |
return "Could not create subdriver"; |
|
327 |
} |
|
328 |
||
329 |
QZ_GameSizeChanged(); |
|
330 |
||
331 |
QZ_UpdateVideoModes(); |
|
332 |
||
333 |
return NULL; |
|
334 |
} |
|
335 |
||
336 |
void VideoDriver_Cocoa::MakeDirty(int left, int top, int width, int height) |
|
337 |
{ |
|
338 |
assert(_cocoa_subdriver != NULL); |
|
339 |
||
340 |
_cocoa_subdriver->MakeDirty(left, top, width, height); |
|
341 |
} |
|
342 |
||
343 |
void VideoDriver_Cocoa::MainLoop() |
|
344 |
{ |
|
345 |
/* Start the main event loop */ |
|
346 |
[NSApp run]; |
|
347 |
} |
|
348 |
||
349 |
bool VideoDriver_Cocoa::ChangeResolution(int w, int h) |
|
350 |
{ |
|
351 |
bool ret; |
|
352 |
||
353 |
assert(_cocoa_subdriver != NULL); |
|
354 |
||
355 |
ret = _cocoa_subdriver->ChangeResolution(w, h); |
|
356 |
||
357 |
QZ_GameSizeChanged(); |
|
358 |
||
359 |
QZ_UpdateVideoModes(); |
|
360 |
||
361 |
return ret; |
|
362 |
} |
|
363 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
364 |
bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen) |
9722 | 365 |
{ |
366 |
bool oldfs; |
|
367 |
||
368 |
assert(_cocoa_subdriver != NULL); |
|
369 |
||
370 |
oldfs = _cocoa_subdriver->IsFullscreen(); |
|
371 |
if (full_screen != oldfs) { |
|
372 |
int width = _cocoa_subdriver->GetWidth(); |
|
373 |
int height = _cocoa_subdriver->GetHeight(); |
|
374 |
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); |
|
375 |
||
376 |
delete _cocoa_subdriver; |
|
377 |
_cocoa_subdriver = NULL; |
|
378 |
||
379 |
_cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, full_screen, false); |
|
380 |
if (_cocoa_subdriver == NULL) { |
|
381 |
_cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, oldfs, true); |
|
382 |
if (_cocoa_subdriver == NULL) error("Cocoa: Failed to create subdriver"); |
|
383 |
} |
|
384 |
} |
|
385 |
||
386 |
QZ_GameSizeChanged(); |
|
387 |
||
388 |
QZ_UpdateVideoModes(); |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
389 |
return _cocoa_subdriver->IsFullscreen() == full_screen; |
9722 | 390 |
} |
391 |
||
392 |
||
393 |
/* This is needed since sometimes assert is called before the videodriver is initialized */ |
|
394 |
void CocoaDialog(const char* title, const char* message, const char* buttonLabel) |
|
395 |
{ |
|
396 |
bool wasstarted; |
|
397 |
||
398 |
_cocoa_video_dialog = true; |
|
399 |
||
400 |
wasstarted = _cocoa_video_started; |
|
401 |
if (_video_driver == NULL) { |
|
402 |
setupApplication(); // Setup application before showing dialog |
|
403 |
} else if (!_cocoa_video_started && _video_driver->Start(NULL) != NULL) { |
|
404 |
fprintf(stderr, "%s: %s\n", title, message); |
|
405 |
return; |
|
406 |
} |
|
407 |
||
408 |
NSRunAlertPanel([NSString stringWithCString: title], [NSString stringWithCString: message], [NSString stringWithCString: buttonLabel], nil, nil); |
|
409 |
||
410 |
if (!wasstarted && _video_driver != NULL) _video_driver->Stop(); |
|
411 |
||
412 |
_cocoa_video_dialog = false; |
|
413 |
} |
|
414 |
||
415 |
/* This is needed since OS X application bundles do not have a |
|
416 |
* current directory and the data files are 'somewhere' in the bundle */ |
|
417 |
void cocoaSetApplicationBundleDir() |
|
418 |
{ |
|
419 |
char tmp[MAXPATHLEN]; |
|
420 |
CFURLRef url = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); |
|
421 |
if (CFURLGetFileSystemRepresentation(url, true, (unsigned char*)tmp, MAXPATHLEN)) { |
|
422 |
AppendPathSeparator(tmp, lengthof(tmp)); |
|
423 |
_searchpaths[SP_APPLICATION_BUNDLE_DIR] = strdup(tmp); |
|
424 |
} else { |
|
425 |
_searchpaths[SP_APPLICATION_BUNDLE_DIR] = NULL; |
|
426 |
} |
|
427 |
||
428 |
CFRelease(url); |
|
429 |
} |
|
430 |
||
431 |
/* These are called from main() to prevent a _NSAutoreleaseNoPool error when |
|
432 |
* exiting before the cocoa video driver has been loaded |
|
433 |
*/ |
|
434 |
void cocoaSetupAutoreleasePool() |
|
435 |
{ |
|
436 |
_ottd_autorelease_pool = [[NSAutoreleasePool alloc] init]; |
|
437 |
} |
|
438 |
||
439 |
void cocoaReleaseAutoreleasePool() |
|
440 |
{ |
|
441 |
[_ottd_autorelease_pool release]; |
|
442 |
} |
|
443 |
||
444 |
#endif /* WITH_COCOA */ |