src/video/cocoa/cocoa_v.mm
author egladil
Sat, 24 Nov 2007 09:55:17 +0000
changeset 8448 a59e637a8eb3
parent 8439 bc2f9dfa0d40
child 8461 385ca6f76feb
permissions -rw-r--r--
(svn r11508) -Cleanup: Removed unused headers from the cocoa video driver.
2743
b3a6f4ddfdb8 (svn r3288) Set svn properties on cocoa related files, and add Id tag.
peter1138
parents: 2741
diff changeset
     1
/* $Id$ */
b3a6f4ddfdb8 (svn r3288) Set svn properties on cocoa related files, and add Id tag.
peter1138
parents: 2741
diff changeset
     2
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
     3
/******************************************************************************
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
     4
 *                             Cocoa video driver                             *
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
     5
 * Known things left to do:                                                   *
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
     6
 *  Nothing at the moment.                                                    *
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
     7
 ******************************************************************************/
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
     8
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
     9
#ifdef WITH_COCOA
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    10
6514
634933c84aef (svn r8967) -Fix (OSX): silent the warnings in cocoa_v.mm about deprecated stuff.. we know that\!
truelight
parents: 6485
diff changeset
    11
#include <AvailabilityMacros.h>
634933c84aef (svn r8967) -Fix (OSX): silent the warnings in cocoa_v.mm about deprecated stuff.. we know that\!
truelight
parents: 6485
diff changeset
    12
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    13
#import <Cocoa/Cocoa.h>
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    14
#import <sys/time.h> /* gettimeofday */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    15
#import <sys/param.h> /* for MAXPATHLEN */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    16
#import <unistd.h>
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    17
6192
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    18
/**
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    19
 * Important notice regarding all modifications!!!!!!!
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    20
 * There are certain limitations because the file is objective C++.
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    21
 * gdb has limitations.
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    22
 * C++ and objective C code can't be joined in all cases (classes stuff).
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    23
 * Read http://developer.apple.com/releasenotes/Cocoa/Objective-C++.html for more information.
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    24
 */
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    25
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    26
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    27
/* Portions of CPS.h */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    28
struct CPSProcessSerNum {
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
    29
	UInt32 lo;
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
    30
	UInt32 hi;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    31
};
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    32
6192
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    33
extern "C" OSErr CPSGetCurrentProcess(CPSProcessSerNum* psn);
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    34
extern "C" OSErr CPSEnableForegroundOperation(CPSProcessSerNum* psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    35
extern "C" OSErr CPSSetFrontProcess(CPSProcessSerNum* psn);
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    36
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    37
/* Disables a warning. This is needed since the method exists but has been dropped from the header, supposedly as of 10.4. */
2741
011462ebb67b (svn r3286) -Fix: [OSX] 10.2 works again and universal binaries got 10.2 as target by default
bjarni
parents: 2736
diff changeset
    38
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    39
@interface NSApplication(NSAppleMenu)
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    40
- (void)setAppleMenu:(NSMenu *)menu;
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    41
@end
2741
011462ebb67b (svn r3286) -Fix: [OSX] 10.2 works again and universal binaries got 10.2 as target by default
bjarni
parents: 2736
diff changeset
    42
#endif
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    43
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    44
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    45
/* Defined in stdbool.h */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    46
#ifndef __cplusplus
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    47
# ifndef __BEOS__
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    48
#  undef bool
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    49
#  undef false
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    50
#  undef true
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    51
# endif
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    52
#endif
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    53
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5832
diff changeset
    54
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
    55
#include "../../stdafx.h"
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
    56
#include "../../openttd.h"
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
    57
#include "../../debug.h"
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
    58
#include "../../variables.h"
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    59
#include "cocoa_v.h"
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
    60
#include "../../blitter/factory.hpp"
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
    61
#include "../../fileio.h"
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    62
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    63
#undef Point
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    64
#undef Rect
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    65
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    66
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    67
@interface OTTDMain : NSObject
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    68
@end
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    69
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    70
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    71
static NSAutoreleasePool *_ottd_autorelease_pool;
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    72
static OTTDMain *_ottd_main;
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
    73
static bool _cocoa_video_started = false;
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
    74
static bool _cocoa_video_dialog = false;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    75
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
    76
CocoaSubdriver* _cocoa_subdriver = NULL;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    77
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    78
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    79
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    80
/* The main class of the application, the application's delegate */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    81
@implementation OTTDMain
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    82
/* Called when the internal event loop has just started running */
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
    83
- (void) applicationDidFinishLaunching: (NSNotification*) note
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    84
{
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
    85
	/* Hand off to main application code */
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    86
	QZ_GameLoop();
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    87
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    88
	/* We're done, thank you for playing */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    89
	[ NSApp stop:_ottd_main ];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    90
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    91
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    92
/* Display the in game quit confirmation dialog */
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
    93
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    94
{
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    95
4550
d44b489e4413 (svn r6385) -Fix (r6380): one instance of QZ_AskQuit was left out in the conversion to HandleExitGameRequest.
rubidium
parents: 4549
diff changeset
    96
	HandleExitGameRequest();
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    97
4434
4175805666a5 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 4300
diff changeset
    98
	return NSTerminateCancel; // NSTerminateLater ?
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    99
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   100
@end
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   101
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6562
diff changeset
   102
static void setApplicationMenu()
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   103
{
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   104
	/* warning: this code is very odd */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   105
	NSMenu *appleMenu;
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   106
	NSMenuItem *menuItem;
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   107
	NSString *title;
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   108
	NSString *appName;
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   109
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   110
	appName = @"OTTD";
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   111
	appleMenu = [[NSMenu alloc] initWithTitle:appName];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   112
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   113
	/* Add menu items */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   114
	title = [@"About " stringByAppendingString:appName];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   115
	[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   116
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   117
	[appleMenu addItem:[NSMenuItem separatorItem]];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   118
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   119
	title = [@"Hide " stringByAppendingString:appName];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   120
	[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   121
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   122
	menuItem = (NSMenuItem*)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   123
	[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   124
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   125
	[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   126
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   127
	[appleMenu addItem:[NSMenuItem separatorItem]];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   128
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   129
	title = [@"Quit " stringByAppendingString:appName];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   130
	[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   131
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   132
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   133
	/* Put menu into the menubar */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   134
	menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   135
	[menuItem setSubmenu:appleMenu];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   136
	[[NSApp mainMenu] addItem:menuItem];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   137
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   138
	/* Tell the application object that this is now the application menu */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   139
	[NSApp setAppleMenu:appleMenu];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   140
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   141
	/* Finally give up our references to the objects */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   142
	[appleMenu release];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   143
	[menuItem release];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   144
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   145
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   146
/* Create a window menu */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6562
diff changeset
   147
static void setupWindowMenu()
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   148
{
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   149
	NSMenu* windowMenu;
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   150
	NSMenuItem* windowMenuItem;
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   151
	NSMenuItem* menuItem;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   152
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   153
	windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   154
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   155
	/* "Minimize" item */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   156
	menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   157
	[windowMenu addItem:menuItem];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   158
	[menuItem release];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   159
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   160
	/* Put menu into the menubar */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   161
	windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   162
	[windowMenuItem setSubmenu:windowMenu];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   163
	[[NSApp mainMenu] addItem:windowMenuItem];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   164
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   165
	/* Tell the application object that this is now the window menu */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   166
	[NSApp setWindowsMenu:windowMenu];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   167
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   168
	/* Finally give up our references to the objects */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   169
	[windowMenu release];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   170
	[windowMenuItem release];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   171
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   172
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6562
diff changeset
   173
static void setupApplication()
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   174
{
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   175
	CPSProcessSerNum PSN;
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   176
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   177
	/* Ensure the application object is initialised */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   178
	[NSApplication sharedApplication];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   179
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   180
	/* Tell the dock about us */
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   181
	if (!CPSGetCurrentProcess(&PSN) &&
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   182
			!CPSEnableForegroundOperation(&PSN, 0x03, 0x3C, 0x2C, 0x1103) &&
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   183
			!CPSSetFrontProcess(&PSN)) {
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   184
		[NSApplication sharedApplication];
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   185
	}
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   186
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   187
	/* Set up the menubar */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   188
	[NSApp setMainMenu:[[NSMenu alloc] init]];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   189
	setApplicationMenu();
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   190
	setupWindowMenu();
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   191
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   192
	/* Create OTTDMain and make it the app delegate */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   193
	_ottd_main = [[OTTDMain alloc] init];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   194
	[NSApp setDelegate:_ottd_main];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   195
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   196
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   197
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   198
static void QZ_UpdateVideoModes()
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   199
{
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   200
	uint i, count;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   201
	OTTDPoint modes[32];
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   202
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   203
	assert(_cocoa_subdriver != NULL);
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   204
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   205
	count = _cocoa_subdriver->ListModes(modes, lengthof(modes));
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   206
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   207
	for (i = 0; i < count; i++) {
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   208
		_resolutions[i][0] = modes[i].x;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   209
		_resolutions[i][1] = modes[i].y;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   210
	}
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   211
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   212
	_num_resolutions = count;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   213
}
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   214
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   215
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   216
void QZ_GameSizeChanged()
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   217
{
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   218
	if (_cocoa_subdriver == NULL) return;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   219
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   220
	/* Tell the game that the resolution has changed */
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   221
	_screen.width = _cocoa_subdriver->GetWidth();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   222
	_screen.height = _cocoa_subdriver->GetHeight();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   223
	_screen.pitch = _cocoa_subdriver->GetWidth();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   224
	_fullscreen = _cocoa_subdriver->IsFullscreen();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   225
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   226
	GameSizeChanged();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   227
}
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   228
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   229
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   230
static CocoaSubdriver *QZ_CreateWindowSubdriver(int width, int height, int bpp)
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   231
{
8439
bc2f9dfa0d40 (svn r11498) -Add [FS#1411]: [OSX] Added support for using Quartz instead of Quickdraw in windowed mode on OS X 10.4 and higher. Based on a patch by blackis.
egladil
parents: 8435
diff changeset
   232
	long sysVersion;
bc2f9dfa0d40 (svn r11498) -Add [FS#1411]: [OSX] Added support for using Quartz instead of Quickdraw in windowed mode on OS X 10.4 and higher. Based on a patch by blackis.
egladil
parents: 8435
diff changeset
   233
bc2f9dfa0d40 (svn r11498) -Add [FS#1411]: [OSX] Added support for using Quartz instead of Quickdraw in windowed mode on OS X 10.4 and higher. Based on a patch by blackis.
egladil
parents: 8435
diff changeset
   234
	if (Gestalt(gestaltSystemVersion, &sysVersion) == noErr && sysVersion >= 0x1040) {
bc2f9dfa0d40 (svn r11498) -Add [FS#1411]: [OSX] Added support for using Quartz instead of Quickdraw in windowed mode on OS X 10.4 and higher. Based on a patch by blackis.
egladil
parents: 8435
diff changeset
   235
		return QZ_CreateWindowQuartzSubdriver(width, height, bpp);
bc2f9dfa0d40 (svn r11498) -Add [FS#1411]: [OSX] Added support for using Quartz instead of Quickdraw in windowed mode on OS X 10.4 and higher. Based on a patch by blackis.
egladil
parents: 8435
diff changeset
   236
	}
bc2f9dfa0d40 (svn r11498) -Add [FS#1411]: [OSX] Added support for using Quartz instead of Quickdraw in windowed mode on OS X 10.4 and higher. Based on a patch by blackis.
egladil
parents: 8435
diff changeset
   237
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   238
	return QZ_CreateWindowQuickdrawSubdriver(width, height, bpp);
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   239
}
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   240
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   241
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   242
static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool fullscreen, bool fallback)
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   243
{
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   244
	CocoaSubdriver *ret;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   245
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   246
	ret = fullscreen ? QZ_CreateFullscreenSubdriver(width, height, bpp) : QZ_CreateWindowSubdriver(width, height, bpp);
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   247
	if (ret != NULL) return ret;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   248
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   249
	if (!fallback) return NULL;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   250
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   251
	/* Try again in 640x480 windowed */
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   252
	DEBUG(driver, 0, "Setting video mode failed, falling back to 640x480 windowed mode.");
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   253
	ret = QZ_CreateWindowSubdriver(640, 480, bpp);
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   254
	if (ret != NULL) return ret;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   255
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   256
#ifdef _DEBUG
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   257
	/* Try fullscreen too when in debug mode */
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   258
	DEBUG(driver, 0, "Setting video mode failed, falling back to 640x480 fullscreen mode.");
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   259
	ret = QZ_CreateFullscreenSubdriver(640, 480, bpp);
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   260
	if (ret != NULL) return ret;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   261
#endif
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   262
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   263
	return NULL;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   264
}
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   265
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   266
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7632
diff changeset
   267
static FVideoDriver_Cocoa iFVideoDriver_Cocoa;
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7632
diff changeset
   268
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7632
diff changeset
   269
void VideoDriver_Cocoa::Stop()
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   270
{
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   271
	if (!_cocoa_video_started) return;
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   272
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   273
	delete _cocoa_subdriver;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   274
	_cocoa_subdriver = NULL;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   275
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   276
	[_ottd_main release];
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   277
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   278
	_cocoa_video_started = false;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   279
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   280
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7632
diff changeset
   281
const char *VideoDriver_Cocoa::Start(const char * const *parm)
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   282
{
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   283
	int width, height, bpp;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   284
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   285
	if (_cocoa_video_started) return "Already started";
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   286
	_cocoa_video_started = true;
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   287
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   288
	setupApplication();
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   289
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   290
	/* Don't create a window or enter fullscreen if we're just going to show a dialog. */
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   291
	if (_cocoa_video_dialog) return NULL;
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   292
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   293
	width = _cur_resolution[0];
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   294
	height = _cur_resolution[1];
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   295
	bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   296
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   297
	_cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, _fullscreen, true);
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   298
	if (_cocoa_subdriver == NULL) {
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   299
		Stop();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   300
		return "Could not create subdriver";
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   301
	}
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   302
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   303
	QZ_GameSizeChanged();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   304
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   305
	QZ_UpdateVideoModes();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   306
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   307
	return NULL;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   308
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   309
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7632
diff changeset
   310
void VideoDriver_Cocoa::MakeDirty(int left, int top, int width, int height)
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   311
{
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   312
	assert(_cocoa_subdriver != NULL);
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   313
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   314
	_cocoa_subdriver->MakeDirty(left, top, width, height);
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   315
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   316
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7632
diff changeset
   317
void VideoDriver_Cocoa::MainLoop()
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   318
{
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   319
	/* Start the main event loop */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   320
	[NSApp run];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   321
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   322
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7632
diff changeset
   323
bool VideoDriver_Cocoa::ChangeResolution(int w, int h)
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   324
{
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   325
	bool ret;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   326
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   327
	assert(_cocoa_subdriver != NULL);
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   328
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   329
	ret = _cocoa_subdriver->ChangeResolution(w, h);
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   330
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   331
	QZ_GameSizeChanged();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   332
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   333
	QZ_UpdateVideoModes();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   334
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   335
	return ret;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   336
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   337
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7632
diff changeset
   338
void VideoDriver_Cocoa::ToggleFullscreen(bool full_screen)
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   339
{
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   340
	bool oldfs;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   341
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   342
	assert(_cocoa_subdriver != NULL);
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   343
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   344
	oldfs = _cocoa_subdriver->IsFullscreen();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   345
	if (full_screen != oldfs) {
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   346
		int width  = _cocoa_subdriver->GetWidth();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   347
		int height = _cocoa_subdriver->GetHeight();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   348
		int bpp    = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   349
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   350
		delete _cocoa_subdriver;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   351
		_cocoa_subdriver = NULL;
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   352
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   353
		_cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, full_screen, false);
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   354
		if (_cocoa_subdriver == NULL) {
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   355
			_cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, oldfs, true);
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   356
			if (_cocoa_subdriver == NULL) error("Cocoa: Failed to create subdriver");
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   357
		}
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   358
	}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   359
8435
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   360
	QZ_GameSizeChanged();
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   361
38a1ab65d6e4 (svn r11492) -Codechange: [OSX] Split the cocoa video driver into several files. The reason for this is that the fullscreen and windowed mode api are separate from each other in OS X and thus the driver actual is two drivers in one. This split is to make the code more readable and to prepare for replacing the Quickdraw windowed mode code which uses apis deprecated as of OS X 10.5 (and maybe earlier).
egladil
parents: 8423
diff changeset
   362
	QZ_UpdateVideoModes();
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   363
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   364
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   365
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   366
/* This is needed since sometimes assert is called before the videodriver is initialized */
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   367
void CocoaDialog(const char* title, const char* message, const char* buttonLabel)
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   368
{
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   369
	bool wasstarted;
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   370
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   371
	_cocoa_video_dialog = true;
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   372
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   373
	wasstarted = _cocoa_video_started;
7930
9d7da665872a (svn r10839) -Fix [FS#873]: bring up the assert window for OSX even when there isn't a video-driver loaded (PinguTux)
truelight
parents: 7807
diff changeset
   374
	if (_video_driver == NULL) {
9d7da665872a (svn r10839) -Fix [FS#873]: bring up the assert window for OSX even when there isn't a video-driver loaded (PinguTux)
truelight
parents: 7807
diff changeset
   375
		setupApplication(); // Setup application before showing dialog
9d7da665872a (svn r10839) -Fix [FS#873]: bring up the assert window for OSX even when there isn't a video-driver loaded (PinguTux)
truelight
parents: 7807
diff changeset
   376
	} else if (!_cocoa_video_started && _video_driver->Start(NULL) != NULL) {
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   377
		fprintf(stderr, "%s: %s\n", title, message);
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   378
		return;
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   379
	}
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   380
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   381
	NSRunAlertPanel([NSString stringWithCString: title], [NSString stringWithCString: message], [NSString stringWithCString: buttonLabel], nil, nil);
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   382
7930
9d7da665872a (svn r10839) -Fix [FS#873]: bring up the assert window for OSX even when there isn't a video-driver loaded (PinguTux)
truelight
parents: 7807
diff changeset
   383
	if (!wasstarted && _video_driver != NULL) _video_driver->Stop();
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   384
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   385
	_cocoa_video_dialog = false;
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   386
}
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   387
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   388
/* This is needed since OS X application bundles do not have a
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   389
 * current directory and the data files are 'somewhere' in the bundle */
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   390
void cocoaSetApplicationBundleDir()
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   391
{
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   392
	char tmp[MAXPATHLEN];
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   393
	CFURLRef url = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   394
	if (CFURLGetFileSystemRepresentation(url, true, (unsigned char*)tmp, MAXPATHLEN)) {
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   395
		AppendPathSeparator(tmp, lengthof(tmp));
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   396
		_searchpaths[SP_APPLICATION_BUNDLE_DIR] = strdup(tmp);
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   397
	} else {
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   398
		_searchpaths[SP_APPLICATION_BUNDLE_DIR] = NULL;
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   399
	}
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   400
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   401
	CFRelease(url);
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   402
}
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   403
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   404
/* These are called from main() to prevent a _NSAutoreleaseNoPool error when
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   405
 * exiting before the cocoa video driver has been loaded
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   406
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6562
diff changeset
   407
void cocoaSetupAutoreleasePool()
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   408
{
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   409
	_ottd_autorelease_pool = [[NSAutoreleasePool alloc] init];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   410
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   411
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6562
diff changeset
   412
void cocoaReleaseAutoreleasePool()
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   413
{
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   414
	[_ottd_autorelease_pool release];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   415
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   416
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   417
#endif /* WITH_COCOA */