| author | tron |
| Sat, 04 Mar 2006 11:01:35 +0000 | |
| changeset 3139 | b17abef09e15 |
| parent 3129 | 79dc90ebf03a |
| child 3261 | e17a3e96f11e |
| permissions | -rw-r--r-- |
|
2743
a6c91eb763e8
(svn r3288) Set svn properties on cocoa related files, and add Id tag.
peter1138
parents:
2741
diff
changeset
|
1 |
/* $Id$ */ |
|
a6c91eb763e8
(svn r3288) Set svn properties on cocoa related files, and add Id tag.
peter1138
parents:
2741
diff
changeset
|
2 |
|
| 3036 | 3 |
/****************************************************************************** |
4 |
* Cocoa video driver * |
|
5 |
* Known things left to do: * |
|
6 |
* Nothing at the moment. * |
|
7 |
******************************************************************************/ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
8 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
9 |
#ifdef WITH_COCOA |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
10 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
11 |
#import <Cocoa/Cocoa.h> |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
12 |
#import <sys/time.h> /* gettimeofday */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
13 |
#import <sys/param.h> /* for MAXPATHLEN */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
14 |
#import <unistd.h> |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
15 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
16 |
/* Portions of CPS.h */ |
| 3036 | 17 |
typedef struct CPSProcessSerNum {
|
18 |
UInt32 lo; |
|
19 |
UInt32 hi; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
20 |
} CPSProcessSerNum; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
21 |
|
| 3036 | 22 |
extern OSErr CPSGetCurrentProcess(CPSProcessSerNum* psn); |
23 |
extern OSErr CPSEnableForegroundOperation(CPSProcessSerNum* psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); |
|
24 |
extern OSErr CPSSetFrontProcess(CPSProcessSerNum* psn); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
25 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
26 |
/* From Menus.h (according to Xcode Developer Documentation) */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
27 |
extern void ShowMenuBar(void); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
28 |
extern void HideMenuBar(void); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
29 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
30 |
/* Disables a warning. This is needed since the method exists but has been dropped from the header, supposedly as of 10.4. */ |
|
2741
65d4de069014
(svn r3286) -Fix: [OSX] 10.2 works again and universal binaries got 10.2 as target by default
bjarni
parents:
2736
diff
changeset
|
31 |
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
32 |
@interface NSApplication(NSAppleMenu) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
33 |
- (void)setAppleMenu:(NSMenu *)menu; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
34 |
@end |
|
2741
65d4de069014
(svn r3286) -Fix: [OSX] 10.2 works again and universal binaries got 10.2 as target by default
bjarni
parents:
2736
diff
changeset
|
35 |
#endif |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
36 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
37 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
38 |
/* Defined in ppc/param.h or i386/param.h included from sys/param.h */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
39 |
#undef ALIGN |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
40 |
/* Defined in stdbool.h */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
41 |
#ifndef __cplusplus |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
42 |
# ifndef __BEOS__ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
43 |
# undef bool |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
44 |
# undef false |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
45 |
# undef true |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
46 |
# endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
47 |
#endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
48 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
49 |
#include "../stdafx.h" |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
50 |
#include "../openttd.h" |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
51 |
#include "../debug.h" |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
52 |
#include "../functions.h" |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
53 |
#include "../gfx.h" |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
54 |
#include "../macros.h" |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
55 |
#include "../sdl.h" |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
56 |
#include "../window.h" |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
57 |
#include "../network.h" |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
58 |
#include "../variables.h" |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
59 |
#include "../os/macosx/splash.h" |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
60 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
61 |
#include "cocoa_v.h" |
|
3035
fbc01469d2ba
(svn r3615) Remove the Quartz key codes from the public cocoa video driver interface
tron
parents:
3016
diff
changeset
|
62 |
#include "cocoa_keys.h" |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
63 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
64 |
#undef Point |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
65 |
#undef Rect |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
66 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
67 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
68 |
/* Subclass of NSWindow to fix genie effect and support resize events */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
69 |
@interface OTTD_QuartzWindow : NSWindow |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
70 |
- (void)miniaturize:(id)sender; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
71 |
- (void)display; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
72 |
- (void)setFrame:(NSRect)frameRect display:(BOOL)flag; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
73 |
- (void)appDidHide:(NSNotification*)note; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
74 |
- (void)appWillUnhide:(NSNotification*)note; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
75 |
- (void)appDidUnhide:(NSNotification*)note; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
76 |
- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
77 |
@end |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
78 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
79 |
/* Delegate for our NSWindow to send ask for quit on close */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
80 |
@interface OTTD_QuartzWindowDelegate : NSObject |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
81 |
- (BOOL)windowShouldClose:(id)sender; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
82 |
@end |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
83 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
84 |
@interface OTTDMain : NSObject |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
85 |
@end |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
86 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
87 |
|
| 3036 | 88 |
/* Structure for rez switch gamma fades |
89 |
* We can hide the monitor flicker by setting the gamma tables to 0 |
|
90 |
*/ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
91 |
#define QZ_GAMMA_TABLE_SIZE 256 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
92 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
93 |
typedef struct {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
94 |
CGGammaValue red[QZ_GAMMA_TABLE_SIZE]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
95 |
CGGammaValue green[QZ_GAMMA_TABLE_SIZE]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
96 |
CGGammaValue blue[QZ_GAMMA_TABLE_SIZE]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
97 |
} OTTD_QuartzGammaTable; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
98 |
|
| 3036 | 99 |
/* Add methods to get at private members of NSScreen. |
100 |
* Since there is a bug in Apple's screen switching code that does not update |
|
101 |
* this variable when switching to fullscreen, we'll set it manually (but only |
|
102 |
* for the main screen). |
|
103 |
*/ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
104 |
@interface NSScreen (NSScreenAccess) |
| 3036 | 105 |
- (void) setFrame:(NSRect)frame; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
106 |
@end |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
107 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
108 |
@implementation NSScreen (NSScreenAccess) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
109 |
- (void) setFrame:(NSRect)frame; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
110 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
111 |
_frame = frame; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
112 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
113 |
@end |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
114 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
115 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
116 |
static void QZ_Draw(void); |
| 3036 | 117 |
static void QZ_UnsetVideoMode(void); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
118 |
static void QZ_UpdatePalette(uint start, uint count); |
| 3036 | 119 |
static void QZ_WarpCursor(int x, int y); |
120 |
static void QZ_ShowMouse(void); |
|
121 |
static void QZ_HideMouse(void); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
122 |
static void CocoaVideoFullScreen(bool full_screen); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
123 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
124 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
125 |
static NSAutoreleasePool *_ottd_autorelease_pool; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
126 |
static OTTDMain *_ottd_main; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
127 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
128 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
129 |
static struct CocoaVideoData {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
130 |
bool isset; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
131 |
bool issetting; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
132 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
133 |
CGDirectDisplayID display_id; /* 0 == main display (only support single display) */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
134 |
CFDictionaryRef mode; /* current mode of the display */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
135 |
CFDictionaryRef save_mode; /* original mode of the display */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
136 |
CFArrayRef mode_list; /* list of available fullscreen modes */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
137 |
CGDirectPaletteRef palette; /* palette of an 8-bit display */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
138 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
139 |
uint32 device_width; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
140 |
uint32 device_height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
141 |
uint32 device_bpp; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
142 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
143 |
void *realpixels; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
144 |
uint8 *pixels; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
145 |
uint32 width; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
146 |
uint32 height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
147 |
uint32 pitch; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
148 |
bool fullscreen; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
149 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
150 |
unsigned int current_mods; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
151 |
bool tab_is_down; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
152 |
bool emulating_right_button; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
153 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
154 |
bool cursor_visible; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
155 |
bool active; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
156 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
157 |
#ifdef _DEBUG |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
158 |
uint32 tEvent; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
159 |
#endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
160 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
161 |
OTTD_QuartzWindow *window; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
162 |
NSQuickDrawView *qdview; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
163 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
164 |
#define MAX_DIRTY_RECTS 100 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
165 |
OTTDRect dirty_rects[MAX_DIRTY_RECTS]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
166 |
int num_dirty_rects; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
167 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
168 |
uint16 palette16[256]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
169 |
uint32 palette32[256]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
170 |
} _cocoa_video_data; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
171 |
|
|
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
172 |
static bool _cocoa_video_started = false; |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
173 |
static bool _cocoa_video_dialog = false; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
174 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
175 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
176 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
177 |
|
| 3036 | 178 |
/****************************************************************************** |
179 |
* Game loop and accessories * |
|
180 |
******************************************************************************/ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
181 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
182 |
static uint32 GetTick(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
183 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
184 |
struct timeval tim; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
185 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
186 |
gettimeofday(&tim, NULL); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
187 |
return tim.tv_usec / 1000 + tim.tv_sec * 1000; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
188 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
189 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
190 |
static void QZ_CheckPaletteAnim(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
191 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
192 |
if (_pal_last_dirty != -1) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
193 |
QZ_UpdatePalette(_pal_first_dirty, _pal_last_dirty - _pal_first_dirty + 1); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
194 |
_pal_last_dirty = -1; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
195 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
196 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
197 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
198 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
199 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
200 |
extern void DoExitSave(void); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
201 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
202 |
static void QZ_AskQuit(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
203 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
204 |
if (_game_mode == GM_MENU) { // do not ask to quit on the main screen
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
205 |
_exit_game = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
206 |
} else if (_patches.autosave_on_exit) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
207 |
DoExitSave(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
208 |
_exit_game = true; |
| 3036 | 209 |
} else {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
210 |
AskExitGame(); |
| 3036 | 211 |
} |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
212 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
213 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
214 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
215 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
216 |
typedef struct VkMapping {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
217 |
unsigned short vk_from; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
218 |
byte map_to; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
219 |
} VkMapping; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
220 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
221 |
#define AS(x, z) {x, z}
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
222 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
223 |
static const VkMapping _vk_mapping[] = {
|
| 3036 | 224 |
AS(QZ_BACKQUOTE, WKC_BACKQUOTE), // key left of '1' |
225 |
AS(QZ_BACKQUOTE2, WKC_BACKQUOTE), // some keyboards have it on another scancode |
|
|
2845
e520ad0a77b7
(svn r3393) -Fix: [OSX] some keyboards had a different scancode for opening the console (egladil)
bjarni
parents:
2827
diff
changeset
|
226 |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
227 |
// Pageup stuff + up/down |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
228 |
//AM(SDLK_PAGEUP, SDLK_PAGEDOWN, WKC_PAGEUP, WKC_PAGEDOWN), <==== Does this include HOME/END? |
| 3036 | 229 |
AS(QZ_PAGEUP, WKC_PAGEUP), |
230 |
AS(QZ_PAGEDOWN, WKC_PAGEDOWN), |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
231 |
|
| 3036 | 232 |
AS(QZ_UP, WKC_UP), |
233 |
AS(QZ_DOWN, WKC_DOWN), |
|
234 |
AS(QZ_LEFT, WKC_LEFT), |
|
235 |
AS(QZ_RIGHT, WKC_RIGHT), |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
236 |
|
| 3036 | 237 |
AS(QZ_HOME, WKC_HOME), |
238 |
AS(QZ_END, WKC_END), |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
239 |
|
| 3036 | 240 |
AS(QZ_INSERT, WKC_INSERT), |
241 |
AS(QZ_DELETE, WKC_DELETE), |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
242 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
243 |
// Letters. QZ_[a-z] is not in numerical order so we can't use AM(...) |
| 3036 | 244 |
AS(QZ_a, 'A'), |
245 |
AS(QZ_b, 'B'), |
|
246 |
AS(QZ_c, 'C'), |
|
247 |
AS(QZ_d, 'D'), |
|
248 |
AS(QZ_e, 'E'), |
|
249 |
AS(QZ_f, 'F'), |
|
250 |
AS(QZ_g, 'G'), |
|
251 |
AS(QZ_h, 'H'), |
|
252 |
AS(QZ_i, 'I'), |
|
253 |
AS(QZ_j, 'J'), |
|
254 |
AS(QZ_k, 'K'), |
|
255 |
AS(QZ_l, 'L'), |
|
256 |
AS(QZ_m, 'M'), |
|
257 |
AS(QZ_n, 'N'), |
|
258 |
AS(QZ_o, 'O'), |
|
259 |
AS(QZ_p, 'P'), |
|
260 |
AS(QZ_q, 'Q'), |
|
261 |
AS(QZ_r, 'R'), |
|
262 |
AS(QZ_s, 'S'), |
|
263 |
AS(QZ_t, 'T'), |
|
264 |
AS(QZ_u, 'U'), |
|
265 |
AS(QZ_v, 'V'), |
|
266 |
AS(QZ_w, 'W'), |
|
267 |
AS(QZ_x, 'X'), |
|
268 |
AS(QZ_y, 'Y'), |
|
269 |
AS(QZ_z, 'Z'), |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
270 |
// Same thing for digits |
| 3036 | 271 |
AS(QZ_0, '0'), |
272 |
AS(QZ_1, '1'), |
|
273 |
AS(QZ_2, '2'), |
|
274 |
AS(QZ_3, '3'), |
|
275 |
AS(QZ_4, '4'), |
|
276 |
AS(QZ_5, '5'), |
|
277 |
AS(QZ_6, '6'), |
|
278 |
AS(QZ_7, '7'), |
|
279 |
AS(QZ_8, '8'), |
|
280 |
AS(QZ_9, '9'), |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
281 |
|
| 3036 | 282 |
AS(QZ_ESCAPE, WKC_ESC), |
283 |
AS(QZ_PAUSE, WKC_PAUSE), |
|
284 |
AS(QZ_BACKSPACE, WKC_BACKSPACE), |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
285 |
|
| 3036 | 286 |
AS(QZ_SPACE, WKC_SPACE), |
287 |
AS(QZ_RETURN, WKC_RETURN), |
|
288 |
AS(QZ_TAB, WKC_TAB), |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
289 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
290 |
// Function keys |
| 3036 | 291 |
AS(QZ_F1, WKC_F1), |
292 |
AS(QZ_F2, WKC_F2), |
|
293 |
AS(QZ_F3, WKC_F3), |
|
294 |
AS(QZ_F4, WKC_F4), |
|
295 |
AS(QZ_F5, WKC_F5), |
|
296 |
AS(QZ_F6, WKC_F6), |
|
297 |
AS(QZ_F7, WKC_F7), |
|
298 |
AS(QZ_F8, WKC_F8), |
|
299 |
AS(QZ_F9, WKC_F9), |
|
300 |
AS(QZ_F10, WKC_F10), |
|
301 |
AS(QZ_F11, WKC_F11), |
|
302 |
AS(QZ_F12, WKC_F12), |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
303 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
304 |
// Numeric part. |
| 3036 | 305 |
AS(QZ_KP0, WKC_NUM_0), |
306 |
AS(QZ_KP1, WKC_NUM_1), |
|
307 |
AS(QZ_KP2, WKC_NUM_2), |
|
308 |
AS(QZ_KP3, WKC_NUM_3), |
|
309 |
AS(QZ_KP4, WKC_NUM_4), |
|
310 |
AS(QZ_KP5, WKC_NUM_5), |
|
311 |
AS(QZ_KP6, WKC_NUM_6), |
|
312 |
AS(QZ_KP7, WKC_NUM_7), |
|
313 |
AS(QZ_KP8, WKC_NUM_8), |
|
314 |
AS(QZ_KP9, WKC_NUM_9), |
|
315 |
AS(QZ_KP_DIVIDE, WKC_NUM_DIV), |
|
316 |
AS(QZ_KP_MULTIPLY, WKC_NUM_MUL), |
|
317 |
AS(QZ_KP_MINUS, WKC_NUM_MINUS), |
|
318 |
AS(QZ_KP_PLUS, WKC_NUM_PLUS), |
|
319 |
AS(QZ_KP_ENTER, WKC_NUM_ENTER), |
|
320 |
AS(QZ_KP_PERIOD, WKC_NUM_DECIMAL) |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
321 |
}; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
322 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
323 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
324 |
static uint32 QZ_MapKey(unsigned short sym) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
325 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
326 |
const VkMapping *map; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
327 |
uint32 key = 0; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
328 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
329 |
for (map = _vk_mapping; map != endof(_vk_mapping); ++map) {
|
| 3036 | 330 |
if (sym == map->vk_from) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
331 |
key = map->map_to; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
332 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
333 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
334 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
335 |
|
| 3036 | 336 |
if (_cocoa_video_data.current_mods & NSShiftKeyMask) key |= WKC_SHIFT; |
337 |
if (_cocoa_video_data.current_mods & NSControlKeyMask) key |= WKC_CTRL; |
|
338 |
if (_cocoa_video_data.current_mods & NSAlternateKeyMask) key |= WKC_ALT; |
|
339 |
if (_cocoa_video_data.current_mods & NSCommandKeyMask) key |= WKC_META; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
340 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
341 |
return key << 16; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
342 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
343 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
344 |
static void QZ_KeyEvent(unsigned short keycode, unsigned short unicode, BOOL down) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
345 |
{
|
| 3036 | 346 |
switch (keycode) {
|
347 |
case QZ_UP: SB(_dirkeys, 1, 1, down); break; |
|
348 |
case QZ_DOWN: SB(_dirkeys, 3, 1, down); break; |
|
349 |
case QZ_LEFT: SB(_dirkeys, 0, 1, down); break; |
|
350 |
case QZ_RIGHT: SB(_dirkeys, 2, 1, down); break; |
|
351 |
||
352 |
case QZ_TAB: _cocoa_video_data.tab_is_down = down; break; |
|
353 |
||
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
354 |
case QZ_RETURN: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
355 |
case QZ_f: |
| 3036 | 356 |
if (down && ( |
357 |
(_cocoa_video_data.current_mods & NSControlKeyMask) || |
|
358 |
(_cocoa_video_data.current_mods & NSCommandKeyMask) |
|
359 |
)) {
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
360 |
CocoaVideoFullScreen(!_fullscreen); |
| 3036 | 361 |
} |
362 |
break; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
363 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
364 |
|
| 3036 | 365 |
if (down) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
366 |
_pressed_key = QZ_MapKey(keycode) | unicode; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
367 |
DEBUG(driver, 2)("cocoa_v: QZ_KeyEvent: %x (%x), down, mapping: %x", keycode, unicode, _pressed_key);
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
368 |
} else {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
369 |
DEBUG(driver, 2)("cocoa_v: QZ_KeyEvent: %x (%x), up", keycode, unicode);
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
370 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
371 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
372 |
|
| 3036 | 373 |
static void QZ_DoUnsidedModifiers(unsigned int newMods) |
374 |
{
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
375 |
const int mapping[] = { QZ_CAPSLOCK, QZ_LSHIFT, QZ_LCTRL, QZ_LALT, QZ_LMETA };
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
376 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
377 |
int i; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
378 |
int bit; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
379 |
|
| 3036 | 380 |
if (_cocoa_video_data.current_mods == newMods) return; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
381 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
382 |
/* Iterate through the bits, testing each against the current modifiers */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
383 |
for (i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
384 |
unsigned int currentMask, newMask; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
385 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
386 |
currentMask = _cocoa_video_data.current_mods & bit; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
387 |
newMask = newMods & bit; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
388 |
|
| 3036 | 389 |
if (currentMask && currentMask != newMask) { /* modifier up event */
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
390 |
/* If this was Caps Lock, we need some additional voodoo to make SDL happy (is this needed in ottd?) */ |
| 3036 | 391 |
if (bit == NSAlphaShiftKeyMask) QZ_KeyEvent(mapping[i], 0, YES); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
392 |
QZ_KeyEvent(mapping[i], 0, NO); |
| 3036 | 393 |
} else if (newMask && currentMask != newMask) { /* modifier down event */
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
394 |
QZ_KeyEvent(mapping[i], 0, YES); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
395 |
/* If this was Caps Lock, we need some additional voodoo to make SDL happy (is this needed in ottd?) */ |
| 3036 | 396 |
if (bit == NSAlphaShiftKeyMask) QZ_KeyEvent(mapping[i], 0, NO); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
397 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
398 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
399 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
400 |
_cocoa_video_data.current_mods = newMods; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
401 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
402 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
403 |
static void QZ_MouseMovedEvent(int x, int y) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
404 |
{
|
| 3036 | 405 |
if (_cursor.fix_at) {
|
406 |
int dx = x - _cursor.pos.x; |
|
407 |
int dy = y - _cursor.pos.y; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
408 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
409 |
if (dx != 0 || dy != 0) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
410 |
_cursor.delta.x += dx; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
411 |
_cursor.delta.y += dy; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
412 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
413 |
QZ_WarpCursor(_cursor.pos.x, _cursor.pos.y); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
414 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
415 |
} else {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
416 |
_cursor.delta.x = x - _cursor.pos.x; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
417 |
_cursor.delta.y = y - _cursor.pos.y; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
418 |
_cursor.pos.x = x; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
419 |
_cursor.pos.y = y; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
420 |
_cursor.dirty = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
421 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
422 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
423 |
|
| 3036 | 424 |
void QZ_MouseButtonEvent(int button, BOOL down) |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
425 |
{
|
| 3036 | 426 |
switch (button) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
427 |
case 0: |
| 3036 | 428 |
if (down) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
429 |
_left_button_down = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
430 |
} else {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
431 |
_left_button_down = false; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
432 |
_left_button_clicked = false; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
433 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
434 |
break; |
| 3036 | 435 |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
436 |
case 1: |
| 3036 | 437 |
if (down) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
438 |
_right_button_down = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
439 |
_right_button_clicked = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
440 |
} else {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
441 |
_right_button_down = false; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
442 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
443 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
444 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
445 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
446 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
447 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
448 |
static inline NSPoint QZ_GetMouseLocation(NSEvent *event) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
449 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
450 |
NSPoint pt; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
451 |
|
| 3036 | 452 |
if (_cocoa_video_data.fullscreen) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
453 |
pt = [ NSEvent mouseLocation ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
454 |
pt.y = _cocoa_video_data.height - pt.y; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
455 |
} else {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
456 |
pt = [event locationInWindow]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
457 |
pt = [_cocoa_video_data.qdview convertPoint:pt fromView:nil]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
458 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
459 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
460 |
return pt; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
461 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
462 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
463 |
static bool QZ_MouseIsInsideView(NSPoint *pt) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
464 |
{
|
| 3036 | 465 |
if (_cocoa_video_data.fullscreen) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
466 |
return pt->x >= 0 && pt->y >= 0 && pt->x < _cocoa_video_data.width && pt->y < _cocoa_video_data.height; |
| 3036 | 467 |
} else {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
468 |
return [ _cocoa_video_data.qdview mouse:*pt inRect:[ _cocoa_video_data.qdview bounds ] ]; |
| 3036 | 469 |
} |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
470 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
471 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
472 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
473 |
static bool QZ_PollEvent(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
474 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
475 |
NSEvent *event; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
476 |
NSPoint pt; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
477 |
NSString *chars; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
478 |
#ifdef _DEBUG |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
479 |
uint32 et0, et; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
480 |
#endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
481 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
482 |
#ifdef _DEBUG |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
483 |
et0 = GetTick(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
484 |
#endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
485 |
event = [ NSApp nextEventMatchingMask:NSAnyEventMask |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
486 |
untilDate: [ NSDate distantPast ] |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
487 |
inMode: NSDefaultRunLoopMode dequeue:YES ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
488 |
#ifdef _DEBUG |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
489 |
et = GetTick(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
490 |
_cocoa_video_data.tEvent+= et - et0; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
491 |
#endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
492 |
|
| 3036 | 493 |
if (event == nil) return false; |
494 |
if (!_cocoa_video_data.active) {
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
495 |
QZ_ShowMouse(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
496 |
[NSApp sendEvent:event]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
497 |
return true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
498 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
499 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
500 |
QZ_DoUnsidedModifiers( [ event modifierFlags ] ); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
501 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
502 |
switch ([event type]) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
503 |
case NSMouseMoved: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
504 |
case NSOtherMouseDragged: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
505 |
case NSRightMouseDragged: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
506 |
case NSLeftMouseDragged: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
507 |
pt = QZ_GetMouseLocation(event); |
| 3036 | 508 |
if (!QZ_MouseIsInsideView(&pt) && |
509 |
!_cocoa_video_data.emulating_right_button) {
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
510 |
QZ_ShowMouse(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
511 |
[NSApp sendEvent:event]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
512 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
513 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
514 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
515 |
QZ_HideMouse(); |
| 3036 | 516 |
QZ_MouseMovedEvent((int)pt.x, (int)pt.y); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
517 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
518 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
519 |
case NSLeftMouseDown: |
| 3036 | 520 |
if (!([ event modifierFlags ] & NSCommandKeyMask) || |
521 |
!QZ_MouseIsInsideView(&pt)) {
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
522 |
[NSApp sendEvent:event]; |
| 3036 | 523 |
} |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
524 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
525 |
pt = QZ_GetMouseLocation(event); |
| 3036 | 526 |
if (!QZ_MouseIsInsideView(&pt)) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
527 |
QZ_ShowMouse(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
528 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
529 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
530 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
531 |
QZ_HideMouse(); |
| 3036 | 532 |
QZ_MouseMovedEvent((int)pt.x, (int)pt.y); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
533 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
534 |
/* Right mouse button emulation */ |
| 3036 | 535 |
if ([ event modifierFlags ] & NSCommandKeyMask) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
536 |
_cocoa_video_data.emulating_right_button = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
537 |
QZ_MouseButtonEvent(1, YES); |
| 3036 | 538 |
} else {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
539 |
QZ_MouseButtonEvent(0, YES); |
| 3036 | 540 |
} |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
541 |
break; |
| 3036 | 542 |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
543 |
case NSLeftMouseUp: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
544 |
[NSApp sendEvent:event]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
545 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
546 |
pt = QZ_GetMouseLocation(event); |
| 3036 | 547 |
if (!QZ_MouseIsInsideView(&pt)) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
548 |
QZ_ShowMouse(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
549 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
550 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
551 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
552 |
QZ_HideMouse(); |
| 3036 | 553 |
QZ_MouseMovedEvent((int)pt.x, (int)pt.y); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
554 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
555 |
/* Right mouse button emulation */ |
| 3036 | 556 |
if (_cocoa_video_data.emulating_right_button) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
557 |
_cocoa_video_data.emulating_right_button = false; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
558 |
QZ_MouseButtonEvent(1, NO); |
| 3036 | 559 |
} else {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
560 |
QZ_MouseButtonEvent(0, NO); |
| 3036 | 561 |
} |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
562 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
563 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
564 |
case NSRightMouseDown: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
565 |
pt = QZ_GetMouseLocation(event); |
| 3036 | 566 |
if (!QZ_MouseIsInsideView(&pt)) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
567 |
QZ_ShowMouse(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
568 |
[NSApp sendEvent:event]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
569 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
570 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
571 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
572 |
QZ_HideMouse(); |
| 3036 | 573 |
QZ_MouseMovedEvent((int)pt.x, (int)pt.y); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
574 |
QZ_MouseButtonEvent(1, YES); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
575 |
break; |
| 3036 | 576 |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
577 |
case NSRightMouseUp: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
578 |
pt = QZ_GetMouseLocation(event); |
| 3036 | 579 |
if (!QZ_MouseIsInsideView(&pt)) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
580 |
QZ_ShowMouse(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
581 |
[NSApp sendEvent:event]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
582 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
583 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
584 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
585 |
QZ_HideMouse(); |
| 3036 | 586 |
QZ_MouseMovedEvent((int)pt.x, (int)pt.y); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
587 |
QZ_MouseButtonEvent(1, NO); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
588 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
589 |
|
| 3036 | 590 |
#if 0 |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
591 |
/* This is not needed since openttd currently only use two buttons */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
592 |
case NSOtherMouseDown: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
593 |
pt = QZ_GetMouseLocation(event); |
| 3036 | 594 |
if (!QZ_MouseIsInsideView(&pt)) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
595 |
QZ_ShowMouse(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
596 |
[NSApp sendEvent:event]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
597 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
598 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
599 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
600 |
QZ_HideMouse(); |
| 3036 | 601 |
QZ_MouseMovedEvent((int)pt.x, (int)pt.y); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
602 |
QZ_MouseButtonEvent([ event buttonNumber ], YES); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
603 |
break; |
| 3036 | 604 |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
605 |
case NSOtherMouseUp: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
606 |
pt = QZ_GetMouseLocation(event); |
| 3036 | 607 |
if (!QZ_MouseIsInsideView(&pt)) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
608 |
QZ_ShowMouse(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
609 |
[NSApp sendEvent:event]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
610 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
611 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
612 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
613 |
QZ_HideMouse(); |
| 3036 | 614 |
QZ_MouseMovedEvent((int)pt.x, (int)pt.y); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
615 |
QZ_MouseButtonEvent([ event buttonNumber ], NO); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
616 |
break; |
| 3036 | 617 |
#endif |
618 |
||
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
619 |
case NSKeyDown: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
620 |
/* Quit, hide and minimize */ |
| 3036 | 621 |
switch ([event keyCode]) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
622 |
case QZ_q: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
623 |
case QZ_h: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
624 |
case QZ_m: |
| 3036 | 625 |
if ([ event modifierFlags ] & NSCommandKeyMask) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
626 |
[NSApp sendEvent:event]; |
| 3036 | 627 |
} |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
628 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
629 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
630 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
631 |
chars = [ event characters ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
632 |
QZ_KeyEvent([event keyCode], [ chars length ] ? [ chars characterAtIndex:0 ] : 0, YES); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
633 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
634 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
635 |
case NSKeyUp: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
636 |
/* Quit, hide and minimize */ |
| 3036 | 637 |
switch ([event keyCode]) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
638 |
case QZ_q: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
639 |
case QZ_h: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
640 |
case QZ_m: |
| 3036 | 641 |
if ([ event modifierFlags ] & NSCommandKeyMask) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
642 |
[NSApp sendEvent:event]; |
| 3036 | 643 |
} |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
644 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
645 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
646 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
647 |
chars = [ event characters ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
648 |
QZ_KeyEvent([event keyCode], [ chars length ] ? [ chars characterAtIndex:0 ] : 0, NO); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
649 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
650 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
651 |
case NSScrollWheel: |
| 3036 | 652 |
if ([ event deltaX ] > 0.0 || [ event deltaY ] > 0.0) { /* Scroll up */
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
653 |
_cursor.wheel--; |
| 3036 | 654 |
} else { /* Scroll down */
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
655 |
_cursor.wheel++; |
| 3036 | 656 |
} |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
657 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
658 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
659 |
default: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
660 |
[NSApp sendEvent:event]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
661 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
662 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
663 |
return true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
664 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
665 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
666 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
667 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
668 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
669 |
static void QZ_GameLoop(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
670 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
671 |
uint32 next_tick = GetTick() + 30; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
672 |
uint32 cur_ticks; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
673 |
uint32 pal_tick = 0; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
674 |
#ifdef _DEBUG |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
675 |
uint32 et0, et, st0, st; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
676 |
#endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
677 |
int i; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
678 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
679 |
DEBUG(driver, 1)("cocoa_v: QZ_GameLoop");
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
680 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
681 |
#ifdef _DEBUG |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
682 |
et0 = GetTick(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
683 |
st = 0; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
684 |
#endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
685 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
686 |
_screen.dst_ptr = _cocoa_video_data.pixels; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
687 |
DisplaySplashImage(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
688 |
QZ_CheckPaletteAnim(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
689 |
QZ_Draw(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
690 |
CSleep(1); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
691 |
|
| 3036 | 692 |
for (i = 0; i < 2; i++) GameLoop(); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
693 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
694 |
_screen.dst_ptr = _cocoa_video_data.pixels; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
695 |
UpdateWindows(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
696 |
QZ_CheckPaletteAnim(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
697 |
QZ_Draw(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
698 |
CSleep(1); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
699 |
|
| 3036 | 700 |
for (;;) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
701 |
InteractiveRandom(); // randomness |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
702 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
703 |
while (QZ_PollEvent()) {}
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
704 |
|
| 3036 | 705 |
if (_exit_game) break; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
706 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
707 |
#if defined(_DEBUG) |
| 3036 | 708 |
if (_cocoa_video_data.current_mods & NSShiftKeyMask) |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
709 |
#else |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
710 |
if (_cocoa_video_data.tab_is_down) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
711 |
#endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
712 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
713 |
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
714 |
} else if (_fast_forward & 2) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
715 |
_fast_forward = 0; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
716 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
717 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
718 |
cur_ticks = GetTick(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
719 |
if ((_fast_forward && !_pause) || cur_ticks > next_tick) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
720 |
next_tick = cur_ticks; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
721 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
722 |
if (cur_ticks == next_tick) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
723 |
next_tick += 30; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
724 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
725 |
_ctrl_pressed = !!(_cocoa_video_data.current_mods & NSControlKeyMask); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
726 |
_shift_pressed = !!(_cocoa_video_data.current_mods & NSShiftKeyMask); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
727 |
#ifdef _DEBUG |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
728 |
_dbg_screen_rect = !!(_cocoa_video_data.current_mods & NSAlphaShiftKeyMask); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
729 |
#endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
730 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
731 |
GameLoop(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
732 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
733 |
_screen.dst_ptr = _cocoa_video_data.pixels; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
734 |
UpdateWindows(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
735 |
if (++pal_tick > 4) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
736 |
QZ_CheckPaletteAnim(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
737 |
pal_tick = 1; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
738 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
739 |
QZ_Draw(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
740 |
} else {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
741 |
#ifdef _DEBUG |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
742 |
st0 = GetTick(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
743 |
#endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
744 |
CSleep(1); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
745 |
#ifdef _DEBUG |
| 3036 | 746 |
st += GetTick() - st0; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
747 |
#endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
748 |
_screen.dst_ptr = _cocoa_video_data.pixels; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
749 |
DrawTextMessage(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
750 |
DrawMouseCursor(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
751 |
QZ_Draw(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
752 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
753 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
754 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
755 |
#ifdef _DEBUG |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
756 |
et = GetTick(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
757 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
758 |
DEBUG(driver, 1)("cocoa_v: nextEventMatchingMask took %i ms total", _cocoa_video_data.tEvent);
|
| 3036 | 759 |
DEBUG(driver, 1)("cocoa_v: game loop took %i ms total (%i ms without sleep)", et - et0, et - et0 - st);
|
760 |
DEBUG(driver, 1)("cocoa_v: (nextEventMatchingMask total)/(game loop total) is %f%%", (double)_cocoa_video_data.tEvent / (double)(et - et0) * 100);
|
|
761 |
DEBUG(driver, 1)("cocoa_v: (nextEventMatchingMask total)/(game loop without sleep total) is %f%%", (double)_cocoa_video_data.tEvent / (double)(et - et0 - st) * 100);
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
762 |
#endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
763 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
764 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
765 |
|
| 3036 | 766 |
/****************************************************************************** |
767 |
* Windowed mode * |
|
768 |
******************************************************************************/ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
769 |
|
| 3036 | 770 |
/* This function makes the *game region* of the window 100% opaque. |
771 |
* The genie effect uses the alpha component. Otherwise, |
|
772 |
* it doesn't seem to matter what value it has. |
|
773 |
*/ |
|
774 |
static void QZ_SetPortAlphaOpaque(void) |
|
775 |
{
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
776 |
if (_cocoa_video_data.device_bpp == 32) {
|
| 3036 | 777 |
uint32* pixels = (uint32*)_cocoa_video_data.realpixels; |
778 |
uint32 rowPixels = _cocoa_video_data.pitch / 4; |
|
779 |
uint32 i; |
|
780 |
uint32 j; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
781 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
782 |
for (i = 0; i < _cocoa_video_data.height; i++) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
783 |
for (j = 0; j < _cocoa_video_data.width; j++) {
|
| 3036 | 784 |
pixels[i * rowPixels + j] |= 0xFF000000; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
785 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
786 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
787 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
788 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
789 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
790 |
@implementation OTTD_QuartzWindow |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
791 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
792 |
/* we override these methods to fix the miniaturize animation/dock icon bug */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
793 |
- (void)miniaturize:(id)sender |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
794 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
795 |
/* make the alpha channel opaque so anim won't have holes in it */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
796 |
QZ_SetPortAlphaOpaque (); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
797 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
798 |
/* window is hidden now */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
799 |
_cocoa_video_data.active = false; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
800 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
801 |
QZ_ShowMouse(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
802 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
803 |
[ super miniaturize:sender ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
804 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
805 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
806 |
- (void)display |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
807 |
{
|
| 3036 | 808 |
/* This method fires just before the window deminaturizes from the Dock. |
809 |
* We'll save the current visible surface, let the window manager redraw any |
|
810 |
* UI elements, and restore the surface. This way, no expose event |
|
811 |
* is required, and the deminiaturize works perfectly. |
|
812 |
*/ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
813 |
|
| 3036 | 814 |
QZ_SetPortAlphaOpaque(); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
815 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
816 |
/* save current visible surface */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
817 |
[ self cacheImageInRect:[ _cocoa_video_data.qdview frame ] ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
818 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
819 |
/* let the window manager redraw controls, border, etc */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
820 |
[ super display ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
821 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
822 |
/* restore visible surface */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
823 |
[ self restoreCachedImage ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
824 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
825 |
/* window is visible again */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
826 |
_cocoa_video_data.active = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
827 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
828 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
829 |
- (void)setFrame:(NSRect)frameRect display:(BOOL)flag |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
830 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
831 |
NSRect newViewFrame; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
832 |
CGrafPtr thePort; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
833 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
834 |
[ super setFrame:frameRect display:flag ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
835 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
836 |
/* Don't do anything if the window is currently beign created */ |
| 3036 | 837 |
if (_cocoa_video_data.issetting) return; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
838 |
|
| 3036 | 839 |
if (_cocoa_video_data.window == nil) return; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
840 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
841 |
newViewFrame = [ _cocoa_video_data.qdview frame ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
842 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
843 |
/* Update the pixels and pitch */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
844 |
thePort = [ _cocoa_video_data.qdview qdPort ]; |
| 3036 | 845 |
LockPortBits(thePort); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
846 |
|
| 3036 | 847 |
_cocoa_video_data.realpixels = GetPixBaseAddr(GetPortPixMap(thePort)); |
848 |
_cocoa_video_data.pitch = GetPixRowBytes(GetPortPixMap(thePort)); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
849 |
|
|
3129
79dc90ebf03a
(svn r3742) -codechange: [OSX] changed an assert to use the new error window and added another two to show if the screen buffer fails for some reason in cocoa driver (instead of just crashing)
bjarni
parents:
3128
diff
changeset
|
850 |
if (_cocoa_video_data.realpixels == NULL) {
|
|
79dc90ebf03a
(svn r3742) -codechange: [OSX] changed an assert to use the new error window and added another two to show if the screen buffer fails for some reason in cocoa driver (instead of just crashing)
bjarni
parents:
3128
diff
changeset
|
851 |
ShowMacErrorDialog("Error: failure to locate screen buffer in the OS");
|
|
79dc90ebf03a
(svn r3742) -codechange: [OSX] changed an assert to use the new error window and added another two to show if the screen buffer fails for some reason in cocoa driver (instead of just crashing)
bjarni
parents:
3128
diff
changeset
|
852 |
} |
|
79dc90ebf03a
(svn r3742) -codechange: [OSX] changed an assert to use the new error window and added another two to show if the screen buffer fails for some reason in cocoa driver (instead of just crashing)
bjarni
parents:
3128
diff
changeset
|
853 |
|
| 3036 | 854 |
/* _cocoa_video_data.realpixels now points to the window's pixels |
855 |
* We want it to point to the *view's* pixels |
|
856 |
*/ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
857 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
858 |
int vOffset = [ _cocoa_video_data.window frame ].size.height - newViewFrame.size.height - newViewFrame.origin.y; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
859 |
int hOffset = newViewFrame.origin.x; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
860 |
|
| 3036 | 861 |
_cocoa_video_data.realpixels = (uint8*)_cocoa_video_data.realpixels + (vOffset * _cocoa_video_data.pitch) + hOffset * (_cocoa_video_data.device_bpp / 8); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
862 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
863 |
|
| 3036 | 864 |
UnlockPortBits(thePort); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
865 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
866 |
/* Allocate new buffer */ |
| 3036 | 867 |
free(_cocoa_video_data.pixels); |
868 |
_cocoa_video_data.pixels = (uint8*)malloc(newViewFrame.size.width * newViewFrame.size.height); |
|
|
3129
79dc90ebf03a
(svn r3742) -codechange: [OSX] changed an assert to use the new error window and added another two to show if the screen buffer fails for some reason in cocoa driver (instead of just crashing)
bjarni
parents:
3128
diff
changeset
|
869 |
if (_cocoa_video_data.pixels == NULL) {
|
|
79dc90ebf03a
(svn r3742) -codechange: [OSX] changed an assert to use the new error window and added another two to show if the screen buffer fails for some reason in cocoa driver (instead of just crashing)
bjarni
parents:
3128
diff
changeset
|
870 |
ShowMacErrorDialog("Error: failed to allocate frame buffer");
|
|
79dc90ebf03a
(svn r3742) -codechange: [OSX] changed an assert to use the new error window and added another two to show if the screen buffer fails for some reason in cocoa driver (instead of just crashing)
bjarni
parents:
3128
diff
changeset
|
871 |
} |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
872 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
873 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
874 |
/* Tell the game that the resolution changed */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
875 |
_cocoa_video_data.width = newViewFrame.size.width; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
876 |
_cocoa_video_data.height = newViewFrame.size.height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
877 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
878 |
_screen.width = _cocoa_video_data.width; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
879 |
_screen.height = _cocoa_video_data.height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
880 |
_screen.pitch = _cocoa_video_data.width; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
881 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
882 |
GameSizeChanged(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
883 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
884 |
/* Redraw screen */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
885 |
_cocoa_video_data.num_dirty_rects = MAX_DIRTY_RECTS; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
886 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
887 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
888 |
- (void)appDidHide:(NSNotification*)note |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
889 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
890 |
_cocoa_video_data.active = false; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
891 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
892 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
893 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
894 |
- (void)appWillUnhide:(NSNotification*)note |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
895 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
896 |
QZ_SetPortAlphaOpaque (); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
897 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
898 |
/* save current visible surface */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
899 |
[ self cacheImageInRect:[ _cocoa_video_data.qdview frame ] ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
900 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
901 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
902 |
- (void)appDidUnhide:(NSNotification*)note |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
903 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
904 |
/* restore cached image, since it may not be current, post expose event too */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
905 |
[ self restoreCachedImage ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
906 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
907 |
_cocoa_video_data.active = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
908 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
909 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
910 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
911 |
- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
912 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
913 |
/* Make our window subclass receive these application notifications */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
914 |
[ [ NSNotificationCenter defaultCenter ] addObserver:self |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
915 |
selector:@selector(appDidHide:) name:NSApplicationDidHideNotification object:NSApp ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
916 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
917 |
[ [ NSNotificationCenter defaultCenter ] addObserver:self |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
918 |
selector:@selector(appDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
919 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
920 |
[ [ NSNotificationCenter defaultCenter ] addObserver:self |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
921 |
selector:@selector(appWillUnhide:) name:NSApplicationWillUnhideNotification object:NSApp ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
922 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
923 |
return [ super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
924 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
925 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
926 |
@end |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
927 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
928 |
@implementation OTTD_QuartzWindowDelegate |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
929 |
- (BOOL)windowShouldClose:(id)sender |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
930 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
931 |
QZ_AskQuit(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
932 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
933 |
return NO; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
934 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
935 |
|
| 3036 | 936 |
- (void)windowDidBecomeKey:(NSNotification*)aNotification |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
937 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
938 |
_cocoa_video_data.active = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
939 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
940 |
|
| 3036 | 941 |
- (void)windowDidResignKey:(NSNotification*)aNotification |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
942 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
943 |
_cocoa_video_data.active = false; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
944 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
945 |
|
| 3036 | 946 |
- (void)windowDidBecomeMain:(NSNotification*)aNotification |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
947 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
948 |
_cocoa_video_data.active = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
949 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
950 |
|
| 3036 | 951 |
- (void)windowDidResignMain:(NSNotification*)aNotification |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
952 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
953 |
_cocoa_video_data.active = false; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
954 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
955 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
956 |
@end |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
957 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
958 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
959 |
static void QZ_UpdateWindowPalette(uint start, uint count) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
960 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
961 |
uint i; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
962 |
|
| 3036 | 963 |
switch (_cocoa_video_data.device_bpp) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
964 |
case 32: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
965 |
for (i = start; i < start + count; i++) {
|
| 3036 | 966 |
uint32 clr32 = 0xff000000; |
967 |
clr32 |= (uint32)_cur_palette[i].r << 16; |
|
968 |
clr32 |= (uint32)_cur_palette[i].g << 8; |
|
969 |
clr32 |= (uint32)_cur_palette[i].b; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
970 |
_cocoa_video_data.palette32[i] = clr32; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
971 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
972 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
973 |
case 16: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
974 |
for (i = start; i < start + count; i++) {
|
| 3036 | 975 |
uint16 clr16 = 0x0000; |
976 |
clr16 |= (uint16)((_cur_palette[i].r >> 3) & 0x1f) << 10; |
|
977 |
clr16 |= (uint16)((_cur_palette[i].g >> 3) & 0x1f) << 5; |
|
978 |
clr16 |= (uint16)((_cur_palette[i].b >> 3) & 0x1f); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
979 |
_cocoa_video_data.palette16[i] = clr16; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
980 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
981 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
982 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
983 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
984 |
_cocoa_video_data.num_dirty_rects = MAX_DIRTY_RECTS; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
985 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
986 |
|
|
3038
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
987 |
static inline void QZ_WindowBlitIndexedPixelsToView32(uint left, uint top, uint right, uint bottom) |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
988 |
{
|
|
3038
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
989 |
const uint32* pal = _cocoa_video_data.palette32; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
990 |
const uint8* src = _cocoa_video_data.pixels; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
991 |
uint32* dst = (uint32*)_cocoa_video_data.realpixels; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
992 |
uint width = _cocoa_video_data.width; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
993 |
uint pitch = _cocoa_video_data.pitch / 4; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
994 |
uint x; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
995 |
uint y; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
996 |
|
| 3036 | 997 |
for (y = top; y < bottom; y++) {
|
|
3038
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
998 |
for (x = left; x < right; x++) {
|
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
999 |
dst[y * pitch + x] = pal[src[y * width + x]]; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1000 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1001 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1002 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1003 |
|
|
3038
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1004 |
static inline void QZ_WindowBlitIndexedPixelsToView16(uint left, uint top, uint right, uint bottom) |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1005 |
{
|
|
3038
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1006 |
const uint16* pal = _cocoa_video_data.palette16; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1007 |
const uint8* src = _cocoa_video_data.pixels; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1008 |
uint16* dst = (uint16*)_cocoa_video_data.realpixels; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1009 |
uint width = _cocoa_video_data.width; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1010 |
uint pitch = _cocoa_video_data.pitch / 2; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1011 |
uint x; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1012 |
uint y; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1013 |
|
| 3036 | 1014 |
for (y = top; y < bottom; y++) {
|
|
3038
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1015 |
for (x = left; x < right; x++) {
|
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1016 |
dst[y * pitch + x] = pal[src[y * width + x]]; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1017 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1018 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1019 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1020 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1021 |
static inline void QZ_WindowBlitIndexedPixelsToView(int left, int top, int right, int bottom) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1022 |
{
|
| 3036 | 1023 |
switch (_cocoa_video_data.device_bpp) {
|
1024 |
case 32: QZ_WindowBlitIndexedPixelsToView32(left, top, right, bottom); break; |
|
1025 |
case 16: QZ_WindowBlitIndexedPixelsToView16(left, top, right, bottom); break; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1026 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1027 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1028 |
|
| 3036 | 1029 |
static bool _resize_icon[] = {
|
1030 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, |
|
1031 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, |
|
1032 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, |
|
1033 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, |
|
1034 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, |
|
1035 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, |
|
1036 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, |
|
1037 |
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, |
|
1038 |
0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, |
|
1039 |
0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, |
|
1040 |
0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, |
|
1041 |
0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, |
|
1042 |
0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, |
|
1043 |
0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, |
|
1044 |
0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, |
|
1045 |
1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0 |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1046 |
}; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1047 |
|
| 3036 | 1048 |
static void QZ_DrawResizeIcon(void) |
1049 |
{
|
|
1050 |
int xoff = _cocoa_video_data.width - 16; |
|
1051 |
int yoff = _cocoa_video_data.height - 16; |
|
1052 |
int x; |
|
1053 |
int y; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1054 |
|
| 3036 | 1055 |
for (y = 0; y < 16; y++) {
|
1056 |
uint16* trg16 = (uint16*)_cocoa_video_data.realpixels + (yoff + y) * _cocoa_video_data.pitch / 2 + xoff; |
|
1057 |
uint32* trg32 = (uint32*)_cocoa_video_data.realpixels + (yoff + y) * _cocoa_video_data.pitch / 4 + xoff; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1058 |
|
| 3036 | 1059 |
for (x = 0; x < 16; x++, trg16++, trg32++) {
|
1060 |
if (!_resize_icon[y * 16 + x]) continue; |
|
1061 |
||
1062 |
switch (_cocoa_video_data.device_bpp) {
|
|
1063 |
case 32: *trg32 = 0xff000000; break; |
|
1064 |
case 16: *trg16 = 0x0000; break; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1065 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1066 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1067 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1068 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1069 |
|
| 3036 | 1070 |
static void QZ_DrawWindow(void) |
1071 |
{
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1072 |
int i; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1073 |
RgnHandle dirty, temp; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1074 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1075 |
/* Check if we need to do anything */ |
| 3036 | 1076 |
if (_cocoa_video_data.num_dirty_rects == 0 || |
1077 |
[ _cocoa_video_data.window isMiniaturized ]) {
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1078 |
return; |
| 3036 | 1079 |
} |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1080 |
|
| 3036 | 1081 |
if (_cocoa_video_data.num_dirty_rects >= MAX_DIRTY_RECTS) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1082 |
_cocoa_video_data.num_dirty_rects = 1; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1083 |
_cocoa_video_data.dirty_rects[0].left = 0; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1084 |
_cocoa_video_data.dirty_rects[0].top = 0; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1085 |
_cocoa_video_data.dirty_rects[0].right = _cocoa_video_data.width; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1086 |
_cocoa_video_data.dirty_rects[0].bottom = _cocoa_video_data.height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1087 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1088 |
|
| 3036 | 1089 |
dirty = NewRgn(); |
1090 |
temp = NewRgn(); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1091 |
|
| 3036 | 1092 |
SetEmptyRgn(dirty); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1093 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1094 |
/* Build the region of dirty rectangles */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1095 |
for (i = 0; i < _cocoa_video_data.num_dirty_rects; i++) {
|
| 3036 | 1096 |
QZ_WindowBlitIndexedPixelsToView( |
1097 |
_cocoa_video_data.dirty_rects[i].left, |
|
1098 |
_cocoa_video_data.dirty_rects[i].top, |
|
1099 |
_cocoa_video_data.dirty_rects[i].right, |
|
1100 |
_cocoa_video_data.dirty_rects[i].bottom |
|
1101 |
); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1102 |
|
| 3036 | 1103 |
MacSetRectRgn( |
1104 |
temp, |
|
1105 |
_cocoa_video_data.dirty_rects[i].left, |
|
1106 |
_cocoa_video_data.dirty_rects[i].top, |
|
1107 |
_cocoa_video_data.dirty_rects[i].right, |
|
1108 |
_cocoa_video_data.dirty_rects[i].bottom |
|
1109 |
); |
|
1110 |
MacUnionRgn(dirty, temp, dirty); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1111 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1112 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1113 |
QZ_DrawResizeIcon(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1114 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1115 |
/* Flush the dirty region */ |
| 3036 | 1116 |
QDFlushPortBuffer([ _cocoa_video_data.qdview qdPort ], dirty); |
1117 |
DisposeRgn(dirty); |
|
1118 |
DisposeRgn(temp); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1119 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1120 |
_cocoa_video_data.num_dirty_rects = 0; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1121 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1122 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1123 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1124 |
extern const char _openttd_revision[]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1125 |
|
| 3036 | 1126 |
static const char* QZ_SetVideoWindowed(uint width, uint height) |
1127 |
{
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1128 |
char caption[50]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1129 |
NSString *nsscaption; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1130 |
unsigned int style; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1131 |
NSRect contentRect; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1132 |
BOOL isCustom = NO; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1133 |
|
| 3036 | 1134 |
if (width > _cocoa_video_data.device_width) |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1135 |
width = _cocoa_video_data.device_width; |
| 3036 | 1136 |
if (height > _cocoa_video_data.device_height) |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1137 |
height = _cocoa_video_data.device_height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1138 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1139 |
_cocoa_video_data.width = width; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1140 |
_cocoa_video_data.height = height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1141 |
|
| 3036 | 1142 |
contentRect = NSMakeRect(0, 0, width, height); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1143 |
|
| 3036 | 1144 |
/* Check if we should completely destroy the previous mode |
1145 |
* - If it is fullscreen |
|
1146 |
*/ |
|
1147 |
if (_cocoa_video_data.isset && _cocoa_video_data.fullscreen) |
|
1148 |
QZ_UnsetVideoMode(); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1149 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1150 |
/* Check if we should recreate the window */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1151 |
if (_cocoa_video_data.window == nil) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1152 |
/* Set the window style */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1153 |
style = NSTitledWindowMask; |
| 3036 | 1154 |
style |= (NSMiniaturizableWindowMask | NSClosableWindowMask); |
1155 |
style |= NSResizableWindowMask; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1156 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1157 |
/* Manually create a window, avoids having a nib file resource */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1158 |
_cocoa_video_data.window = [ [ OTTD_QuartzWindow alloc ] |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1159 |
initWithContentRect:contentRect |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1160 |
styleMask:style |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1161 |
backing:NSBackingStoreBuffered |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1162 |
defer:NO ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1163 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1164 |
if (_cocoa_video_data.window == nil) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1165 |
return "Could not create the Cocoa window"; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1166 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1167 |
snprintf(caption, sizeof(caption), "OpenTTD %s", _openttd_revision); |
|
2741
65d4de069014
(svn r3286) -Fix: [OSX] 10.2 works again and universal binaries got 10.2 as target by default
bjarni
parents:
2736
diff
changeset
|
1168 |
nsscaption = [ [ NSString alloc ] initWithCString:caption ]; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1169 |
[ _cocoa_video_data.window setTitle:nsscaption ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1170 |
[ _cocoa_video_data.window setMiniwindowTitle:nsscaption ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1171 |
[ nsscaption release ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1172 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1173 |
[ _cocoa_video_data.window setAcceptsMouseMovedEvents:YES ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1174 |
[ _cocoa_video_data.window setViewsNeedDisplay:NO ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1175 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1176 |
[ _cocoa_video_data.window setDelegate: [ [ [ OTTD_QuartzWindowDelegate alloc ] init ] autorelease ] ]; |
| 3036 | 1177 |
} else {
|
1178 |
/* We already have a window, just change its size */ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1179 |
if (!isCustom) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1180 |
[ _cocoa_video_data.window setContentSize:contentRect.size ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1181 |
[ _cocoa_video_data.qdview setFrameSize:contentRect.size ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1182 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1183 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1184 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1185 |
[ _cocoa_video_data.window center ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1186 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1187 |
/* Only recreate the view if it doesn't already exist */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1188 |
if (_cocoa_video_data.qdview == nil) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1189 |
_cocoa_video_data.qdview = [ [ NSQuickDrawView alloc ] initWithFrame:contentRect ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1190 |
[ _cocoa_video_data.qdview setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1191 |
[ [ _cocoa_video_data.window contentView ] addSubview:_cocoa_video_data.qdview ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1192 |
[ _cocoa_video_data.qdview release ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1193 |
[ _cocoa_video_data.window makeKeyAndOrderFront:nil ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1194 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1195 |
|
| 3036 | 1196 |
LockPortBits([ _cocoa_video_data.qdview qdPort ]); |
1197 |
_cocoa_video_data.realpixels = GetPixBaseAddr(GetPortPixMap([ _cocoa_video_data.qdview qdPort ])); |
|
1198 |
_cocoa_video_data.pitch = GetPixRowBytes(GetPortPixMap([ _cocoa_video_data.qdview qdPort ])); |
|
1199 |
UnlockPortBits([ _cocoa_video_data.qdview qdPort ]); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1200 |
|
| 3036 | 1201 |
/* _cocoa_video_data.realpixels now points to the window's pixels |
1202 |
* We want it to point to the *view's* pixels |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1203 |
*/ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1204 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1205 |
int vOffset = [ _cocoa_video_data.window frame ].size.height - [ _cocoa_video_data.qdview frame ].size.height - [ _cocoa_video_data.qdview frame ].origin.y; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1206 |
int hOffset = [ _cocoa_video_data.qdview frame ].origin.x; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1207 |
|
| 3036 | 1208 |
_cocoa_video_data.realpixels = (uint8*)_cocoa_video_data.realpixels + (vOffset * _cocoa_video_data.pitch) + hOffset * (_cocoa_video_data.device_bpp / 8); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1209 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1210 |
|
| 3036 | 1211 |
free(_cocoa_video_data.pixels); |
1212 |
_cocoa_video_data.pixels = (uint8*)malloc(width * height); |
|
1213 |
if (_cocoa_video_data.pixels == NULL) return "Failed to allocate 8-bit buffer"; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1214 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1215 |
_cocoa_video_data.fullscreen = false; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1216 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1217 |
return NULL; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1218 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1219 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1220 |
|
| 3036 | 1221 |
/****************************************************************************** |
1222 |
* Fullscreen mode * |
|
1223 |
******************************************************************************/ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1224 |
|
| 3036 | 1225 |
/* Gamma functions to try to hide the flash from a rez switch |
1226 |
* Fade the display from normal to black |
|
1227 |
* Save gamma tables for fade back to normal |
|
1228 |
*/ |
|
| 3037 | 1229 |
static uint32 QZ_FadeGammaOut(OTTD_QuartzGammaTable* table) |
| 3036 | 1230 |
{
|
1231 |
CGGammaValue redTable[QZ_GAMMA_TABLE_SIZE]; |
|
1232 |
CGGammaValue greenTable[QZ_GAMMA_TABLE_SIZE]; |
|
1233 |
CGGammaValue blueTable[QZ_GAMMA_TABLE_SIZE]; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1234 |
float percent; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1235 |
int j; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1236 |
unsigned int actual; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1237 |
|
| 3036 | 1238 |
if (CGGetDisplayTransferByTable( |
1239 |
_cocoa_video_data.display_id, QZ_GAMMA_TABLE_SIZE, |
|
1240 |
table->red, table->green, table->blue, &actual |
|
1241 |
) != CGDisplayNoErr || |
|
1242 |
actual != QZ_GAMMA_TABLE_SIZE) {
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1243 |
return 1; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1244 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1245 |
|
| 3036 | 1246 |
memcpy(redTable, table->red, sizeof(redTable)); |
1247 |
memcpy(greenTable, table->green, sizeof(greenTable)); |
|
1248 |
memcpy(blueTable, table->blue, sizeof(greenTable)); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1249 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1250 |
for (percent = 1.0; percent >= 0.0; percent -= 0.01) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1251 |
for (j = 0; j < QZ_GAMMA_TABLE_SIZE; j++) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1252 |
redTable[j] = redTable[j] * percent; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1253 |
greenTable[j] = greenTable[j] * percent; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1254 |
blueTable[j] = blueTable[j] * percent; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1255 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1256 |
|
| 3036 | 1257 |
if (CGSetDisplayTransferByTable( |
1258 |
_cocoa_video_data.display_id, QZ_GAMMA_TABLE_SIZE, |
|
1259 |
redTable, greenTable, blueTable |
|
1260 |
) != CGDisplayNoErr) {
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1261 |
CGDisplayRestoreColorSyncSettings(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1262 |
return 1; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1263 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1264 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1265 |
CSleep(10); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1266 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1267 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1268 |
return 0; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1269 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1270 |
|
| 3036 | 1271 |
/* Fade the display from black to normal |
1272 |
* Restore previously saved gamma values |
|
1273 |
*/ |
|
1274 |
static uint32 QZ_FadeGammaIn(const OTTD_QuartzGammaTable* table) |
|
1275 |
{
|
|
1276 |
CGGammaValue redTable[QZ_GAMMA_TABLE_SIZE]; |
|
1277 |
CGGammaValue greenTable[QZ_GAMMA_TABLE_SIZE]; |
|
1278 |
CGGammaValue blueTable[QZ_GAMMA_TABLE_SIZE]; |
|
1279 |
float percent; |
|
1280 |
int j; |
|
1281 |
||
1282 |
memset(redTable, 0, sizeof(redTable)); |
|
1283 |
memset(greenTable, 0, sizeof(greenTable)); |
|
1284 |
memset(blueTable, 0, sizeof(greenTable)); |
|
1285 |
||
1286 |
for (percent = 0.0; percent <= 1.0; percent += 0.01) {
|
|
1287 |
for (j = 0; j < QZ_GAMMA_TABLE_SIZE; j++) {
|
|
1288 |
redTable[j] = table->red[j] * percent; |
|
1289 |
greenTable[j] = table->green[j] * percent; |
|
1290 |
blueTable[j] = table->blue[j] * percent; |
|
1291 |
} |
|
1292 |
||
1293 |
if (CGSetDisplayTransferByTable( |
|
1294 |
_cocoa_video_data.display_id, QZ_GAMMA_TABLE_SIZE, |
|
1295 |
redTable, greenTable, blueTable |
|
1296 |
) != CGDisplayNoErr) {
|
|
1297 |
CGDisplayRestoreColorSyncSettings(); |
|
1298 |
return 1; |
|
1299 |
} |
|
1300 |
||
1301 |
CSleep(10); |
|
1302 |
} |
|
1303 |
||
1304 |
return 0; |
|
1305 |
} |
|
1306 |
||
1307 |
static const char* QZ_SetVideoFullScreen(int width, int height) |
|
1308 |
{
|
|
1309 |
const char* errstr = "QZ_SetVideoFullScreen error"; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1310 |
int exact_match; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1311 |
CFNumberRef number; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1312 |
int bpp; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1313 |
int gamma_error; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1314 |
OTTD_QuartzGammaTable gamma_table; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1315 |
NSRect screen_rect; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1316 |
CGError error; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1317 |
NSPoint pt; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1318 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1319 |
/* Destroy any previous mode */ |
| 3036 | 1320 |
if (_cocoa_video_data.isset) QZ_UnsetVideoMode(); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1321 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1322 |
/* See if requested mode exists */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1323 |
_cocoa_video_data.mode = CGDisplayBestModeForParameters(_cocoa_video_data.display_id, 8, width, height, &exact_match); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1324 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1325 |
/* If the mode wasn't an exact match, check if it has the right bpp, and update width and height */ |
| 3036 | 1326 |
if (!exact_match) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1327 |
number = CFDictionaryGetValue (_cocoa_video_data.mode, kCGDisplayBitsPerPixel); |
| 3036 | 1328 |
CFNumberGetValue(number, kCFNumberSInt32Type, &bpp); |
1329 |
if (bpp != 8) {
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1330 |
errstr = "Failed to find display resolution"; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1331 |
goto ERR_NO_MATCH; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1332 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1333 |
|
| 3036 | 1334 |
number = CFDictionaryGetValue(_cocoa_video_data.mode, kCGDisplayWidth); |
1335 |
CFNumberGetValue(number, kCFNumberSInt32Type, &width); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1336 |
|
| 3036 | 1337 |
number = CFDictionaryGetValue(_cocoa_video_data.mode, kCGDisplayHeight); |
1338 |
CFNumberGetValue(number, kCFNumberSInt32Type, &height); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1339 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1340 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1341 |
/* Fade display to zero gamma */ |
| 3036 | 1342 |
gamma_error = QZ_FadeGammaOut(&gamma_table); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1343 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1344 |
/* Put up the blanking window (a window above all other windows) */ |
| 3036 | 1345 |
error = CGDisplayCapture(_cocoa_video_data.display_id); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1346 |
|
| 3036 | 1347 |
if (CGDisplayNoErr != error) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1348 |
errstr = "Failed capturing display"; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1349 |
goto ERR_NO_CAPTURE; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1350 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1351 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1352 |
/* Do the physical switch */ |
| 3036 | 1353 |
if (CGDisplaySwitchToMode(_cocoa_video_data.display_id, _cocoa_video_data.mode) != CGDisplayNoErr) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1354 |
errstr = "Failed switching display resolution"; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1355 |
goto ERR_NO_SWITCH; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1356 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1357 |
|
| 3036 | 1358 |
_cocoa_video_data.realpixels = (uint8*)CGDisplayBaseAddress(_cocoa_video_data.display_id); |
1359 |
_cocoa_video_data.pitch = CGDisplayBytesPerRow(_cocoa_video_data.display_id); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1360 |
|
|
3129
79dc90ebf03a
(svn r3742) -codechange: [OSX] changed an assert to use the new error window and added another two to show if the screen buffer fails for some reason in cocoa driver (instead of just crashing)
bjarni
parents:
3128
diff
changeset
|
1361 |
if (_cocoa_video_data.realpixels == NULL ) {
|
|
79dc90ebf03a
(svn r3742) -codechange: [OSX] changed an assert to use the new error window and added another two to show if the screen buffer fails for some reason in cocoa driver (instead of just crashing)
bjarni
parents:
3128
diff
changeset
|
1362 |
ShowMacErrorDialog("Error: failure to locate screen buffer in the OS for full screen mode");
|
|
79dc90ebf03a
(svn r3742) -codechange: [OSX] changed an assert to use the new error window and added another two to show if the screen buffer fails for some reason in cocoa driver (instead of just crashing)
bjarni
parents:
3128
diff
changeset
|
1363 |
} |
|
79dc90ebf03a
(svn r3742) -codechange: [OSX] changed an assert to use the new error window and added another two to show if the screen buffer fails for some reason in cocoa driver (instead of just crashing)
bjarni
parents:
3128
diff
changeset
|
1364 |
|
| 3036 | 1365 |
_cocoa_video_data.width = CGDisplayPixelsWide(_cocoa_video_data.display_id); |
1366 |
_cocoa_video_data.height = CGDisplayPixelsHigh(_cocoa_video_data.display_id); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1367 |
_cocoa_video_data.fullscreen = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1368 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1369 |
/* Setup double-buffer emulation */ |
| 3036 | 1370 |
_cocoa_video_data.pixels = (uint8*)malloc(width * height); |
1371 |
if (_cocoa_video_data.pixels == NULL) {
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1372 |
errstr = "Failed to allocate memory for double buffering"; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1373 |
goto ERR_DOUBLEBUF; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1374 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1375 |
|
| 3036 | 1376 |
if (!CGDisplayCanSetPalette(_cocoa_video_data.display_id)) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1377 |
errstr = "Not an indexed display mode."; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1378 |
goto ERR_NOT_INDEXED; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1379 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1380 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1381 |
/* If we don't hide menu bar, it will get events and interrupt the program */ |
| 3036 | 1382 |
HideMenuBar(); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1383 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1384 |
/* Fade the display to original gamma */ |
| 3036 | 1385 |
if (!gamma_error) QZ_FadeGammaIn(&gamma_table); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1386 |
|
| 3036 | 1387 |
/* There is a bug in Cocoa where NSScreen doesn't synchronize |
1388 |
* with CGDirectDisplay, so the main screen's frame is wrong. |
|
1389 |
* As a result, coordinate translation produces incorrect results. |
|
1390 |
* We can hack around this bug by setting the screen rect ourselves. |
|
1391 |
* This hack should be removed if/when the bug is fixed. |
|
1392 |
*/ |
|
1393 |
screen_rect = NSMakeRect(0, 0, width, height); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1394 |
[ [ NSScreen mainScreen ] setFrame:screen_rect ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1395 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1396 |
/* we're fullscreen, so flag all input states... */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1397 |
_cocoa_video_data.active = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1398 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1399 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1400 |
pt = [ NSEvent mouseLocation ]; |
| 3036 | 1401 |
pt.y = CGDisplayPixelsHigh(_cocoa_video_data.display_id) - pt.y; |
1402 |
if (QZ_MouseIsInsideView(&pt)) QZ_HideMouse(); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1403 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1404 |
return NULL; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1405 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1406 |
/* Since the blanking window covers *all* windows (even force quit) correct recovery is crucial */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1407 |
ERR_NOT_INDEXED: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1408 |
free(_cocoa_video_data.pixels); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1409 |
_cocoa_video_data.pixels = NULL; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1410 |
ERR_DOUBLEBUF: |
| 3036 | 1411 |
CGDisplaySwitchToMode(_cocoa_video_data.display_id, _cocoa_video_data.save_mode); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1412 |
ERR_NO_SWITCH: |
| 3036 | 1413 |
CGReleaseAllDisplays(); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1414 |
ERR_NO_CAPTURE: |
| 3036 | 1415 |
if (!gamma_error) QZ_FadeGammaIn(&gamma_table); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1416 |
ERR_NO_MATCH: |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1417 |
return errstr; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1418 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1419 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1420 |
|
| 3036 | 1421 |
static void QZ_UpdateFullscreenPalette(uint first_color, uint num_colors) |
1422 |
{
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1423 |
CGTableCount index; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1424 |
CGDeviceColor color; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1425 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1426 |
for (index = first_color; index < first_color+num_colors; index++) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1427 |
/* Clamp colors between 0.0 and 1.0 */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1428 |
color.red = _cur_palette[index].r / 255.0; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1429 |
color.blue = _cur_palette[index].b / 255.0; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1430 |
color.green = _cur_palette[index].g / 255.0; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1431 |
|
| 3036 | 1432 |
CGPaletteSetColorAtIndex(_cocoa_video_data.palette, color, index); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1433 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1434 |
|
| 3036 | 1435 |
CGDisplaySetPalette(_cocoa_video_data.display_id, _cocoa_video_data.palette); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1436 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1437 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1438 |
/* Wait for the VBL to occur (estimated since we don't have a hardware interrupt) */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1439 |
static void QZ_WaitForVerticalBlank(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1440 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1441 |
/* The VBL delay is based on Ian Ollmann's RezLib <iano@cco.caltech.edu> */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1442 |
double refreshRate; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1443 |
double linesPerSecond; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1444 |
double target; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1445 |
double position; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1446 |
double adjustment; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1447 |
CFNumberRef refreshRateCFNumber; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1448 |
|
| 3036 | 1449 |
refreshRateCFNumber = CFDictionaryGetValue(_cocoa_video_data.mode, kCGDisplayRefreshRate); |
1450 |
if (refreshRateCFNumber == NULL) return; |
|
1451 |
||
1452 |
if (CFNumberGetValue(refreshRateCFNumber, kCFNumberDoubleType, &refreshRate) == 0) |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1453 |
return; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1454 |
|
| 3036 | 1455 |
if (refreshRate == 0) return; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1456 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1457 |
linesPerSecond = refreshRate * _cocoa_video_data.height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1458 |
target = _cocoa_video_data.height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1459 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1460 |
/* Figure out the first delay so we start off about right */ |
| 3036 | 1461 |
position = CGDisplayBeamPosition(_cocoa_video_data.display_id); |
1462 |
if (position > target) position = 0; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1463 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1464 |
adjustment = (target - position) / linesPerSecond; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1465 |
|
| 3036 | 1466 |
CSleep((uint32)(adjustment * 1000)); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1467 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1468 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1469 |
static void QZ_DrawScreen(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1470 |
{
|
|
3038
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1471 |
const uint8* src; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1472 |
uint8* dst; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1473 |
uint height; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1474 |
uint width; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1475 |
uint pitch; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1476 |
uint y; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1477 |
|
|
3038
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1478 |
src = _cocoa_video_data.pixels; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1479 |
dst = (uint8*)_cocoa_video_data.realpixels; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1480 |
width = _cocoa_video_data.width; |
|
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
1481 |
pitch = _cocoa_video_data.pitch; |
|
3081
3a46f595b16b
(svn r3670) -Codechange: [OSX] rewrote a part of the cocoa video driver to speed it up by 1000% in fullscreen
bjarni
parents:
3038
diff
changeset
|
1482 |
|
|
3128
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1483 |
#ifdef __POWERPC__ |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1484 |
// PPC appears to handle updating of rectangles right |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1485 |
{
|
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1486 |
uint num_dirty_rects; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1487 |
uint length_drawn; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1488 |
uint left; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1489 |
uint i; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1490 |
|
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1491 |
num_dirty_rects = _cocoa_video_data.num_dirty_rects; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1492 |
|
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1493 |
/* Check if we need to do anything */ |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1494 |
if (num_dirty_rects == 0 ) return; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1495 |
|
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1496 |
if (num_dirty_rects >= MAX_DIRTY_RECTS) {
|
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1497 |
num_dirty_rects = 1; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1498 |
_cocoa_video_data.dirty_rects[0].left = 0; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1499 |
_cocoa_video_data.dirty_rects[0].top = 0; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1500 |
_cocoa_video_data.dirty_rects[0].right = _cocoa_video_data.width; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1501 |
_cocoa_video_data.dirty_rects[0].bottom = _cocoa_video_data.height; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1502 |
} |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1503 |
|
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1504 |
QZ_WaitForVerticalBlank(); |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1505 |
/* Build the region of dirty rectangles */ |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1506 |
for (i = 0; i < num_dirty_rects; i++) {
|
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1507 |
|
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1508 |
y = _cocoa_video_data.dirty_rects[i].top; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1509 |
left = _cocoa_video_data.dirty_rects[i].left; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1510 |
length_drawn = _cocoa_video_data.dirty_rects[i].right - left + 1; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1511 |
height = _cocoa_video_data.dirty_rects[i].bottom; |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1512 |
for (; y <= height; y++) memcpy(dst + y * pitch + left, src + y * width +left, length_drawn); |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1513 |
} |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1514 |
|
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1515 |
_cocoa_video_data.num_dirty_rects = 0; |
|
3081
3a46f595b16b
(svn r3670) -Codechange: [OSX] rewrote a part of the cocoa video driver to speed it up by 1000% in fullscreen
bjarni
parents:
3038
diff
changeset
|
1516 |
} |
|
3128
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1517 |
#else |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1518 |
// it appears that Intel based macs didn't like to only update parts of the screen at a time, so they still update everything at each frame |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1519 |
// we need to switch to use Quartz exclusively (no QuickDraw commands at all) to fix this |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1520 |
// to use Quartz exclusively, we should use 16 or 32 bit graphics since 8 bit coloured graphic support sucks |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1521 |
height = _cocoa_video_data.height; |
|
3081
3a46f595b16b
(svn r3670) -Codechange: [OSX] rewrote a part of the cocoa video driver to speed it up by 1000% in fullscreen
bjarni
parents:
3038
diff
changeset
|
1522 |
QZ_WaitForVerticalBlank(); |
|
3128
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1523 |
for (y = 0; y < height; y++) memcpy(dst + y * pitch, src + y * width, width); |
|
7ad52c82e55b
(svn r3741) -Fix: [i686 OSX] reverted the change in rev 3670 for non PowerPC (done with #ifdef) since it appeared to crash intel based macs
bjarni
parents:
3082
diff
changeset
|
1524 |
#endif |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1525 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1526 |
|
| 3036 | 1527 |
static int QZ_ListFullscreenModes(OTTDPoint* mode_list, int max_modes) |
1528 |
{
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1529 |
CFIndex num_modes; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1530 |
CFIndex i; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1531 |
int list_size = 0; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1532 |
|
| 3036 | 1533 |
num_modes = CFArrayGetCount(_cocoa_video_data.mode_list); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1534 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1535 |
/* Build list of modes with the requested bpp */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1536 |
for (i = 0; i < num_modes && list_size < max_modes; i++) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1537 |
CFDictionaryRef onemode; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1538 |
CFNumberRef number; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1539 |
int bpp; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1540 |
int intvalue; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1541 |
bool hasMode; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1542 |
uint16 width, height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1543 |
|
| 3036 | 1544 |
onemode = CFArrayGetValueAtIndex(_cocoa_video_data.mode_list, i); |
1545 |
number = CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1546 |
CFNumberGetValue (number, kCFNumberSInt32Type, &bpp); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1547 |
|
| 3036 | 1548 |
if (bpp != 8) continue; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1549 |
|
| 3036 | 1550 |
number = CFDictionaryGetValue(onemode, kCGDisplayWidth); |
1551 |
CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); |
|
1552 |
width = (uint16)intvalue; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1553 |
|
| 3036 | 1554 |
number = CFDictionaryGetValue(onemode, kCGDisplayHeight); |
1555 |
CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); |
|
1556 |
height = (uint16)intvalue; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1557 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1558 |
/* Check if mode is already in the list */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1559 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1560 |
int i; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1561 |
hasMode = false; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1562 |
for (i = 0; i < list_size; i++) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1563 |
if (mode_list[i].x == width && mode_list[i].y == height) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1564 |
hasMode = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1565 |
break; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1566 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1567 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1568 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1569 |
|
| 3036 | 1570 |
if (hasMode) continue; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1571 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1572 |
/* Add mode to the list */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1573 |
mode_list[list_size].x = width; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1574 |
mode_list[list_size].y = height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1575 |
list_size++; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1576 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1577 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1578 |
/* Sort list smallest to largest */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1579 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1580 |
int i, j; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1581 |
for (i = 0; i < list_size; i++) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1582 |
for (j = 0; j < list_size-1; j++) {
|
| 3036 | 1583 |
if (mode_list[j].x > mode_list[j + 1].x || ( |
1584 |
mode_list[j].x == mode_list[j + 1].x && |
|
1585 |
mode_list[j].y > mode_list[j + 1].y |
|
1586 |
)) {
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1587 |
uint tmpw = mode_list[j].x; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1588 |
uint tmph = mode_list[j].y; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1589 |
|
| 3036 | 1590 |
mode_list[j].x = mode_list[j + 1].x; |
1591 |
mode_list[j].y = mode_list[j + 1].y; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1592 |
|
| 3036 | 1593 |
mode_list[j + 1].x = tmpw; |
1594 |
mode_list[j + 1].y = tmph; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1595 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1596 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1597 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1598 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1599 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1600 |
return list_size; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1601 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1602 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1603 |
|
| 3036 | 1604 |
/****************************************************************************** |
1605 |
* Windowed and fullscreen common code * |
|
1606 |
******************************************************************************/ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1607 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1608 |
static void QZ_UpdatePalette(uint start, uint count) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1609 |
{
|
| 3036 | 1610 |
if (_cocoa_video_data.fullscreen) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1611 |
QZ_UpdateFullscreenPalette(start, count); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1612 |
} else {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1613 |
QZ_UpdateWindowPalette(start, count); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1614 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1615 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1616 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1617 |
static void QZ_InitPalette(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1618 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1619 |
QZ_UpdatePalette(0, 256); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1620 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1621 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1622 |
static void QZ_Draw(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1623 |
{
|
| 3036 | 1624 |
if (_cocoa_video_data.fullscreen) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1625 |
QZ_DrawScreen(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1626 |
} else {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1627 |
QZ_DrawWindow(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1628 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1629 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1630 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1631 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1632 |
static const OTTDPoint _default_resolutions[] = {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1633 |
{ 640, 480},
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1634 |
{ 800, 600},
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1635 |
{1024, 768},
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1636 |
{1152, 864},
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1637 |
{1280, 800},
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1638 |
{1280, 960},
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1639 |
{1280, 1024},
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1640 |
{1400, 1050},
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1641 |
{1600, 1200},
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1642 |
{1680, 1050},
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1643 |
{1920, 1200}
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1644 |
}; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1645 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1646 |
static void QZ_UpdateVideoModes(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1647 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1648 |
uint i, j, count; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1649 |
OTTDPoint modes[32]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1650 |
const OTTDPoint *current_modes; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1651 |
|
| 3036 | 1652 |
if (_cocoa_video_data.fullscreen) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1653 |
count = QZ_ListFullscreenModes(modes, 32); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1654 |
current_modes = modes; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1655 |
} else {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1656 |
count = lengthof(_default_resolutions); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1657 |
current_modes = _default_resolutions; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1658 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1659 |
|
| 3036 | 1660 |
for (i = 0, j = 0; j < lengthof(_resolutions) && i < count; i++) {
|
1661 |
if (_cocoa_video_data.fullscreen || ( |
|
1662 |
(uint)current_modes[i].x <= _cocoa_video_data.device_width && |
|
1663 |
(uint)current_modes[i].y <= _cocoa_video_data.device_height) |
|
1664 |
) {
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1665 |
_resolutions[j][0] = current_modes[i].x; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1666 |
_resolutions[j][1] = current_modes[i].y; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1667 |
j++; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1668 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1669 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1670 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1671 |
_num_resolutions = j; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1672 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1673 |
|
| 3036 | 1674 |
static void QZ_UnsetVideoMode(void) |
1675 |
{
|
|
1676 |
if (_cocoa_video_data.fullscreen) {
|
|
1677 |
/* Release fullscreen resources */ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1678 |
OTTD_QuartzGammaTable gamma_table; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1679 |
int gamma_error; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1680 |
NSRect screen_rect; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1681 |
|
| 3036 | 1682 |
gamma_error = QZ_FadeGammaOut(&gamma_table); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1683 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1684 |
/* Restore original screen resolution/bpp */ |
| 3036 | 1685 |
CGDisplaySwitchToMode(_cocoa_video_data.display_id, _cocoa_video_data.save_mode); |
1686 |
CGReleaseAllDisplays(); |
|
1687 |
ShowMenuBar(); |
|
1688 |
/* Reset the main screen's rectangle |
|
1689 |
* See comment in QZ_SetVideoFullscreen for why we do this |
|
1690 |
*/ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1691 |
screen_rect = NSMakeRect(0,0,_cocoa_video_data.device_width,_cocoa_video_data.device_height); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1692 |
[ [ NSScreen mainScreen ] setFrame:screen_rect ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1693 |
|
| 3036 | 1694 |
if (!gamma_error) QZ_FadeGammaIn(&gamma_table); |
1695 |
} else {
|
|
1696 |
/* Release window mode resources */ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1697 |
[ _cocoa_video_data.window close ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1698 |
_cocoa_video_data.window = nil; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1699 |
_cocoa_video_data.qdview = nil; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1700 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1701 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1702 |
free(_cocoa_video_data.pixels); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1703 |
_cocoa_video_data.pixels = NULL; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1704 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1705 |
QZ_ShowMouse(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1706 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1707 |
/* Signal successful teardown */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1708 |
_cocoa_video_data.isset = false; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1709 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1710 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1711 |
|
| 3036 | 1712 |
static const char* QZ_SetVideoMode(uint width, uint height, bool fullscreen) |
1713 |
{
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1714 |
const char *ret; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1715 |
|
| 3036 | 1716 |
_cocoa_video_data.issetting = true; |
1717 |
if (fullscreen) {
|
|
1718 |
/* Setup full screen video */ |
|
1719 |
ret = QZ_SetVideoFullScreen(width, height); |
|
1720 |
} else {
|
|
1721 |
/* Setup windowed video */ |
|
1722 |
ret = QZ_SetVideoWindowed(width, height); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1723 |
} |
| 3036 | 1724 |
_cocoa_video_data.issetting = false; |
1725 |
if (ret != NULL) return ret; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1726 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1727 |
/* Signal successful completion (used internally) */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1728 |
_cocoa_video_data.isset = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1729 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1730 |
/* Tell the game that the resolution has changed */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1731 |
_screen.width = _cocoa_video_data.width; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1732 |
_screen.height = _cocoa_video_data.height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1733 |
_screen.pitch = _cocoa_video_data.width; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1734 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1735 |
QZ_UpdateVideoModes(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1736 |
GameSizeChanged(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1737 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1738 |
QZ_InitPalette(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1739 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1740 |
return NULL; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1741 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1742 |
|
| 3036 | 1743 |
static const char* QZ_SetVideoModeAndRestoreOnFailure(uint width, uint height, bool fullscreen) |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1744 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1745 |
bool wasset = _cocoa_video_data.isset; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1746 |
uint32 oldwidth = _cocoa_video_data.width; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1747 |
uint32 oldheight = _cocoa_video_data.height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1748 |
bool oldfullscreen = _cocoa_video_data.fullscreen; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1749 |
const char *ret; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1750 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1751 |
ret = QZ_SetVideoMode(width, height, fullscreen); |
| 3036 | 1752 |
if (ret != NULL && wasset) QZ_SetVideoMode(oldwidth, oldheight, oldfullscreen); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1753 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1754 |
return ret; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1755 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1756 |
|
| 3036 | 1757 |
static void QZ_VideoInit(void) |
1758 |
{
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1759 |
memset(&_cocoa_video_data, 0, sizeof(_cocoa_video_data)); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1760 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1761 |
/* Initialize the video settings; this data persists between mode switches */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1762 |
_cocoa_video_data.display_id = kCGDirectMainDisplay; |
| 3036 | 1763 |
_cocoa_video_data.save_mode = CGDisplayCurrentMode(_cocoa_video_data.display_id); |
1764 |
_cocoa_video_data.mode_list = CGDisplayAvailableModes(_cocoa_video_data.display_id); |
|
1765 |
_cocoa_video_data.palette = CGPaletteCreateDefaultColorPalette(); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1766 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1767 |
/* Gather some information that is useful to know about the display */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1768 |
/* Maybe this should be moved to QZ_SetVideoMode, in case this is changed after startup */ |
| 3036 | 1769 |
CFNumberGetValue( |
1770 |
CFDictionaryGetValue(_cocoa_video_data.save_mode, kCGDisplayBitsPerPixel), |
|
1771 |
kCFNumberSInt32Type, &_cocoa_video_data.device_bpp |
|
1772 |
); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1773 |
|
| 3036 | 1774 |
CFNumberGetValue( |
1775 |
CFDictionaryGetValue(_cocoa_video_data.save_mode, kCGDisplayWidth), |
|
1776 |
kCFNumberSInt32Type, &_cocoa_video_data.device_width |
|
1777 |
); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1778 |
|
| 3036 | 1779 |
CFNumberGetValue( |
1780 |
CFDictionaryGetValue(_cocoa_video_data.save_mode, kCGDisplayHeight), |
|
1781 |
kCFNumberSInt32Type, &_cocoa_video_data.device_height |
|
1782 |
); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1783 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1784 |
_cocoa_video_data.cursor_visible = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1785 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1786 |
/* register for sleep notifications so wake from sleep generates SDL_VIDEOEXPOSE */ |
| 3036 | 1787 |
// QZ_RegisterForSleepNotifications(); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1788 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1789 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1790 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1791 |
/* Convert local coordinate to window server (CoreGraphics) coordinate */ |
| 3036 | 1792 |
static CGPoint QZ_PrivateLocalToCG(NSPoint* p) |
1793 |
{
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1794 |
CGPoint cgp; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1795 |
|
| 3036 | 1796 |
if (!_cocoa_video_data.fullscreen) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1797 |
*p = [ _cocoa_video_data.qdview convertPoint:*p toView: nil ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1798 |
*p = [ _cocoa_video_data.window convertBaseToScreen:*p ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1799 |
p->y = _cocoa_video_data.device_height - p->y; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1800 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1801 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1802 |
cgp.x = p->x; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1803 |
cgp.y = p->y; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1804 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1805 |
return cgp; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1806 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1807 |
|
| 3036 | 1808 |
static void QZ_WarpCursor(int x, int y) |
1809 |
{
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1810 |
NSPoint p; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1811 |
CGPoint cgp; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1812 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1813 |
/* Only allow warping when in foreground */ |
| 3036 | 1814 |
if (![ NSApp isActive ]) return; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1815 |
|
| 3036 | 1816 |
p = NSMakePoint(x, y); |
1817 |
cgp = QZ_PrivateLocalToCG(&p); |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1818 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1819 |
/* this is the magic call that fixes cursor "freezing" after warp */ |
| 3036 | 1820 |
CGSetLocalEventsSuppressionInterval(0.0); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1821 |
/* Do the actual warp */ |
| 3036 | 1822 |
CGWarpMouseCursorPosition(cgp); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1823 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1824 |
/* Generate the mouse moved event */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1825 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1826 |
|
| 3036 | 1827 |
static void QZ_ShowMouse(void) |
1828 |
{
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1829 |
if (!_cocoa_video_data.cursor_visible) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1830 |
[ NSCursor unhide ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1831 |
_cocoa_video_data.cursor_visible = true; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1832 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1833 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1834 |
|
| 3036 | 1835 |
static void QZ_HideMouse(void) |
1836 |
{
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1837 |
if (_cocoa_video_data.cursor_visible) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1838 |
#ifndef _DEBUG |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1839 |
[ NSCursor hide ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1840 |
#endif |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1841 |
_cocoa_video_data.cursor_visible = false; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1842 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1843 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1844 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1845 |
|
| 3036 | 1846 |
/****************************************************************************** |
1847 |
* OS X application creation * |
|
1848 |
******************************************************************************/ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1849 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1850 |
/* The main class of the application, the application's delegate */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1851 |
@implementation OTTDMain |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1852 |
/* Called when the internal event loop has just started running */ |
| 3036 | 1853 |
- (void) applicationDidFinishLaunching: (NSNotification*) note |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1854 |
{
|
|
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1855 |
/* Hand off to main application code */ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1856 |
QZ_GameLoop(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1857 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1858 |
/* We're done, thank you for playing */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1859 |
[ NSApp stop:_ottd_main ]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1860 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1861 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1862 |
/* Display the in game quit confirmation dialog */ |
| 3036 | 1863 |
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1864 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1865 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1866 |
QZ_AskQuit(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1867 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1868 |
return NSTerminateCancel; // NSTerminateLater ? |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1869 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1870 |
@end |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1871 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1872 |
static void setApplicationMenu(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1873 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1874 |
/* warning: this code is very odd */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1875 |
NSMenu *appleMenu; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1876 |
NSMenuItem *menuItem; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1877 |
NSString *title; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1878 |
NSString *appName; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1879 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1880 |
appName = @"OTTD"; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1881 |
appleMenu = [[NSMenu alloc] initWithTitle:appName]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1882 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1883 |
/* Add menu items */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1884 |
title = [@"About " stringByAppendingString:appName]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1885 |
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1886 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1887 |
[appleMenu addItem:[NSMenuItem separatorItem]]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1888 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1889 |
title = [@"Hide " stringByAppendingString:appName]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1890 |
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1891 |
|
| 3036 | 1892 |
menuItem = (NSMenuItem*)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1893 |
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1894 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1895 |
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1896 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1897 |
[appleMenu addItem:[NSMenuItem separatorItem]]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1898 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1899 |
title = [@"Quit " stringByAppendingString:appName]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1900 |
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1901 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1902 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1903 |
/* Put menu into the menubar */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1904 |
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1905 |
[menuItem setSubmenu:appleMenu]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1906 |
[[NSApp mainMenu] addItem:menuItem]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1907 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1908 |
/* Tell the application object that this is now the application menu */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1909 |
[NSApp setAppleMenu:appleMenu]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1910 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1911 |
/* Finally give up our references to the objects */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1912 |
[appleMenu release]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1913 |
[menuItem release]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1914 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1915 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1916 |
/* Create a window menu */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1917 |
static void setupWindowMenu(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1918 |
{
|
| 3036 | 1919 |
NSMenu* windowMenu; |
1920 |
NSMenuItem* windowMenuItem; |
|
1921 |
NSMenuItem* menuItem; |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1922 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1923 |
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1924 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1925 |
/* "Minimize" item */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1926 |
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1927 |
[windowMenu addItem:menuItem]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1928 |
[menuItem release]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1929 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1930 |
/* Put menu into the menubar */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1931 |
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1932 |
[windowMenuItem setSubmenu:windowMenu]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1933 |
[[NSApp mainMenu] addItem:windowMenuItem]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1934 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1935 |
/* Tell the application object that this is now the window menu */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1936 |
[NSApp setWindowsMenu:windowMenu]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1937 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1938 |
/* Finally give up our references to the objects */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1939 |
[windowMenu release]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1940 |
[windowMenuItem release]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1941 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1942 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1943 |
static void setupApplication(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1944 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1945 |
CPSProcessSerNum PSN; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1946 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1947 |
/* Ensure the application object is initialised */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1948 |
[NSApplication sharedApplication]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1949 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1950 |
/* Tell the dock about us */ |
| 3036 | 1951 |
if (!CPSGetCurrentProcess(&PSN) && |
1952 |
!CPSEnableForegroundOperation(&PSN, 0x03, 0x3C, 0x2C, 0x1103) && |
|
1953 |
!CPSSetFrontProcess(&PSN)) {
|
|
1954 |
[NSApplication sharedApplication]; |
|
1955 |
} |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1956 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1957 |
/* Set up the menubar */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1958 |
[NSApp setMainMenu:[[NSMenu alloc] init]]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1959 |
setApplicationMenu(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1960 |
setupWindowMenu(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1961 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1962 |
/* Create OTTDMain and make it the app delegate */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1963 |
_ottd_main = [[OTTDMain alloc] init]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1964 |
[NSApp setDelegate:_ottd_main]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1965 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1966 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1967 |
|
| 3036 | 1968 |
/****************************************************************************** |
1969 |
* Video driver interface * |
|
1970 |
******************************************************************************/ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1971 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1972 |
static void CocoaVideoStop(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1973 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1974 |
DEBUG(driver, 1)("cocoa_v: CocoaVideoStop");
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1975 |
|
| 3036 | 1976 |
if (!_cocoa_video_started) return; |
|
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1977 |
|
| 3036 | 1978 |
if (_cocoa_video_data.isset) QZ_UnsetVideoMode(); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1979 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1980 |
[_ottd_main release]; |
|
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1981 |
|
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1982 |
_cocoa_video_started = false; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1983 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1984 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1985 |
static const char *CocoaVideoStart(const char * const *parm) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1986 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1987 |
const char *ret; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1988 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1989 |
DEBUG(driver, 1)("cocoa_v: CocoaVideoStart");
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1990 |
|
| 3036 | 1991 |
if (_cocoa_video_started) return "Already started"; |
|
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1992 |
_cocoa_video_started = true; |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1993 |
|
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1994 |
memset(&_cocoa_video_data, 0, sizeof(_cocoa_video_data)); |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1995 |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1996 |
setupApplication(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1997 |
|
|
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1998 |
/* Don't create a window or enter fullscreen if we're just going to show a dialog. */ |
| 3036 | 1999 |
if (_cocoa_video_dialog) return NULL; |
|
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2000 |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2001 |
QZ_VideoInit(); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2002 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2003 |
ret = QZ_SetVideoMode(_cur_resolution[0], _cur_resolution[1], _fullscreen); |
| 3036 | 2004 |
if (ret != NULL) CocoaVideoStop(); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2005 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2006 |
return ret; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2007 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2008 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2009 |
static void CocoaVideoMakeDirty(int left, int top, int width, int height) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2010 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2011 |
if (_cocoa_video_data.num_dirty_rects < MAX_DIRTY_RECTS) {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2012 |
_cocoa_video_data.dirty_rects[_cocoa_video_data.num_dirty_rects].left = left; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2013 |
_cocoa_video_data.dirty_rects[_cocoa_video_data.num_dirty_rects].top = top; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2014 |
_cocoa_video_data.dirty_rects[_cocoa_video_data.num_dirty_rects].right = left + width; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2015 |
_cocoa_video_data.dirty_rects[_cocoa_video_data.num_dirty_rects].bottom = top + height; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2016 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2017 |
_cocoa_video_data.num_dirty_rects++; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2018 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2019 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2020 |
static void CocoaVideoMainLoop(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2021 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2022 |
DEBUG(driver, 1)("cocoa_v: CocoaVideoMainLoop");
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2023 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2024 |
/* Start the main event loop */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2025 |
[NSApp run]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2026 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2027 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2028 |
static bool CocoaVideoChangeRes(int w, int h) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2029 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2030 |
const char *ret; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2031 |
DEBUG(driver, 1)("cocoa_v: CocoaVideoChangeRes");
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2032 |
|
| 3036 | 2033 |
ret = QZ_SetVideoModeAndRestoreOnFailure((uint)w, (uint)h, _cocoa_video_data.fullscreen); |
2034 |
if (ret != NULL) {
|
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2035 |
DEBUG(driver, 1)("cocoa_v: failed with message: %s", ret);
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2036 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2037 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2038 |
return ret == NULL; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2039 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2040 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2041 |
static void CocoaVideoFullScreen(bool full_screen) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2042 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2043 |
const char *ret; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2044 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2045 |
DEBUG(driver, 1)("cocoa_v: CocoaVideoFullScreen");
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2046 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2047 |
ret = QZ_SetVideoModeAndRestoreOnFailure(_cocoa_video_data.width, _cocoa_video_data.height, full_screen); |
| 3036 | 2048 |
if (ret != NULL) {
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2049 |
DEBUG(driver, 1)("cocoa_v: failed with message: %s", ret);
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2050 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2051 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2052 |
_fullscreen = _cocoa_video_data.fullscreen; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2053 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2054 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2055 |
const HalVideoDriver _cocoa_video_driver = {
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2056 |
CocoaVideoStart, |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2057 |
CocoaVideoStop, |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2058 |
CocoaVideoMakeDirty, |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2059 |
CocoaVideoMainLoop, |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2060 |
CocoaVideoChangeRes, |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2061 |
CocoaVideoFullScreen, |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2062 |
}; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2063 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2064 |
|
|
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2065 |
/* This is needed since sometimes assert is called before the videodriver is initialized */ |
| 3036 | 2066 |
void CocoaDialog(const char* title, const char* message, const char* buttonLabel) |
|
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2067 |
{
|
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2068 |
bool wasstarted; |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2069 |
|
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2070 |
_cocoa_video_dialog = true; |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2071 |
|
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2072 |
wasstarted = _cocoa_video_started; |
| 3036 | 2073 |
if (!_cocoa_video_started && CocoaVideoStart(NULL) != NULL) {
|
|
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2074 |
fprintf(stderr, "%s: %s\n", title, message); |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2075 |
return; |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2076 |
} |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2077 |
|
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2078 |
NSRunAlertPanel([NSString stringWithCString: title], [NSString stringWithCString: message], [NSString stringWithCString: buttonLabel], nil, nil); |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2079 |
|
| 3036 | 2080 |
if (!wasstarted) CocoaVideoStop(); |
|
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2081 |
|
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2082 |
_cocoa_video_dialog = false; |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2083 |
} |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2084 |
|
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2085 |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2086 |
/* This is needed since OS X applications are started with the working dir set to / when double-clicked */ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2087 |
void cocoaSetWorkingDirectory(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2088 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2089 |
char parentdir[MAXPATHLEN]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2090 |
int chdir_ret; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2091 |
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2092 |
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); |
| 3036 | 2093 |
if (CFURLGetFileSystemRepresentation(url2, true, (unsigned char*)parentdir, MAXPATHLEN)) {
|
2094 |
chdir_ret = chdir(parentdir); /* chdir to the binary app's parent */ |
|
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2095 |
assert(chdir_ret == 0); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2096 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2097 |
CFRelease(url); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2098 |
CFRelease(url2); |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2099 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2100 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2101 |
/* These are called from main() to prevent a _NSAutoreleaseNoPool error when |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2102 |
* exiting before the cocoa video driver has been loaded |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2103 |
*/ |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2104 |
void cocoaSetupAutoreleasePool(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2105 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2106 |
_ottd_autorelease_pool = [[NSAutoreleasePool alloc] init]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2107 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2108 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2109 |
void cocoaReleaseAutoreleasePool(void) |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2110 |
{
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2111 |
[_ottd_autorelease_pool release]; |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2112 |
} |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2113 |
|
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2114 |
#endif /* WITH_COCOA */ |