src/video/cocoa/cocoa_v.mm
author belugas
Tue, 01 Jan 2008 14:20:48 +0000
changeset 8667 c916a5375166
parent 8623 652df321c912
child 10443 0cbb1eb8cbc7
permissions -rw-r--r--
(svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
-Fix[FS#1519]: When you can not use this resolution at full screen, now you'll know that it failed.
As for the reason it did not work, each computer/OS has its reason.
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
8461
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8448
diff changeset
    11
#define MAC_OS_X_VERSION_MIN_REQUIRED    MAC_OS_X_VERSION_10_3
6514
634933c84aef (svn r8967) -Fix (OSX): silent the warnings in cocoa_v.mm about deprecated stuff.. we know that\!
truelight
parents: 6485
diff changeset
    12
#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
    13
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    14
#import <Cocoa/Cocoa.h>
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    15
#import <sys/time.h> /* gettimeofday */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    16
#import <sys/param.h> /* for MAXPATHLEN */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    17
#import <unistd.h>
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    18
6192
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    19
/**
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    20
 * Important notice regarding all modifications!!!!!!!
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    21
 * 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
    22
 * gdb has limitations.
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    23
 * 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
    24
 * 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
    25
 */
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    26
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    27
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    28
/* Portions of CPS.h */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    29
struct CPSProcessSerNum {
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
    30
	UInt32 lo;
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
    31
	UInt32 hi;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    32
};
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    33
6192
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    34
extern "C" OSErr CPSGetCurrentProcess(CPSProcessSerNum* psn);
c6adfc929c6b (svn r8605) -Codechange: [OSX] changed all objective C to objective C++
bjarni
parents: 5993
diff changeset
    35
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
    36
extern "C" OSErr CPSSetFrontProcess(CPSProcessSerNum* psn);
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    37
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    38
/* 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
    39
#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
    40
@interface NSApplication(NSAppleMenu)
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    41
- (void)setAppleMenu:(NSMenu *)menu;
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    42
@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
    43
#endif
2736
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
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    46
/* Defined in stdbool.h */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    47
#ifndef __cplusplus
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    48
# ifndef __BEOS__
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    49
#  undef bool
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    50
#  undef false
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    51
#  undef true
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
#endif
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    54
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5832
diff changeset
    55
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
    56
#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
    57
#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
    58
#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
    59
#include "../../variables.h"
8623
652df321c912 (svn r11688) -Fix [FS#1581]: Compilation was broken on OS X again.
egladil
parents: 8588
diff changeset
    60
#include "../../core/geometry_type.hpp"
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
    61
#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
    62
#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
    63
#include "../../fileio.h"
8623
652df321c912 (svn r11688) -Fix [FS#1581]: Compilation was broken on OS X again.
egladil
parents: 8588
diff changeset
    64
#include "../../gfx_func.h"
2736
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;
8623
652df321c912 (svn r11688) -Fix [FS#1581]: Compilation was broken on OS X again.
egladil
parents: 8588
diff changeset
   201
	OTTD_Point modes[32];
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
   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
{
8461
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8448
diff changeset
   232
	CocoaSubdriver *ret;
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
   233
8588
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   234
#ifdef ENABLE_COCOA_QUARTZ
8480
0ca368be883d (svn r11540) -Fix: [OSX] Don't try to compile the quartz video driver on OSX 10.3. It will fail
bjarni
parents: 8461
diff changeset
   235
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
8535
cda5ffec8999 (svn r11599) -Change: [OSX] 10.4 will now use quickdraw for window mode instead of quartz
bjarni
parents: 8480
diff changeset
   236
	/* The reason for the version mismatch is due to the fact that the 10.4 binary needs to work on 10.5 as well. */
cda5ffec8999 (svn r11599) -Change: [OSX] 10.4 will now use quickdraw for window mode instead of quartz
bjarni
parents: 8480
diff changeset
   237
	if (MacOSVersionIsAtLeast(10, 5, 0)) {
8461
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8448
diff changeset
   238
		ret = QZ_CreateWindowQuartzSubdriver(width, height, bpp);
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8448
diff changeset
   239
		if (ret != NULL) return ret;
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
   240
	}
8480
0ca368be883d (svn r11540) -Fix: [OSX] Don't try to compile the quartz video driver on OSX 10.3. It will fail
bjarni
parents: 8461
diff changeset
   241
#endif
8588
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   242
#endif
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
   243
8588
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   244
#ifdef ENABLE_COCOA_QUICKDRAW
8461
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8448
diff changeset
   245
	ret = QZ_CreateWindowQuickdrawSubdriver(width, height, bpp);
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8448
diff changeset
   246
	if (ret != NULL) return ret;
8588
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   247
#endif
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   248
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   249
#ifdef ENABLE_COCOA_QUARTZ
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   250
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   251
        /*
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   252
	 * If we get here we are running 10.4 or earlier and either openttd was compiled without the quickdraw driver
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   253
	 * or it failed to load for some reason. Fall back to Quartz if possible even though that driver is slower.
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   254
	 */
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   255
        if (MacOSVersionIsAtLeast(10, 4, 0)) {
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   256
                ret = QZ_CreateWindowQuartzSubdriver(width, height, bpp);
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   257
                if (ret != NULL) return ret;
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   258
        }
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   259
#endif
9a8122b510f9 (svn r11653) -Feature: [OSX] Allow windowed mode subdrivers to be disabled at compile time.
egladil
parents: 8535
diff changeset
   260
#endif
8461
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8448
diff changeset
   261
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8448
diff changeset
   262
	return NULL;
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
   263
}
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
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
   266
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
   267
{
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
   268
	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
   269
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
   270
	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
   271
	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
   272
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
	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
   274
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
   275
	/* 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
   276
	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
   277
	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
   278
	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
   279
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
   280
#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
   281
	/* 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
   282
	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
   283
	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
   284
	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
   285
#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
   286
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
   287
	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
   288
}
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
   289
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   290
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
   291
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
   292
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
   293
void VideoDriver_Cocoa::Stop()
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   294
{
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   295
	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
   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
	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
   298
	_cocoa_subdriver = NULL;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   299
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   300
	[_ottd_main release];
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   301
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   302
	_cocoa_video_started = false;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   303
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   304
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
   305
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
   306
{
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
   307
	int width, height, bpp;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   308
8461
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8448
diff changeset
   309
	if (!MacOSVersionIsAtLeast(10, 3, 0)) return "The Cocoa video driver requires Mac OS X 10.3 or later.";
385ca6f76feb (svn r11521) -Codechange: [OSX] Check what the running os version is in a cleaner way.
egladil
parents: 8448
diff changeset
   310
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   311
	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
   312
	_cocoa_video_started = true;
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   313
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   314
	setupApplication();
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   315
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   316
	/* 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
   317
	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
   318
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
   319
	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
   320
	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
   321
	bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   322
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
   323
	_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
   324
	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
   325
		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
   326
		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
   327
	}
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   328
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
   329
	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
   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_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
   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
	return NULL;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   334
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   335
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
   336
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
   337
{
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
   338
	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
   339
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
	_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
   341
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   342
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
   343
void VideoDriver_Cocoa::MainLoop()
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   344
{
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   345
	/* Start the main event loop */
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   346
	[NSApp run];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   347
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   348
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
   349
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
   350
{
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
   351
	bool ret;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   352
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
   353
	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
   354
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
	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
   356
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
	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
   358
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
   359
	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
   360
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
	return ret;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   362
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   363
8667
c916a5375166 (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8623
diff changeset
   364
bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen)
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   365
{
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
   366
	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
   367
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
   368
	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
   369
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
   370
	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
   371
	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
   372
		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
   373
		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
   374
		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
   375
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
   376
		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
   377
		_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
   378
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
   379
		_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
   380
		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
   381
			_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
   382
			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
   383
		}
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   384
	}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   385
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
   386
	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
   387
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
   388
	QZ_UpdateVideoModes();
8667
c916a5375166 (svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents: 8623
diff changeset
   389
	return _cocoa_subdriver->IsFullscreen() == full_screen;
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   390
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   391
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   392
2827
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   393
/* This is needed since sometimes assert is called before the videodriver is initialized */
3036
d6670ee6981f (svn r3616) Style sweep
tron
parents: 3035
diff changeset
   394
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
   395
{
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   396
	bool wasstarted;
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   397
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   398
	_cocoa_video_dialog = true;
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   399
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   400
	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
   401
	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
   402
		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
   403
	} 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
   404
		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
   405
		return;
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   406
	}
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   407
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   408
	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
   409
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
   410
	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
   411
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   412
	_cocoa_video_dialog = false;
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   413
}
61e2ac8b0801 (svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents: 2743
diff changeset
   414
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   415
/* 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
   416
 * 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
   417
void cocoaSetApplicationBundleDir()
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   418
{
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   419
	char tmp[MAXPATHLEN];
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   420
	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
   421
	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
   422
		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
   423
		_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
   424
	} else {
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   425
		_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
   426
	}
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   427
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   428
	CFRelease(url);
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   429
}
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7377
diff changeset
   430
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   431
/* 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
   432
 * 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
   433
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6562
diff changeset
   434
void cocoaSetupAutoreleasePool()
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   435
{
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   436
	_ottd_autorelease_pool = [[NSAutoreleasePool alloc] init];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   437
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   438
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6562
diff changeset
   439
void cocoaReleaseAutoreleasePool()
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   440
{
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   441
	[_ottd_autorelease_pool release];
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   442
}
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   443
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff changeset
   444
#endif /* WITH_COCOA */