author | peter1138 |
Mon, 23 Oct 2006 21:39:15 +0000 | |
changeset 4932 | 4bf213d0ed53 |
parent 4550 | 089509518963 |
child 5086 | 386ba9fe0621 |
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 |
typedef struct VkMapping { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
201 |
unsigned short vk_from; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
202 |
byte map_to; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
203 |
} VkMapping; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
204 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
205 |
#define AS(x, z) {x, z} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
206 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
207 |
static const VkMapping _vk_mapping[] = { |
3036 | 208 |
AS(QZ_BACKQUOTE, WKC_BACKQUOTE), // key left of '1' |
209 |
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
|
210 |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
211 |
// Pageup stuff + up/down |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
212 |
//AM(SDLK_PAGEUP, SDLK_PAGEDOWN, WKC_PAGEUP, WKC_PAGEDOWN), <==== Does this include HOME/END? |
3036 | 213 |
AS(QZ_PAGEUP, WKC_PAGEUP), |
214 |
AS(QZ_PAGEDOWN, WKC_PAGEDOWN), |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
215 |
|
3036 | 216 |
AS(QZ_UP, WKC_UP), |
217 |
AS(QZ_DOWN, WKC_DOWN), |
|
218 |
AS(QZ_LEFT, WKC_LEFT), |
|
219 |
AS(QZ_RIGHT, WKC_RIGHT), |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
220 |
|
3036 | 221 |
AS(QZ_HOME, WKC_HOME), |
222 |
AS(QZ_END, WKC_END), |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
223 |
|
3036 | 224 |
AS(QZ_INSERT, WKC_INSERT), |
225 |
AS(QZ_DELETE, WKC_DELETE), |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
226 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
227 |
// Letters. QZ_[a-z] is not in numerical order so we can't use AM(...) |
3036 | 228 |
AS(QZ_a, 'A'), |
229 |
AS(QZ_b, 'B'), |
|
230 |
AS(QZ_c, 'C'), |
|
231 |
AS(QZ_d, 'D'), |
|
232 |
AS(QZ_e, 'E'), |
|
233 |
AS(QZ_f, 'F'), |
|
234 |
AS(QZ_g, 'G'), |
|
235 |
AS(QZ_h, 'H'), |
|
236 |
AS(QZ_i, 'I'), |
|
237 |
AS(QZ_j, 'J'), |
|
238 |
AS(QZ_k, 'K'), |
|
239 |
AS(QZ_l, 'L'), |
|
240 |
AS(QZ_m, 'M'), |
|
241 |
AS(QZ_n, 'N'), |
|
242 |
AS(QZ_o, 'O'), |
|
243 |
AS(QZ_p, 'P'), |
|
244 |
AS(QZ_q, 'Q'), |
|
245 |
AS(QZ_r, 'R'), |
|
246 |
AS(QZ_s, 'S'), |
|
247 |
AS(QZ_t, 'T'), |
|
248 |
AS(QZ_u, 'U'), |
|
249 |
AS(QZ_v, 'V'), |
|
250 |
AS(QZ_w, 'W'), |
|
251 |
AS(QZ_x, 'X'), |
|
252 |
AS(QZ_y, 'Y'), |
|
253 |
AS(QZ_z, 'Z'), |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
254 |
// Same thing for digits |
3036 | 255 |
AS(QZ_0, '0'), |
256 |
AS(QZ_1, '1'), |
|
257 |
AS(QZ_2, '2'), |
|
258 |
AS(QZ_3, '3'), |
|
259 |
AS(QZ_4, '4'), |
|
260 |
AS(QZ_5, '5'), |
|
261 |
AS(QZ_6, '6'), |
|
262 |
AS(QZ_7, '7'), |
|
263 |
AS(QZ_8, '8'), |
|
264 |
AS(QZ_9, '9'), |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
265 |
|
3036 | 266 |
AS(QZ_ESCAPE, WKC_ESC), |
267 |
AS(QZ_PAUSE, WKC_PAUSE), |
|
268 |
AS(QZ_BACKSPACE, WKC_BACKSPACE), |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
269 |
|
3036 | 270 |
AS(QZ_SPACE, WKC_SPACE), |
271 |
AS(QZ_RETURN, WKC_RETURN), |
|
272 |
AS(QZ_TAB, WKC_TAB), |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
273 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
274 |
// Function keys |
3036 | 275 |
AS(QZ_F1, WKC_F1), |
276 |
AS(QZ_F2, WKC_F2), |
|
277 |
AS(QZ_F3, WKC_F3), |
|
278 |
AS(QZ_F4, WKC_F4), |
|
279 |
AS(QZ_F5, WKC_F5), |
|
280 |
AS(QZ_F6, WKC_F6), |
|
281 |
AS(QZ_F7, WKC_F7), |
|
282 |
AS(QZ_F8, WKC_F8), |
|
283 |
AS(QZ_F9, WKC_F9), |
|
284 |
AS(QZ_F10, WKC_F10), |
|
285 |
AS(QZ_F11, WKC_F11), |
|
286 |
AS(QZ_F12, WKC_F12), |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
287 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
288 |
// Numeric part. |
3036 | 289 |
AS(QZ_KP0, WKC_NUM_0), |
290 |
AS(QZ_KP1, WKC_NUM_1), |
|
291 |
AS(QZ_KP2, WKC_NUM_2), |
|
292 |
AS(QZ_KP3, WKC_NUM_3), |
|
293 |
AS(QZ_KP4, WKC_NUM_4), |
|
294 |
AS(QZ_KP5, WKC_NUM_5), |
|
295 |
AS(QZ_KP6, WKC_NUM_6), |
|
296 |
AS(QZ_KP7, WKC_NUM_7), |
|
297 |
AS(QZ_KP8, WKC_NUM_8), |
|
298 |
AS(QZ_KP9, WKC_NUM_9), |
|
299 |
AS(QZ_KP_DIVIDE, WKC_NUM_DIV), |
|
300 |
AS(QZ_KP_MULTIPLY, WKC_NUM_MUL), |
|
301 |
AS(QZ_KP_MINUS, WKC_NUM_MINUS), |
|
302 |
AS(QZ_KP_PLUS, WKC_NUM_PLUS), |
|
303 |
AS(QZ_KP_ENTER, WKC_NUM_ENTER), |
|
304 |
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
|
305 |
}; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
306 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
307 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
308 |
static uint32 QZ_MapKey(unsigned short sym) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
309 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
310 |
const VkMapping *map; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
311 |
uint32 key = 0; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
312 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
313 |
for (map = _vk_mapping; map != endof(_vk_mapping); ++map) { |
3036 | 314 |
if (sym == map->vk_from) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
315 |
key = map->map_to; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
316 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
317 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
318 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
319 |
|
3036 | 320 |
if (_cocoa_video_data.current_mods & NSShiftKeyMask) key |= WKC_SHIFT; |
321 |
if (_cocoa_video_data.current_mods & NSControlKeyMask) key |= WKC_CTRL; |
|
322 |
if (_cocoa_video_data.current_mods & NSAlternateKeyMask) key |= WKC_ALT; |
|
323 |
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
|
324 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
325 |
return key << 16; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
326 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
327 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
328 |
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
|
329 |
{ |
3036 | 330 |
switch (keycode) { |
331 |
case QZ_UP: SB(_dirkeys, 1, 1, down); break; |
|
332 |
case QZ_DOWN: SB(_dirkeys, 3, 1, down); break; |
|
333 |
case QZ_LEFT: SB(_dirkeys, 0, 1, down); break; |
|
334 |
case QZ_RIGHT: SB(_dirkeys, 2, 1, down); break; |
|
335 |
||
336 |
case QZ_TAB: _cocoa_video_data.tab_is_down = down; break; |
|
337 |
||
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
338 |
case QZ_RETURN: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
339 |
case QZ_f: |
3036 | 340 |
if (down && ( |
341 |
(_cocoa_video_data.current_mods & NSControlKeyMask) || |
|
342 |
(_cocoa_video_data.current_mods & NSCommandKeyMask) |
|
343 |
)) { |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
344 |
CocoaVideoFullScreen(!_fullscreen); |
3036 | 345 |
} |
346 |
break; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
347 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
348 |
|
3036 | 349 |
if (down) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
350 |
_pressed_key = QZ_MapKey(keycode) | unicode; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
351 |
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
|
352 |
} else { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
353 |
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
|
354 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
355 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
356 |
|
3036 | 357 |
static void QZ_DoUnsidedModifiers(unsigned int newMods) |
358 |
{ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
359 |
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
|
360 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
361 |
int i; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
362 |
int bit; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
363 |
|
3036 | 364 |
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
|
365 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
366 |
/* 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
|
367 |
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
|
368 |
unsigned int currentMask, newMask; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
369 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
370 |
currentMask = _cocoa_video_data.current_mods & bit; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
371 |
newMask = newMods & bit; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
372 |
|
3036 | 373 |
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
|
374 |
/* If this was Caps Lock, we need some additional voodoo to make SDL happy (is this needed in ottd?) */ |
3036 | 375 |
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
|
376 |
QZ_KeyEvent(mapping[i], 0, NO); |
3036 | 377 |
} 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
|
378 |
QZ_KeyEvent(mapping[i], 0, YES); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
379 |
/* If this was Caps Lock, we need some additional voodoo to make SDL happy (is this needed in ottd?) */ |
3036 | 380 |
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
|
381 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
382 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
383 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
384 |
_cocoa_video_data.current_mods = newMods; |
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
387 |
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
|
388 |
{ |
3036 | 389 |
if (_cursor.fix_at) { |
390 |
int dx = x - _cursor.pos.x; |
|
391 |
int dy = y - _cursor.pos.y; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
392 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
393 |
if (dx != 0 || dy != 0) { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
394 |
_cursor.delta.x += dx; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
395 |
_cursor.delta.y += dy; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
396 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
397 |
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
|
398 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
399 |
} else { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
400 |
_cursor.delta.x = x - _cursor.pos.x; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
401 |
_cursor.delta.y = y - _cursor.pos.y; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
402 |
_cursor.pos.x = x; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
403 |
_cursor.pos.y = y; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
404 |
_cursor.dirty = true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
405 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
406 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
407 |
|
4509 | 408 |
|
409 |
static 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
|
410 |
{ |
3036 | 411 |
switch (button) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
412 |
case 0: |
3036 | 413 |
if (down) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
414 |
_left_button_down = true; |
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 |
_left_button_down = false; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
417 |
_left_button_clicked = false; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
418 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
419 |
break; |
3036 | 420 |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
421 |
case 1: |
3036 | 422 |
if (down) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
423 |
_right_button_down = true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
424 |
_right_button_clicked = true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
425 |
} else { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
426 |
_right_button_down = false; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
427 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
428 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
429 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
430 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
431 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
432 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
433 |
static inline NSPoint QZ_GetMouseLocation(NSEvent *event) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
434 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
435 |
NSPoint pt; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
436 |
|
3036 | 437 |
if (_cocoa_video_data.fullscreen) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
438 |
pt = [ NSEvent mouseLocation ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
439 |
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
|
440 |
} else { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
441 |
pt = [event locationInWindow]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
442 |
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
|
443 |
} |
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 |
return pt; |
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 bool QZ_MouseIsInsideView(NSPoint *pt) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
449 |
{ |
3036 | 450 |
if (_cocoa_video_data.fullscreen) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
451 |
return pt->x >= 0 && pt->y >= 0 && pt->x < _cocoa_video_data.width && pt->y < _cocoa_video_data.height; |
3036 | 452 |
} else { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
453 |
return [ _cocoa_video_data.qdview mouse:*pt inRect:[ _cocoa_video_data.qdview bounds ] ]; |
3036 | 454 |
} |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
455 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
456 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
457 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
458 |
static bool QZ_PollEvent(void) |
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 |
NSEvent *event; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
461 |
NSPoint pt; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
462 |
NSString *chars; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
463 |
#ifdef _DEBUG |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
464 |
uint32 et0, et; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
465 |
#endif |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
466 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
467 |
#ifdef _DEBUG |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
468 |
et0 = GetTick(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
469 |
#endif |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
470 |
event = [ NSApp nextEventMatchingMask:NSAnyEventMask |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
471 |
untilDate: [ NSDate distantPast ] |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
472 |
inMode: NSDefaultRunLoopMode dequeue:YES ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
473 |
#ifdef _DEBUG |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
474 |
et = GetTick(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
475 |
_cocoa_video_data.tEvent+= et - et0; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
476 |
#endif |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
477 |
|
3036 | 478 |
if (event == nil) return false; |
479 |
if (!_cocoa_video_data.active) { |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
480 |
QZ_ShowMouse(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
481 |
[NSApp sendEvent:event]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
482 |
return true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
483 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
484 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
485 |
QZ_DoUnsidedModifiers( [ event modifierFlags ] ); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
486 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
487 |
switch ([event type]) { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
488 |
case NSMouseMoved: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
489 |
case NSOtherMouseDragged: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
490 |
case NSRightMouseDragged: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
491 |
case NSLeftMouseDragged: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
492 |
pt = QZ_GetMouseLocation(event); |
3036 | 493 |
if (!QZ_MouseIsInsideView(&pt) && |
494 |
!_cocoa_video_data.emulating_right_button) { |
|
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 |
break; |
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_HideMouse(); |
3036 | 501 |
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
|
502 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
503 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
504 |
case NSLeftMouseDown: |
3036 | 505 |
if (!([ event modifierFlags ] & NSCommandKeyMask) || |
506 |
!QZ_MouseIsInsideView(&pt)) { |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
507 |
[NSApp sendEvent:event]; |
3036 | 508 |
} |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
509 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
510 |
pt = QZ_GetMouseLocation(event); |
3036 | 511 |
if (!QZ_MouseIsInsideView(&pt)) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
512 |
QZ_ShowMouse(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
513 |
break; |
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
516 |
QZ_HideMouse(); |
3036 | 517 |
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
|
518 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
519 |
/* Right mouse button emulation */ |
3036 | 520 |
if ([ event modifierFlags ] & NSCommandKeyMask) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
521 |
_cocoa_video_data.emulating_right_button = true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
522 |
QZ_MouseButtonEvent(1, YES); |
3036 | 523 |
} else { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
524 |
QZ_MouseButtonEvent(0, YES); |
3036 | 525 |
} |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
526 |
break; |
3036 | 527 |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
528 |
case NSLeftMouseUp: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
529 |
[NSApp sendEvent:event]; |
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 |
pt = QZ_GetMouseLocation(event); |
3036 | 532 |
if (!QZ_MouseIsInsideView(&pt)) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
533 |
QZ_ShowMouse(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
534 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
535 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
536 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
537 |
QZ_HideMouse(); |
3036 | 538 |
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
|
539 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
540 |
/* Right mouse button emulation */ |
3036 | 541 |
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
|
542 |
_cocoa_video_data.emulating_right_button = false; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
543 |
QZ_MouseButtonEvent(1, NO); |
3036 | 544 |
} else { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
545 |
QZ_MouseButtonEvent(0, NO); |
3036 | 546 |
} |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
547 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
548 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
549 |
case NSRightMouseDown: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
550 |
pt = QZ_GetMouseLocation(event); |
3036 | 551 |
if (!QZ_MouseIsInsideView(&pt)) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
552 |
QZ_ShowMouse(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
553 |
[NSApp sendEvent:event]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
554 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
555 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
556 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
557 |
QZ_HideMouse(); |
3036 | 558 |
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
|
559 |
QZ_MouseButtonEvent(1, YES); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
560 |
break; |
3036 | 561 |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
562 |
case NSRightMouseUp: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
563 |
pt = QZ_GetMouseLocation(event); |
3036 | 564 |
if (!QZ_MouseIsInsideView(&pt)) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
565 |
QZ_ShowMouse(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
566 |
[NSApp sendEvent:event]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
567 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
568 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
569 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
570 |
QZ_HideMouse(); |
3036 | 571 |
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
|
572 |
QZ_MouseButtonEvent(1, NO); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
573 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
574 |
|
3036 | 575 |
#if 0 |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
576 |
/* 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
|
577 |
case NSOtherMouseDown: |
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([ event buttonNumber ], YES); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
588 |
break; |
3036 | 589 |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
590 |
case NSOtherMouseUp: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
591 |
pt = QZ_GetMouseLocation(event); |
3036 | 592 |
if (!QZ_MouseIsInsideView(&pt)) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
593 |
QZ_ShowMouse(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
594 |
[NSApp sendEvent:event]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
595 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
596 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
597 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
598 |
QZ_HideMouse(); |
3036 | 599 |
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
|
600 |
QZ_MouseButtonEvent([ event buttonNumber ], NO); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
601 |
break; |
3036 | 602 |
#endif |
603 |
||
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
604 |
case NSKeyDown: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
605 |
/* Quit, hide and minimize */ |
3036 | 606 |
switch ([event keyCode]) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
607 |
case QZ_q: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
608 |
case QZ_h: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
609 |
case QZ_m: |
3036 | 610 |
if ([ event modifierFlags ] & NSCommandKeyMask) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
611 |
[NSApp sendEvent:event]; |
3036 | 612 |
} |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
613 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
614 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
615 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
616 |
chars = [ event characters ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
617 |
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
|
618 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
619 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
620 |
case NSKeyUp: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
621 |
/* Quit, hide and minimize */ |
3036 | 622 |
switch ([event keyCode]) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
623 |
case QZ_q: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
624 |
case QZ_h: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
625 |
case QZ_m: |
3036 | 626 |
if ([ event modifierFlags ] & NSCommandKeyMask) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
627 |
[NSApp sendEvent:event]; |
3036 | 628 |
} |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
629 |
break; |
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
632 |
chars = [ event characters ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
633 |
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
|
634 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
635 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
636 |
case NSScrollWheel: |
4116
f57064a934a3
(svn r5460) -Feature: [OSX] macs with touchpads that support two finger scrolling can now use this "scrollwheel" to scroll up/down (ln-)
bjarni
parents:
4000
diff
changeset
|
637 |
if ([ event deltaY ] > 0.0) { /* Scroll up */ |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
638 |
_cursor.wheel--; |
4116
f57064a934a3
(svn r5460) -Feature: [OSX] macs with touchpads that support two finger scrolling can now use this "scrollwheel" to scroll up/down (ln-)
bjarni
parents:
4000
diff
changeset
|
639 |
} else if ([ event deltaY ] < 0.0) { /* Scroll down */ |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
640 |
_cursor.wheel++; |
4116
f57064a934a3
(svn r5460) -Feature: [OSX] macs with touchpads that support two finger scrolling can now use this "scrollwheel" to scroll up/down (ln-)
bjarni
parents:
4000
diff
changeset
|
641 |
} /* else: deltaY was 0.0 and we don't want to do anything */ |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
642 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
643 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
644 |
default: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
645 |
[NSApp sendEvent:event]; |
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
648 |
return true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
649 |
} |
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
652 |
static void QZ_GameLoop(void) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
653 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
654 |
uint32 next_tick = GetTick() + 30; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
655 |
uint32 cur_ticks; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
656 |
uint32 pal_tick = 0; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
657 |
#ifdef _DEBUG |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
658 |
uint32 et0, et, st0, st; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
659 |
#endif |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
660 |
int i; |
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 |
DEBUG(driver, 1)("cocoa_v: QZ_GameLoop"); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
663 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
664 |
#ifdef _DEBUG |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
665 |
et0 = GetTick(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
666 |
st = 0; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
667 |
#endif |
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 |
_screen.dst_ptr = _cocoa_video_data.pixels; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
670 |
DisplaySplashImage(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
671 |
QZ_CheckPaletteAnim(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
672 |
QZ_Draw(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
673 |
CSleep(1); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
674 |
|
3036 | 675 |
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
|
676 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
677 |
_screen.dst_ptr = _cocoa_video_data.pixels; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
678 |
UpdateWindows(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
679 |
QZ_CheckPaletteAnim(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
680 |
QZ_Draw(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
681 |
CSleep(1); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
682 |
|
3036 | 683 |
for (;;) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
684 |
InteractiveRandom(); // randomness |
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 |
while (QZ_PollEvent()) {} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
687 |
|
3036 | 688 |
if (_exit_game) break; |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
689 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
690 |
#if defined(_DEBUG) |
3036 | 691 |
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
|
692 |
#else |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
693 |
if (_cocoa_video_data.tab_is_down) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
694 |
#endif |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
695 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
696 |
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2; |
4536
d532b2611952
(svn r6365) -Cleanup: remove IsGeneratingWorld calls that are either not called or have no effect.
rubidium
parents:
4509
diff
changeset
|
697 |
} else if (_fast_forward & 2) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
698 |
_fast_forward = 0; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
699 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
700 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
701 |
cur_ticks = GetTick(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
702 |
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
|
703 |
next_tick = cur_ticks; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
704 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
705 |
if (cur_ticks == next_tick) { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
706 |
next_tick += 30; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
707 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
708 |
_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
|
709 |
_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
|
710 |
#ifdef _DEBUG |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
711 |
_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
|
712 |
#endif |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
713 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
714 |
GameLoop(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
715 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
716 |
_screen.dst_ptr = _cocoa_video_data.pixels; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
717 |
UpdateWindows(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
718 |
if (++pal_tick > 4) { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
719 |
QZ_CheckPaletteAnim(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
720 |
pal_tick = 1; |
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 |
QZ_Draw(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
723 |
} else { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
724 |
#ifdef _DEBUG |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
725 |
st0 = GetTick(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
726 |
#endif |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
727 |
CSleep(1); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
728 |
#ifdef _DEBUG |
3036 | 729 |
st += GetTick() - st0; |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
730 |
#endif |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
731 |
_screen.dst_ptr = _cocoa_video_data.pixels; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
732 |
DrawTextMessage(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
733 |
DrawMouseCursor(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
734 |
QZ_Draw(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
735 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
736 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
737 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
738 |
#ifdef _DEBUG |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
739 |
et = GetTick(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
740 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
741 |
DEBUG(driver, 1)("cocoa_v: nextEventMatchingMask took %i ms total", _cocoa_video_data.tEvent); |
3036 | 742 |
DEBUG(driver, 1)("cocoa_v: game loop took %i ms total (%i ms without sleep)", et - et0, et - et0 - st); |
743 |
DEBUG(driver, 1)("cocoa_v: (nextEventMatchingMask total)/(game loop total) is %f%%", (double)_cocoa_video_data.tEvent / (double)(et - et0) * 100); |
|
744 |
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
|
745 |
#endif |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
746 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
747 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
748 |
|
3036 | 749 |
/****************************************************************************** |
750 |
* Windowed mode * |
|
751 |
******************************************************************************/ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
752 |
|
3036 | 753 |
/* This function makes the *game region* of the window 100% opaque. |
754 |
* The genie effect uses the alpha component. Otherwise, |
|
755 |
* it doesn't seem to matter what value it has. |
|
756 |
*/ |
|
757 |
static void QZ_SetPortAlphaOpaque(void) |
|
758 |
{ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
759 |
if (_cocoa_video_data.device_bpp == 32) { |
3036 | 760 |
uint32* pixels = (uint32*)_cocoa_video_data.realpixels; |
761 |
uint32 rowPixels = _cocoa_video_data.pitch / 4; |
|
762 |
uint32 i; |
|
763 |
uint32 j; |
|
2736
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 |
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
|
766 |
for (j = 0; j < _cocoa_video_data.width; j++) { |
3036 | 767 |
pixels[i * rowPixels + j] |= 0xFF000000; |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
768 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
769 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
770 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
771 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
772 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
773 |
@implementation OTTD_QuartzWindow |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
774 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
775 |
/* 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
|
776 |
- (void)miniaturize:(id)sender |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
777 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
778 |
/* 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
|
779 |
QZ_SetPortAlphaOpaque (); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
780 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
781 |
/* window is hidden now */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
782 |
_cocoa_video_data.active = false; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
783 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
784 |
QZ_ShowMouse(); |
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 |
[ super miniaturize:sender ]; |
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 |
- (void)display |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
790 |
{ |
3036 | 791 |
/* This method fires just before the window deminaturizes from the Dock. |
792 |
* We'll save the current visible surface, let the window manager redraw any |
|
793 |
* UI elements, and restore the surface. This way, no expose event |
|
794 |
* is required, and the deminiaturize works perfectly. |
|
795 |
*/ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
796 |
|
3036 | 797 |
QZ_SetPortAlphaOpaque(); |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
798 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
799 |
/* save current visible surface */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
800 |
[ self cacheImageInRect:[ _cocoa_video_data.qdview frame ] ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
801 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
802 |
/* 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
|
803 |
[ super display ]; |
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 |
/* restore visible surface */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
806 |
[ self restoreCachedImage ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
807 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
808 |
/* window is visible again */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
809 |
_cocoa_video_data.active = true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
810 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
811 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
812 |
- (void)setFrame:(NSRect)frameRect display:(BOOL)flag |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
813 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
814 |
NSRect newViewFrame; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
815 |
CGrafPtr thePort; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
816 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
817 |
[ super setFrame:frameRect display:flag ]; |
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 |
/* Don't do anything if the window is currently beign created */ |
3036 | 820 |
if (_cocoa_video_data.issetting) return; |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
821 |
|
3036 | 822 |
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
|
823 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
824 |
newViewFrame = [ _cocoa_video_data.qdview frame ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
825 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
826 |
/* Update the pixels and pitch */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
827 |
thePort = [ _cocoa_video_data.qdview qdPort ]; |
3036 | 828 |
LockPortBits(thePort); |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
829 |
|
3036 | 830 |
_cocoa_video_data.realpixels = GetPixBaseAddr(GetPortPixMap(thePort)); |
831 |
_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
|
832 |
|
3036 | 833 |
/* _cocoa_video_data.realpixels now points to the window's pixels |
834 |
* We want it to point to the *view's* pixels |
|
835 |
*/ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
836 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
837 |
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
|
838 |
int hOffset = newViewFrame.origin.x; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
839 |
|
3036 | 840 |
_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
|
841 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
842 |
|
3036 | 843 |
UnlockPortBits(thePort); |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
844 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
845 |
/* Allocate new buffer */ |
3036 | 846 |
free(_cocoa_video_data.pixels); |
847 |
_cocoa_video_data.pixels = (uint8*)malloc(newViewFrame.size.width * newViewFrame.size.height); |
|
3261
e17a3e96f11e
(svn r3971) reverted r3742 as those new errors were not the right way to handle those exceptions
bjarni
parents:
3129
diff
changeset
|
848 |
assert(_cocoa_video_data.pixels != NULL); |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
849 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
850 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
851 |
/* Tell the game that the resolution changed */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
852 |
_cocoa_video_data.width = newViewFrame.size.width; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
853 |
_cocoa_video_data.height = newViewFrame.size.height; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
854 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
855 |
_screen.width = _cocoa_video_data.width; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
856 |
_screen.height = _cocoa_video_data.height; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
857 |
_screen.pitch = _cocoa_video_data.width; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
858 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
859 |
GameSizeChanged(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
860 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
861 |
/* Redraw screen */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
862 |
_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
|
863 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
864 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
865 |
- (void)appDidHide:(NSNotification*)note |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
866 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
867 |
_cocoa_video_data.active = false; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
868 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
869 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
870 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
871 |
- (void)appWillUnhide:(NSNotification*)note |
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 |
QZ_SetPortAlphaOpaque (); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
874 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
875 |
/* save current visible surface */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
876 |
[ self cacheImageInRect:[ _cocoa_video_data.qdview frame ] ]; |
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
879 |
- (void)appDidUnhide:(NSNotification*)note |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
880 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
881 |
/* 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
|
882 |
[ self restoreCachedImage ]; |
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 |
_cocoa_video_data.active = true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
885 |
} |
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 |
- (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
|
889 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
890 |
/* 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
|
891 |
[ [ NSNotificationCenter defaultCenter ] addObserver:self |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
892 |
selector:@selector(appDidHide:) name:NSApplicationDidHideNotification object:NSApp ]; |
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 |
[ [ NSNotificationCenter defaultCenter ] addObserver:self |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
895 |
selector:@selector(appDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
896 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
897 |
[ [ NSNotificationCenter defaultCenter ] addObserver:self |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
898 |
selector:@selector(appWillUnhide:) name:NSApplicationWillUnhideNotification object:NSApp ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
899 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
900 |
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
|
901 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
902 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
903 |
@end |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
904 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
905 |
@implementation OTTD_QuartzWindowDelegate |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
906 |
- (BOOL)windowShouldClose:(id)sender |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
907 |
{ |
4548
6165e12570bf
(svn r6380) -Codechange: unify all ways to quit OTTD.
rubidium
parents:
4536
diff
changeset
|
908 |
HandleExitGameRequest(); |
2736
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 |
return NO; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
911 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
912 |
|
3036 | 913 |
- (void)windowDidBecomeKey:(NSNotification*)aNotification |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
914 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
915 |
_cocoa_video_data.active = true; |
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 |
|
3036 | 918 |
- (void)windowDidResignKey:(NSNotification*)aNotification |
2736
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 |
_cocoa_video_data.active = false; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
921 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
922 |
|
3036 | 923 |
- (void)windowDidBecomeMain:(NSNotification*)aNotification |
2736
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 |
_cocoa_video_data.active = true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
926 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
927 |
|
3036 | 928 |
- (void)windowDidResignMain:(NSNotification*)aNotification |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
929 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
930 |
_cocoa_video_data.active = false; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
931 |
} |
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 |
@end |
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
936 |
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
|
937 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
938 |
uint i; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
939 |
|
3036 | 940 |
switch (_cocoa_video_data.device_bpp) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
941 |
case 32: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
942 |
for (i = start; i < start + count; i++) { |
3036 | 943 |
uint32 clr32 = 0xff000000; |
944 |
clr32 |= (uint32)_cur_palette[i].r << 16; |
|
945 |
clr32 |= (uint32)_cur_palette[i].g << 8; |
|
946 |
clr32 |= (uint32)_cur_palette[i].b; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
947 |
_cocoa_video_data.palette32[i] = clr32; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
948 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
949 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
950 |
case 16: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
951 |
for (i = start; i < start + count; i++) { |
3036 | 952 |
uint16 clr16 = 0x0000; |
953 |
clr16 |= (uint16)((_cur_palette[i].r >> 3) & 0x1f) << 10; |
|
954 |
clr16 |= (uint16)((_cur_palette[i].g >> 3) & 0x1f) << 5; |
|
955 |
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
|
956 |
_cocoa_video_data.palette16[i] = clr16; |
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 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
959 |
} |
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 |
_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
|
962 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
963 |
|
3038
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
964 |
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
|
965 |
{ |
3038
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
966 |
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
|
967 |
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
|
968 |
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
|
969 |
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
|
970 |
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
|
971 |
uint x; |
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
972 |
uint y; |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
973 |
|
3036 | 974 |
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
|
975 |
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
|
976 |
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
|
977 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
978 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
979 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
980 |
|
3038
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
981 |
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
|
982 |
{ |
3038
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
983 |
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
|
984 |
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
|
985 |
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
|
986 |
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
|
987 |
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
|
988 |
uint x; |
976e2aeca1fc
(svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver
bjarni
parents:
3037
diff
changeset
|
989 |
uint y; |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
990 |
|
3036 | 991 |
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
|
992 |
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
|
993 |
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
|
994 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
995 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
996 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
997 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
998 |
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
|
999 |
{ |
3036 | 1000 |
switch (_cocoa_video_data.device_bpp) { |
1001 |
case 32: QZ_WindowBlitIndexedPixelsToView32(left, top, right, bottom); break; |
|
1002 |
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
|
1003 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1004 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1005 |
|
3036 | 1006 |
static bool _resize_icon[] = { |
1007 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, |
|
1008 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, |
|
1009 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, |
|
1010 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, |
|
1011 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, |
|
1012 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, |
|
1013 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, |
|
1014 |
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, |
|
1015 |
0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, |
|
1016 |
0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, |
|
1017 |
0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, |
|
1018 |
0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, |
|
1019 |
0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, |
|
1020 |
0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, |
|
1021 |
0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, |
|
1022 |
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
|
1023 |
}; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1024 |
|
3036 | 1025 |
static void QZ_DrawResizeIcon(void) |
1026 |
{ |
|
1027 |
int xoff = _cocoa_video_data.width - 16; |
|
1028 |
int yoff = _cocoa_video_data.height - 16; |
|
1029 |
int x; |
|
1030 |
int y; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1031 |
|
3036 | 1032 |
for (y = 0; y < 16; y++) { |
1033 |
uint16* trg16 = (uint16*)_cocoa_video_data.realpixels + (yoff + y) * _cocoa_video_data.pitch / 2 + xoff; |
|
1034 |
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
|
1035 |
|
3036 | 1036 |
for (x = 0; x < 16; x++, trg16++, trg32++) { |
1037 |
if (!_resize_icon[y * 16 + x]) continue; |
|
1038 |
||
1039 |
switch (_cocoa_video_data.device_bpp) { |
|
1040 |
case 32: *trg32 = 0xff000000; break; |
|
1041 |
case 16: *trg16 = 0x0000; break; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1042 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1043 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1044 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1045 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1046 |
|
3036 | 1047 |
static void QZ_DrawWindow(void) |
1048 |
{ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1049 |
int i; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1050 |
RgnHandle dirty, temp; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1051 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1052 |
/* Check if we need to do anything */ |
3036 | 1053 |
if (_cocoa_video_data.num_dirty_rects == 0 || |
1054 |
[ _cocoa_video_data.window isMiniaturized ]) { |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1055 |
return; |
3036 | 1056 |
} |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1057 |
|
3036 | 1058 |
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
|
1059 |
_cocoa_video_data.num_dirty_rects = 1; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1060 |
_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
|
1061 |
_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
|
1062 |
_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
|
1063 |
_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
|
1064 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1065 |
|
3036 | 1066 |
dirty = NewRgn(); |
1067 |
temp = NewRgn(); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1068 |
|
3036 | 1069 |
SetEmptyRgn(dirty); |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1070 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1071 |
/* Build the region of dirty rectangles */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1072 |
for (i = 0; i < _cocoa_video_data.num_dirty_rects; i++) { |
3036 | 1073 |
QZ_WindowBlitIndexedPixelsToView( |
1074 |
_cocoa_video_data.dirty_rects[i].left, |
|
1075 |
_cocoa_video_data.dirty_rects[i].top, |
|
1076 |
_cocoa_video_data.dirty_rects[i].right, |
|
1077 |
_cocoa_video_data.dirty_rects[i].bottom |
|
1078 |
); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1079 |
|
3036 | 1080 |
MacSetRectRgn( |
1081 |
temp, |
|
1082 |
_cocoa_video_data.dirty_rects[i].left, |
|
1083 |
_cocoa_video_data.dirty_rects[i].top, |
|
1084 |
_cocoa_video_data.dirty_rects[i].right, |
|
1085 |
_cocoa_video_data.dirty_rects[i].bottom |
|
1086 |
); |
|
1087 |
MacUnionRgn(dirty, temp, dirty); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1088 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1089 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1090 |
QZ_DrawResizeIcon(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1091 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1092 |
/* Flush the dirty region */ |
3036 | 1093 |
QDFlushPortBuffer([ _cocoa_video_data.qdview qdPort ], dirty); |
1094 |
DisposeRgn(dirty); |
|
1095 |
DisposeRgn(temp); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1096 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1097 |
_cocoa_video_data.num_dirty_rects = 0; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1098 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1099 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1100 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1101 |
extern const char _openttd_revision[]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1102 |
|
3036 | 1103 |
static const char* QZ_SetVideoWindowed(uint width, uint height) |
1104 |
{ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1105 |
char caption[50]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1106 |
NSString *nsscaption; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1107 |
unsigned int style; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1108 |
NSRect contentRect; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1109 |
BOOL isCustom = NO; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1110 |
|
3036 | 1111 |
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
|
1112 |
width = _cocoa_video_data.device_width; |
3036 | 1113 |
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
|
1114 |
height = _cocoa_video_data.device_height; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1115 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1116 |
_cocoa_video_data.width = width; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1117 |
_cocoa_video_data.height = height; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1118 |
|
3036 | 1119 |
contentRect = NSMakeRect(0, 0, width, height); |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1120 |
|
3036 | 1121 |
/* Check if we should completely destroy the previous mode |
1122 |
* - If it is fullscreen |
|
1123 |
*/ |
|
1124 |
if (_cocoa_video_data.isset && _cocoa_video_data.fullscreen) |
|
1125 |
QZ_UnsetVideoMode(); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1126 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1127 |
/* Check if we should recreate the window */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1128 |
if (_cocoa_video_data.window == nil) { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1129 |
/* Set the window style */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1130 |
style = NSTitledWindowMask; |
3036 | 1131 |
style |= (NSMiniaturizableWindowMask | NSClosableWindowMask); |
1132 |
style |= NSResizableWindowMask; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1133 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1134 |
/* 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
|
1135 |
_cocoa_video_data.window = [ [ OTTD_QuartzWindow alloc ] |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1136 |
initWithContentRect:contentRect |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1137 |
styleMask:style |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1138 |
backing:NSBackingStoreBuffered |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1139 |
defer:NO ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1140 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1141 |
if (_cocoa_video_data.window == nil) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1142 |
return "Could not create the Cocoa window"; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1143 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1144 |
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
|
1145 |
nsscaption = [ [ NSString alloc ] initWithCString:caption ]; |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1146 |
[ _cocoa_video_data.window setTitle:nsscaption ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1147 |
[ _cocoa_video_data.window setMiniwindowTitle:nsscaption ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1148 |
[ nsscaption release ]; |
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 |
[ _cocoa_video_data.window setAcceptsMouseMovedEvents:YES ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1151 |
[ _cocoa_video_data.window setViewsNeedDisplay:NO ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1152 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1153 |
[ _cocoa_video_data.window setDelegate: [ [ [ OTTD_QuartzWindowDelegate alloc ] init ] autorelease ] ]; |
3036 | 1154 |
} else { |
1155 |
/* 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
|
1156 |
if (!isCustom) { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1157 |
[ _cocoa_video_data.window setContentSize:contentRect.size ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1158 |
[ _cocoa_video_data.qdview setFrameSize:contentRect.size ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1159 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1160 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1161 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1162 |
[ _cocoa_video_data.window center ]; |
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 |
/* 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
|
1165 |
if (_cocoa_video_data.qdview == nil) { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1166 |
_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
|
1167 |
[ _cocoa_video_data.qdview setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1168 |
[ [ _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
|
1169 |
[ _cocoa_video_data.qdview release ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1170 |
[ _cocoa_video_data.window makeKeyAndOrderFront:nil ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1171 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1172 |
|
3036 | 1173 |
LockPortBits([ _cocoa_video_data.qdview qdPort ]); |
1174 |
_cocoa_video_data.realpixels = GetPixBaseAddr(GetPortPixMap([ _cocoa_video_data.qdview qdPort ])); |
|
1175 |
_cocoa_video_data.pitch = GetPixRowBytes(GetPortPixMap([ _cocoa_video_data.qdview qdPort ])); |
|
1176 |
UnlockPortBits([ _cocoa_video_data.qdview qdPort ]); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1177 |
|
3036 | 1178 |
/* _cocoa_video_data.realpixels now points to the window's pixels |
1179 |
* We want it to point to the *view's* pixels |
|
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4548
diff
changeset
|
1180 |
*/ |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1181 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1182 |
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
|
1183 |
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
|
1184 |
|
3036 | 1185 |
_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
|
1186 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1187 |
|
3036 | 1188 |
free(_cocoa_video_data.pixels); |
1189 |
_cocoa_video_data.pixels = (uint8*)malloc(width * height); |
|
1190 |
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
|
1191 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1192 |
_cocoa_video_data.fullscreen = false; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1193 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1194 |
return NULL; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1195 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1196 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1197 |
|
3036 | 1198 |
/****************************************************************************** |
1199 |
* Fullscreen mode * |
|
1200 |
******************************************************************************/ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1201 |
|
3036 | 1202 |
/* Gamma functions to try to hide the flash from a rez switch |
1203 |
* Fade the display from normal to black |
|
1204 |
* Save gamma tables for fade back to normal |
|
1205 |
*/ |
|
3037 | 1206 |
static uint32 QZ_FadeGammaOut(OTTD_QuartzGammaTable* table) |
3036 | 1207 |
{ |
1208 |
CGGammaValue redTable[QZ_GAMMA_TABLE_SIZE]; |
|
1209 |
CGGammaValue greenTable[QZ_GAMMA_TABLE_SIZE]; |
|
1210 |
CGGammaValue blueTable[QZ_GAMMA_TABLE_SIZE]; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1211 |
float percent; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1212 |
int j; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1213 |
unsigned int actual; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1214 |
|
3036 | 1215 |
if (CGGetDisplayTransferByTable( |
1216 |
_cocoa_video_data.display_id, QZ_GAMMA_TABLE_SIZE, |
|
1217 |
table->red, table->green, table->blue, &actual |
|
1218 |
) != CGDisplayNoErr || |
|
1219 |
actual != QZ_GAMMA_TABLE_SIZE) { |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1220 |
return 1; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1221 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1222 |
|
3036 | 1223 |
memcpy(redTable, table->red, sizeof(redTable)); |
1224 |
memcpy(greenTable, table->green, sizeof(greenTable)); |
|
1225 |
memcpy(blueTable, table->blue, sizeof(greenTable)); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1226 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1227 |
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
|
1228 |
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
|
1229 |
redTable[j] = redTable[j] * percent; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1230 |
greenTable[j] = greenTable[j] * percent; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1231 |
blueTable[j] = blueTable[j] * percent; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1232 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1233 |
|
3036 | 1234 |
if (CGSetDisplayTransferByTable( |
1235 |
_cocoa_video_data.display_id, QZ_GAMMA_TABLE_SIZE, |
|
1236 |
redTable, greenTable, blueTable |
|
1237 |
) != CGDisplayNoErr) { |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1238 |
CGDisplayRestoreColorSyncSettings(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1239 |
return 1; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1240 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1241 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1242 |
CSleep(10); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1243 |
} |
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 |
return 0; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1246 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1247 |
|
3036 | 1248 |
/* Fade the display from black to normal |
1249 |
* Restore previously saved gamma values |
|
1250 |
*/ |
|
1251 |
static uint32 QZ_FadeGammaIn(const OTTD_QuartzGammaTable* table) |
|
1252 |
{ |
|
1253 |
CGGammaValue redTable[QZ_GAMMA_TABLE_SIZE]; |
|
1254 |
CGGammaValue greenTable[QZ_GAMMA_TABLE_SIZE]; |
|
1255 |
CGGammaValue blueTable[QZ_GAMMA_TABLE_SIZE]; |
|
1256 |
float percent; |
|
1257 |
int j; |
|
1258 |
||
1259 |
memset(redTable, 0, sizeof(redTable)); |
|
1260 |
memset(greenTable, 0, sizeof(greenTable)); |
|
1261 |
memset(blueTable, 0, sizeof(greenTable)); |
|
1262 |
||
1263 |
for (percent = 0.0; percent <= 1.0; percent += 0.01) { |
|
1264 |
for (j = 0; j < QZ_GAMMA_TABLE_SIZE; j++) { |
|
1265 |
redTable[j] = table->red[j] * percent; |
|
1266 |
greenTable[j] = table->green[j] * percent; |
|
1267 |
blueTable[j] = table->blue[j] * percent; |
|
1268 |
} |
|
1269 |
||
1270 |
if (CGSetDisplayTransferByTable( |
|
1271 |
_cocoa_video_data.display_id, QZ_GAMMA_TABLE_SIZE, |
|
1272 |
redTable, greenTable, blueTable |
|
1273 |
) != CGDisplayNoErr) { |
|
1274 |
CGDisplayRestoreColorSyncSettings(); |
|
1275 |
return 1; |
|
1276 |
} |
|
1277 |
||
1278 |
CSleep(10); |
|
1279 |
} |
|
1280 |
||
1281 |
return 0; |
|
1282 |
} |
|
1283 |
||
1284 |
static const char* QZ_SetVideoFullScreen(int width, int height) |
|
1285 |
{ |
|
1286 |
const char* errstr = "QZ_SetVideoFullScreen error"; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1287 |
int exact_match; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1288 |
CFNumberRef number; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1289 |
int bpp; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1290 |
int gamma_error; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1291 |
OTTD_QuartzGammaTable gamma_table; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1292 |
NSRect screen_rect; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1293 |
CGError error; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1294 |
NSPoint pt; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1295 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1296 |
/* Destroy any previous mode */ |
3036 | 1297 |
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
|
1298 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1299 |
/* See if requested mode exists */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1300 |
_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
|
1301 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1302 |
/* If the mode wasn't an exact match, check if it has the right bpp, and update width and height */ |
3036 | 1303 |
if (!exact_match) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1304 |
number = CFDictionaryGetValue (_cocoa_video_data.mode, kCGDisplayBitsPerPixel); |
3036 | 1305 |
CFNumberGetValue(number, kCFNumberSInt32Type, &bpp); |
1306 |
if (bpp != 8) { |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1307 |
errstr = "Failed to find display resolution"; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1308 |
goto ERR_NO_MATCH; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1309 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1310 |
|
3036 | 1311 |
number = CFDictionaryGetValue(_cocoa_video_data.mode, kCGDisplayWidth); |
1312 |
CFNumberGetValue(number, kCFNumberSInt32Type, &width); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1313 |
|
3036 | 1314 |
number = CFDictionaryGetValue(_cocoa_video_data.mode, kCGDisplayHeight); |
1315 |
CFNumberGetValue(number, kCFNumberSInt32Type, &height); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1316 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1317 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1318 |
/* Fade display to zero gamma */ |
3036 | 1319 |
gamma_error = QZ_FadeGammaOut(&gamma_table); |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1320 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1321 |
/* Put up the blanking window (a window above all other windows) */ |
3036 | 1322 |
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
|
1323 |
|
3036 | 1324 |
if (CGDisplayNoErr != error) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1325 |
errstr = "Failed capturing display"; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1326 |
goto ERR_NO_CAPTURE; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1327 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1328 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1329 |
/* Do the physical switch */ |
3036 | 1330 |
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
|
1331 |
errstr = "Failed switching display resolution"; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1332 |
goto ERR_NO_SWITCH; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1333 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1334 |
|
3036 | 1335 |
_cocoa_video_data.realpixels = (uint8*)CGDisplayBaseAddress(_cocoa_video_data.display_id); |
1336 |
_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
|
1337 |
|
3036 | 1338 |
_cocoa_video_data.width = CGDisplayPixelsWide(_cocoa_video_data.display_id); |
1339 |
_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
|
1340 |
_cocoa_video_data.fullscreen = true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1341 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1342 |
/* Setup double-buffer emulation */ |
3036 | 1343 |
_cocoa_video_data.pixels = (uint8*)malloc(width * height); |
1344 |
if (_cocoa_video_data.pixels == NULL) { |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1345 |
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
|
1346 |
goto ERR_DOUBLEBUF; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1347 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1348 |
|
3036 | 1349 |
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
|
1350 |
errstr = "Not an indexed display mode."; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1351 |
goto ERR_NOT_INDEXED; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1352 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1353 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1354 |
/* If we don't hide menu bar, it will get events and interrupt the program */ |
3036 | 1355 |
HideMenuBar(); |
2736
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 |
/* Fade the display to original gamma */ |
3036 | 1358 |
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
|
1359 |
|
3036 | 1360 |
/* There is a bug in Cocoa where NSScreen doesn't synchronize |
1361 |
* with CGDirectDisplay, so the main screen's frame is wrong. |
|
1362 |
* As a result, coordinate translation produces incorrect results. |
|
1363 |
* We can hack around this bug by setting the screen rect ourselves. |
|
1364 |
* This hack should be removed if/when the bug is fixed. |
|
1365 |
*/ |
|
1366 |
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
|
1367 |
[ [ NSScreen mainScreen ] setFrame:screen_rect ]; |
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 |
/* 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
|
1370 |
_cocoa_video_data.active = true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1371 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1372 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1373 |
pt = [ NSEvent mouseLocation ]; |
3036 | 1374 |
pt.y = CGDisplayPixelsHigh(_cocoa_video_data.display_id) - pt.y; |
1375 |
if (QZ_MouseIsInsideView(&pt)) QZ_HideMouse(); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1376 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1377 |
return NULL; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1378 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1379 |
/* 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
|
1380 |
ERR_NOT_INDEXED: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1381 |
free(_cocoa_video_data.pixels); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1382 |
_cocoa_video_data.pixels = NULL; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1383 |
ERR_DOUBLEBUF: |
3036 | 1384 |
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
|
1385 |
ERR_NO_SWITCH: |
3036 | 1386 |
CGReleaseAllDisplays(); |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1387 |
ERR_NO_CAPTURE: |
3036 | 1388 |
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
|
1389 |
ERR_NO_MATCH: |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1390 |
return errstr; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1391 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1392 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1393 |
|
3036 | 1394 |
static void QZ_UpdateFullscreenPalette(uint first_color, uint num_colors) |
1395 |
{ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1396 |
CGTableCount index; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1397 |
CGDeviceColor color; |
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 |
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
|
1400 |
/* 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
|
1401 |
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
|
1402 |
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
|
1403 |
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
|
1404 |
|
3036 | 1405 |
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
|
1406 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1407 |
|
3036 | 1408 |
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
|
1409 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1410 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1411 |
/* 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
|
1412 |
static void QZ_WaitForVerticalBlank(void) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1413 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1414 |
/* 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
|
1415 |
double refreshRate; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1416 |
double linesPerSecond; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1417 |
double target; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1418 |
double position; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1419 |
double adjustment; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1420 |
CFNumberRef refreshRateCFNumber; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1421 |
|
3036 | 1422 |
refreshRateCFNumber = CFDictionaryGetValue(_cocoa_video_data.mode, kCGDisplayRefreshRate); |
1423 |
if (refreshRateCFNumber == NULL) return; |
|
1424 |
||
1425 |
if (CFNumberGetValue(refreshRateCFNumber, kCFNumberDoubleType, &refreshRate) == 0) |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1426 |
return; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1427 |
|
3036 | 1428 |
if (refreshRate == 0) return; |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1429 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1430 |
linesPerSecond = refreshRate * _cocoa_video_data.height; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1431 |
target = _cocoa_video_data.height; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1432 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1433 |
/* Figure out the first delay so we start off about right */ |
3036 | 1434 |
position = CGDisplayBeamPosition(_cocoa_video_data.display_id); |
1435 |
if (position > target) position = 0; |
|
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 |
adjustment = (target - position) / linesPerSecond; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1438 |
|
3036 | 1439 |
CSleep((uint32)(adjustment * 1000)); |
2736
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 |
|
4475 | 1442 |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1443 |
static void QZ_DrawScreen(void) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1444 |
{ |
4475 | 1445 |
const uint8* src = _cocoa_video_data.pixels; |
1446 |
uint8* dst = (uint8*)_cocoa_video_data.realpixels; |
|
1447 |
uint pitch = _cocoa_video_data.pitch; |
|
1448 |
uint width = _cocoa_video_data.width; |
|
1449 |
uint num_dirty = _cocoa_video_data.num_dirty_rects; |
|
3327
2493a2b8f4eb
(svn r4099) -Codechange: [OSX] the cocoa video driver speedup of around 1000% now also applies to Intel macs
bjarni
parents:
3317
diff
changeset
|
1450 |
uint i; |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1451 |
|
3327
2493a2b8f4eb
(svn r4099) -Codechange: [OSX] the cocoa video driver speedup of around 1000% now also applies to Intel macs
bjarni
parents:
3317
diff
changeset
|
1452 |
/* Check if we need to do anything */ |
4475 | 1453 |
if (num_dirty == 0) return; |
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
|
1454 |
|
4475 | 1455 |
if (num_dirty >= MAX_DIRTY_RECTS) { |
1456 |
num_dirty = 1; |
|
1457 |
_cocoa_video_data.dirty_rects[0].left = 0; |
|
1458 |
_cocoa_video_data.dirty_rects[0].top = 0; |
|
1459 |
_cocoa_video_data.dirty_rects[0].right = _cocoa_video_data.width; |
|
3327
2493a2b8f4eb
(svn r4099) -Codechange: [OSX] the cocoa video driver speedup of around 1000% now also applies to Intel macs
bjarni
parents:
3317
diff
changeset
|
1460 |
_cocoa_video_data.dirty_rects[0].bottom = _cocoa_video_data.height; |
2493a2b8f4eb
(svn r4099) -Codechange: [OSX] the cocoa video driver speedup of around 1000% now also applies to Intel macs
bjarni
parents:
3317
diff
changeset
|
1461 |
} |
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
|
1462 |
|
3327
2493a2b8f4eb
(svn r4099) -Codechange: [OSX] the cocoa video driver speedup of around 1000% now also applies to Intel macs
bjarni
parents:
3317
diff
changeset
|
1463 |
QZ_WaitForVerticalBlank(); |
2493a2b8f4eb
(svn r4099) -Codechange: [OSX] the cocoa video driver speedup of around 1000% now also applies to Intel macs
bjarni
parents:
3317
diff
changeset
|
1464 |
/* Build the region of dirty rectangles */ |
4475 | 1465 |
for (i = 0; i < num_dirty; i++) { |
1466 |
uint y = _cocoa_video_data.dirty_rects[i].top; |
|
1467 |
uint left = _cocoa_video_data.dirty_rects[i].left; |
|
1468 |
uint length = _cocoa_video_data.dirty_rects[i].right - left; |
|
1469 |
uint bottom = _cocoa_video_data.dirty_rects[i].bottom; |
|
3327
2493a2b8f4eb
(svn r4099) -Codechange: [OSX] the cocoa video driver speedup of around 1000% now also applies to Intel macs
bjarni
parents:
3317
diff
changeset
|
1470 |
|
4475 | 1471 |
for (; y < bottom; y++) { |
1472 |
memcpy(dst + y * pitch + left, src + y * width + left, length); |
|
1473 |
} |
|
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
|
1474 |
} |
3327
2493a2b8f4eb
(svn r4099) -Codechange: [OSX] the cocoa video driver speedup of around 1000% now also applies to Intel macs
bjarni
parents:
3317
diff
changeset
|
1475 |
|
2493a2b8f4eb
(svn r4099) -Codechange: [OSX] the cocoa video driver speedup of around 1000% now also applies to Intel macs
bjarni
parents:
3317
diff
changeset
|
1476 |
_cocoa_video_data.num_dirty_rects = 0; |
4475 | 1477 |
} |
3327
2493a2b8f4eb
(svn r4099) -Codechange: [OSX] the cocoa video driver speedup of around 1000% now also applies to Intel macs
bjarni
parents:
3317
diff
changeset
|
1478 |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1479 |
|
3036 | 1480 |
static int QZ_ListFullscreenModes(OTTDPoint* mode_list, int max_modes) |
1481 |
{ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1482 |
CFIndex num_modes; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1483 |
CFIndex i; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1484 |
int list_size = 0; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1485 |
|
3036 | 1486 |
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
|
1487 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1488 |
/* 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
|
1489 |
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
|
1490 |
CFDictionaryRef onemode; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1491 |
CFNumberRef number; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1492 |
int bpp; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1493 |
int intvalue; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1494 |
bool hasMode; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1495 |
uint16 width, height; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1496 |
|
3036 | 1497 |
onemode = CFArrayGetValueAtIndex(_cocoa_video_data.mode_list, i); |
1498 |
number = CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1499 |
CFNumberGetValue (number, kCFNumberSInt32Type, &bpp); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1500 |
|
3036 | 1501 |
if (bpp != 8) continue; |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1502 |
|
3036 | 1503 |
number = CFDictionaryGetValue(onemode, kCGDisplayWidth); |
1504 |
CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); |
|
1505 |
width = (uint16)intvalue; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1506 |
|
3036 | 1507 |
number = CFDictionaryGetValue(onemode, kCGDisplayHeight); |
1508 |
CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); |
|
1509 |
height = (uint16)intvalue; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1510 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1511 |
/* 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
|
1512 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1513 |
int i; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1514 |
hasMode = false; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1515 |
for (i = 0; i < list_size; i++) { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1516 |
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
|
1517 |
hasMode = true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1518 |
break; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1519 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1520 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1521 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1522 |
|
3036 | 1523 |
if (hasMode) continue; |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1524 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1525 |
/* Add mode to the list */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1526 |
mode_list[list_size].x = width; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1527 |
mode_list[list_size].y = height; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1528 |
list_size++; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1529 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1530 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1531 |
/* Sort list smallest to largest */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1532 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1533 |
int i, j; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1534 |
for (i = 0; i < list_size; i++) { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1535 |
for (j = 0; j < list_size-1; j++) { |
3036 | 1536 |
if (mode_list[j].x > mode_list[j + 1].x || ( |
1537 |
mode_list[j].x == mode_list[j + 1].x && |
|
1538 |
mode_list[j].y > mode_list[j + 1].y |
|
1539 |
)) { |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1540 |
uint tmpw = mode_list[j].x; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1541 |
uint tmph = mode_list[j].y; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1542 |
|
3036 | 1543 |
mode_list[j].x = mode_list[j + 1].x; |
1544 |
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
|
1545 |
|
3036 | 1546 |
mode_list[j + 1].x = tmpw; |
1547 |
mode_list[j + 1].y = tmph; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1548 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1549 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1550 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1551 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1552 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1553 |
return list_size; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1554 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1555 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1556 |
|
3036 | 1557 |
/****************************************************************************** |
1558 |
* Windowed and fullscreen common code * |
|
1559 |
******************************************************************************/ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1560 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1561 |
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
|
1562 |
{ |
3036 | 1563 |
if (_cocoa_video_data.fullscreen) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1564 |
QZ_UpdateFullscreenPalette(start, count); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1565 |
} else { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1566 |
QZ_UpdateWindowPalette(start, count); |
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1570 |
static void QZ_InitPalette(void) |
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 |
QZ_UpdatePalette(0, 256); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1573 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1574 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1575 |
static void QZ_Draw(void) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1576 |
{ |
3036 | 1577 |
if (_cocoa_video_data.fullscreen) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1578 |
QZ_DrawScreen(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1579 |
} else { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1580 |
QZ_DrawWindow(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1581 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1582 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1583 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1584 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1585 |
static const OTTDPoint _default_resolutions[] = { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1586 |
{ 640, 480}, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1587 |
{ 800, 600}, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1588 |
{1024, 768}, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1589 |
{1152, 864}, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1590 |
{1280, 800}, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1591 |
{1280, 960}, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1592 |
{1280, 1024}, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1593 |
{1400, 1050}, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1594 |
{1600, 1200}, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1595 |
{1680, 1050}, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1596 |
{1920, 1200} |
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 |
static void QZ_UpdateVideoModes(void) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1600 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1601 |
uint i, j, count; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1602 |
OTTDPoint modes[32]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1603 |
const OTTDPoint *current_modes; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1604 |
|
3036 | 1605 |
if (_cocoa_video_data.fullscreen) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1606 |
count = QZ_ListFullscreenModes(modes, 32); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1607 |
current_modes = modes; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1608 |
} else { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1609 |
count = lengthof(_default_resolutions); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1610 |
current_modes = _default_resolutions; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1611 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1612 |
|
3036 | 1613 |
for (i = 0, j = 0; j < lengthof(_resolutions) && i < count; i++) { |
1614 |
if (_cocoa_video_data.fullscreen || ( |
|
3316
66b80af7608f
(svn r4082) -Fix: [OSX] FS#80 Crash when switching from windowed to fullscreen
bjarni
parents:
3261
diff
changeset
|
1615 |
(uint)current_modes[i].x < _cocoa_video_data.device_width && |
66b80af7608f
(svn r4082) -Fix: [OSX] FS#80 Crash when switching from windowed to fullscreen
bjarni
parents:
3261
diff
changeset
|
1616 |
(uint)current_modes[i].y < _cocoa_video_data.device_height) |
3036 | 1617 |
) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1618 |
_resolutions[j][0] = current_modes[i].x; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1619 |
_resolutions[j][1] = current_modes[i].y; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1620 |
j++; |
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 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1623 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1624 |
_num_resolutions = j; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1625 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1626 |
|
3036 | 1627 |
static void QZ_UnsetVideoMode(void) |
1628 |
{ |
|
1629 |
if (_cocoa_video_data.fullscreen) { |
|
1630 |
/* Release fullscreen resources */ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1631 |
OTTD_QuartzGammaTable gamma_table; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1632 |
int gamma_error; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1633 |
NSRect screen_rect; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1634 |
|
3036 | 1635 |
gamma_error = QZ_FadeGammaOut(&gamma_table); |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1636 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1637 |
/* Restore original screen resolution/bpp */ |
3036 | 1638 |
CGDisplaySwitchToMode(_cocoa_video_data.display_id, _cocoa_video_data.save_mode); |
1639 |
CGReleaseAllDisplays(); |
|
1640 |
ShowMenuBar(); |
|
1641 |
/* Reset the main screen's rectangle |
|
1642 |
* See comment in QZ_SetVideoFullscreen for why we do this |
|
1643 |
*/ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1644 |
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
|
1645 |
[ [ NSScreen mainScreen ] setFrame:screen_rect ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1646 |
|
3036 | 1647 |
if (!gamma_error) QZ_FadeGammaIn(&gamma_table); |
1648 |
} else { |
|
1649 |
/* Release window mode resources */ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1650 |
[ _cocoa_video_data.window close ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1651 |
_cocoa_video_data.window = nil; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1652 |
_cocoa_video_data.qdview = nil; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1653 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1654 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1655 |
free(_cocoa_video_data.pixels); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1656 |
_cocoa_video_data.pixels = NULL; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1657 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1658 |
/* Signal successful teardown */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1659 |
_cocoa_video_data.isset = false; |
3317
6aa52b41b084
(svn r4083) -Feature: [OSX] Ported r4075 (Undraw the mouse when it leaves the window and Draw it again when it enters).
egladil
parents:
3316
diff
changeset
|
1660 |
|
6aa52b41b084
(svn r4083) -Feature: [OSX] Ported r4075 (Undraw the mouse when it leaves the window and Draw it again when it enters).
egladil
parents:
3316
diff
changeset
|
1661 |
QZ_ShowMouse(); |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1662 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1663 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1664 |
|
3036 | 1665 |
static const char* QZ_SetVideoMode(uint width, uint height, bool fullscreen) |
1666 |
{ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1667 |
const char *ret; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1668 |
|
3036 | 1669 |
_cocoa_video_data.issetting = true; |
1670 |
if (fullscreen) { |
|
1671 |
/* Setup full screen video */ |
|
1672 |
ret = QZ_SetVideoFullScreen(width, height); |
|
1673 |
} else { |
|
1674 |
/* Setup windowed video */ |
|
1675 |
ret = QZ_SetVideoWindowed(width, height); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1676 |
} |
3036 | 1677 |
_cocoa_video_data.issetting = false; |
1678 |
if (ret != NULL) return ret; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1679 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1680 |
/* Signal successful completion (used internally) */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1681 |
_cocoa_video_data.isset = true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1682 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1683 |
/* 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
|
1684 |
_screen.width = _cocoa_video_data.width; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1685 |
_screen.height = _cocoa_video_data.height; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1686 |
_screen.pitch = _cocoa_video_data.width; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1687 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1688 |
QZ_UpdateVideoModes(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1689 |
GameSizeChanged(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1690 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1691 |
QZ_InitPalette(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1692 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1693 |
return NULL; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1694 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1695 |
|
3036 | 1696 |
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
|
1697 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1698 |
bool wasset = _cocoa_video_data.isset; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1699 |
uint32 oldwidth = _cocoa_video_data.width; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1700 |
uint32 oldheight = _cocoa_video_data.height; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1701 |
bool oldfullscreen = _cocoa_video_data.fullscreen; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1702 |
const char *ret; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1703 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1704 |
ret = QZ_SetVideoMode(width, height, fullscreen); |
3036 | 1705 |
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
|
1706 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1707 |
return ret; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1708 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1709 |
|
3036 | 1710 |
static void QZ_VideoInit(void) |
1711 |
{ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1712 |
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
|
1713 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1714 |
/* 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
|
1715 |
_cocoa_video_data.display_id = kCGDirectMainDisplay; |
3036 | 1716 |
_cocoa_video_data.save_mode = CGDisplayCurrentMode(_cocoa_video_data.display_id); |
1717 |
_cocoa_video_data.mode_list = CGDisplayAvailableModes(_cocoa_video_data.display_id); |
|
1718 |
_cocoa_video_data.palette = CGPaletteCreateDefaultColorPalette(); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1719 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1720 |
/* 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
|
1721 |
/* Maybe this should be moved to QZ_SetVideoMode, in case this is changed after startup */ |
3036 | 1722 |
CFNumberGetValue( |
1723 |
CFDictionaryGetValue(_cocoa_video_data.save_mode, kCGDisplayBitsPerPixel), |
|
1724 |
kCFNumberSInt32Type, &_cocoa_video_data.device_bpp |
|
1725 |
); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1726 |
|
3036 | 1727 |
CFNumberGetValue( |
1728 |
CFDictionaryGetValue(_cocoa_video_data.save_mode, kCGDisplayWidth), |
|
1729 |
kCFNumberSInt32Type, &_cocoa_video_data.device_width |
|
1730 |
); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1731 |
|
3036 | 1732 |
CFNumberGetValue( |
1733 |
CFDictionaryGetValue(_cocoa_video_data.save_mode, kCGDisplayHeight), |
|
1734 |
kCFNumberSInt32Type, &_cocoa_video_data.device_height |
|
1735 |
); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1736 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1737 |
_cocoa_video_data.cursor_visible = true; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1738 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1739 |
/* register for sleep notifications so wake from sleep generates SDL_VIDEOEXPOSE */ |
3036 | 1740 |
// QZ_RegisterForSleepNotifications(); |
2736
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1743 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1744 |
/* Convert local coordinate to window server (CoreGraphics) coordinate */ |
3036 | 1745 |
static CGPoint QZ_PrivateLocalToCG(NSPoint* p) |
1746 |
{ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1747 |
CGPoint cgp; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1748 |
|
3036 | 1749 |
if (!_cocoa_video_data.fullscreen) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1750 |
*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
|
1751 |
*p = [ _cocoa_video_data.window convertBaseToScreen:*p ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1752 |
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
|
1753 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1754 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1755 |
cgp.x = p->x; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1756 |
cgp.y = p->y; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1757 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1758 |
return cgp; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1759 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1760 |
|
3036 | 1761 |
static void QZ_WarpCursor(int x, int y) |
1762 |
{ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1763 |
NSPoint p; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1764 |
CGPoint cgp; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1765 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1766 |
/* Only allow warping when in foreground */ |
3036 | 1767 |
if (![ NSApp isActive ]) return; |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1768 |
|
3036 | 1769 |
p = NSMakePoint(x, y); |
1770 |
cgp = QZ_PrivateLocalToCG(&p); |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1771 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1772 |
/* this is the magic call that fixes cursor "freezing" after warp */ |
3036 | 1773 |
CGSetLocalEventsSuppressionInterval(0.0); |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1774 |
/* Do the actual warp */ |
3036 | 1775 |
CGWarpMouseCursorPosition(cgp); |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1776 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1777 |
/* Generate the mouse moved event */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1778 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1779 |
|
3036 | 1780 |
static void QZ_ShowMouse(void) |
1781 |
{ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1782 |
if (!_cocoa_video_data.cursor_visible) { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1783 |
[ NSCursor unhide ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1784 |
_cocoa_video_data.cursor_visible = true; |
3317
6aa52b41b084
(svn r4083) -Feature: [OSX] Ported r4075 (Undraw the mouse when it leaves the window and Draw it again when it enters).
egladil
parents:
3316
diff
changeset
|
1785 |
|
6aa52b41b084
(svn r4083) -Feature: [OSX] Ported r4075 (Undraw the mouse when it leaves the window and Draw it again when it enters).
egladil
parents:
3316
diff
changeset
|
1786 |
// Hide the openttd cursor when leaving the window |
6aa52b41b084
(svn r4083) -Feature: [OSX] Ported r4075 (Undraw the mouse when it leaves the window and Draw it again when it enters).
egladil
parents:
3316
diff
changeset
|
1787 |
if (_cocoa_video_data.isset) |
6aa52b41b084
(svn r4083) -Feature: [OSX] Ported r4075 (Undraw the mouse when it leaves the window and Draw it again when it enters).
egladil
parents:
3316
diff
changeset
|
1788 |
UndrawMouseCursor(); |
6aa52b41b084
(svn r4083) -Feature: [OSX] Ported r4075 (Undraw the mouse when it leaves the window and Draw it again when it enters).
egladil
parents:
3316
diff
changeset
|
1789 |
_cursor.in_window = false; |
2736
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 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1792 |
|
3036 | 1793 |
static void QZ_HideMouse(void) |
1794 |
{ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1795 |
if (_cocoa_video_data.cursor_visible) { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1796 |
#ifndef _DEBUG |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1797 |
[ NSCursor hide ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1798 |
#endif |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1799 |
_cocoa_video_data.cursor_visible = false; |
3317
6aa52b41b084
(svn r4083) -Feature: [OSX] Ported r4075 (Undraw the mouse when it leaves the window and Draw it again when it enters).
egladil
parents:
3316
diff
changeset
|
1800 |
|
6aa52b41b084
(svn r4083) -Feature: [OSX] Ported r4075 (Undraw the mouse when it leaves the window and Draw it again when it enters).
egladil
parents:
3316
diff
changeset
|
1801 |
// Show the openttd cursor again |
6aa52b41b084
(svn r4083) -Feature: [OSX] Ported r4075 (Undraw the mouse when it leaves the window and Draw it again when it enters).
egladil
parents:
3316
diff
changeset
|
1802 |
_cursor.in_window = true; |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1803 |
} |
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1806 |
|
3036 | 1807 |
/****************************************************************************** |
1808 |
* OS X application creation * |
|
1809 |
******************************************************************************/ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1810 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1811 |
/* 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
|
1812 |
@implementation OTTDMain |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1813 |
/* Called when the internal event loop has just started running */ |
3036 | 1814 |
- (void) applicationDidFinishLaunching: (NSNotification*) note |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1815 |
{ |
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1816 |
/* Hand off to main application code */ |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1817 |
QZ_GameLoop(); |
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 |
/* We're done, thank you for playing */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1820 |
[ NSApp stop:_ottd_main ]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1821 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1822 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1823 |
/* Display the in game quit confirmation dialog */ |
3036 | 1824 |
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender |
2736
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 |
|
4550
089509518963
(svn r6385) -Fix (r6380): one instance of QZ_AskQuit was left out in the conversion to HandleExitGameRequest.
rubidium
parents:
4549
diff
changeset
|
1827 |
HandleExitGameRequest(); |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1828 |
|
4434
a08cb4b5c179
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4300
diff
changeset
|
1829 |
return NSTerminateCancel; // NSTerminateLater ? |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1830 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1831 |
@end |
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 |
static void setApplicationMenu(void) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1834 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1835 |
/* warning: this code is very odd */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1836 |
NSMenu *appleMenu; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1837 |
NSMenuItem *menuItem; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1838 |
NSString *title; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1839 |
NSString *appName; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1840 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1841 |
appName = @"OTTD"; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1842 |
appleMenu = [[NSMenu alloc] initWithTitle:appName]; |
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 |
/* Add menu items */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1845 |
title = [@"About " stringByAppendingString:appName]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1846 |
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1847 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1848 |
[appleMenu addItem:[NSMenuItem separatorItem]]; |
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 |
title = [@"Hide " stringByAppendingString:appName]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1851 |
[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
|
1852 |
|
3036 | 1853 |
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
|
1854 |
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1855 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1856 |
[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
|
1857 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1858 |
[appleMenu addItem:[NSMenuItem separatorItem]]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1859 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1860 |
title = [@"Quit " stringByAppendingString:appName]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1861 |
[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
|
1862 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1863 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1864 |
/* Put menu into the menubar */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1865 |
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1866 |
[menuItem setSubmenu:appleMenu]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1867 |
[[NSApp mainMenu] addItem:menuItem]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1868 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1869 |
/* 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
|
1870 |
[NSApp setAppleMenu:appleMenu]; |
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 |
/* 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
|
1873 |
[appleMenu release]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1874 |
[menuItem release]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1875 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1876 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1877 |
/* Create a window menu */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1878 |
static void setupWindowMenu(void) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1879 |
{ |
3036 | 1880 |
NSMenu* windowMenu; |
1881 |
NSMenuItem* windowMenuItem; |
|
1882 |
NSMenuItem* menuItem; |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1883 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1884 |
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1885 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1886 |
/* "Minimize" item */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1887 |
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
|
1888 |
[windowMenu addItem:menuItem]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1889 |
[menuItem release]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1890 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1891 |
/* Put menu into the menubar */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1892 |
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
|
1893 |
[windowMenuItem setSubmenu:windowMenu]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1894 |
[[NSApp mainMenu] addItem:windowMenuItem]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1895 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1896 |
/* 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
|
1897 |
[NSApp setWindowsMenu:windowMenu]; |
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 |
/* 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
|
1900 |
[windowMenu release]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1901 |
[windowMenuItem release]; |
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1904 |
static void setupApplication(void) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1905 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1906 |
CPSProcessSerNum PSN; |
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 |
/* Ensure the application object is initialised */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1909 |
[NSApplication sharedApplication]; |
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 |
/* Tell the dock about us */ |
3036 | 1912 |
if (!CPSGetCurrentProcess(&PSN) && |
1913 |
!CPSEnableForegroundOperation(&PSN, 0x03, 0x3C, 0x2C, 0x1103) && |
|
1914 |
!CPSSetFrontProcess(&PSN)) { |
|
1915 |
[NSApplication sharedApplication]; |
|
1916 |
} |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1917 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1918 |
/* Set up the menubar */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1919 |
[NSApp setMainMenu:[[NSMenu alloc] init]]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1920 |
setApplicationMenu(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1921 |
setupWindowMenu(); |
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 |
/* 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
|
1924 |
_ottd_main = [[OTTDMain alloc] init]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1925 |
[NSApp setDelegate:_ottd_main]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1926 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1927 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1928 |
|
3036 | 1929 |
/****************************************************************************** |
1930 |
* Video driver interface * |
|
1931 |
******************************************************************************/ |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1932 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1933 |
static void CocoaVideoStop(void) |
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 |
DEBUG(driver, 1)("cocoa_v: CocoaVideoStop"); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1936 |
|
3036 | 1937 |
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
|
1938 |
|
3036 | 1939 |
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
|
1940 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1941 |
[_ottd_main release]; |
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1942 |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1943 |
_cocoa_video_started = false; |
2736
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1946 |
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
|
1947 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1948 |
const char *ret; |
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 |
DEBUG(driver, 1)("cocoa_v: CocoaVideoStart"); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1951 |
|
3036 | 1952 |
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
|
1953 |
_cocoa_video_started = true; |
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1954 |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1955 |
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
|
1956 |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1957 |
setupApplication(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1958 |
|
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
1959 |
/* Don't create a window or enter fullscreen if we're just going to show a dialog. */ |
3036 | 1960 |
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
|
1961 |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1962 |
QZ_VideoInit(); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1963 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1964 |
ret = QZ_SetVideoMode(_cur_resolution[0], _cur_resolution[1], _fullscreen); |
3036 | 1965 |
if (ret != NULL) CocoaVideoStop(); |
2736
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 |
return ret; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1968 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1969 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1970 |
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
|
1971 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1972 |
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
|
1973 |
_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
|
1974 |
_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
|
1975 |
_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
|
1976 |
_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
|
1977 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1978 |
_cocoa_video_data.num_dirty_rects++; |
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1981 |
static void CocoaVideoMainLoop(void) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1982 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1983 |
DEBUG(driver, 1)("cocoa_v: CocoaVideoMainLoop"); |
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 |
/* Start the main event loop */ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1986 |
[NSApp run]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1987 |
} |
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 |
static bool CocoaVideoChangeRes(int w, int h) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1990 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1991 |
const char *ret; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1992 |
DEBUG(driver, 1)("cocoa_v: CocoaVideoChangeRes"); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1993 |
|
3036 | 1994 |
ret = QZ_SetVideoModeAndRestoreOnFailure((uint)w, (uint)h, _cocoa_video_data.fullscreen); |
1995 |
if (ret != NULL) { |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1996 |
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
|
1997 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1998 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
1999 |
return ret == NULL; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2000 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2001 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2002 |
static void CocoaVideoFullScreen(bool full_screen) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2003 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2004 |
const char *ret; |
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 |
DEBUG(driver, 1)("cocoa_v: CocoaVideoFullScreen"); |
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 |
ret = QZ_SetVideoModeAndRestoreOnFailure(_cocoa_video_data.width, _cocoa_video_data.height, full_screen); |
3036 | 2009 |
if (ret != NULL) { |
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2010 |
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
|
2011 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2012 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2013 |
_fullscreen = _cocoa_video_data.fullscreen; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2014 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2015 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2016 |
const HalVideoDriver _cocoa_video_driver = { |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2017 |
CocoaVideoStart, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2018 |
CocoaVideoStop, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2019 |
CocoaVideoMakeDirty, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2020 |
CocoaVideoMainLoop, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2021 |
CocoaVideoChangeRes, |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2022 |
CocoaVideoFullScreen, |
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 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2025 |
|
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2026 |
/* This is needed since sometimes assert is called before the videodriver is initialized */ |
3036 | 2027 |
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
|
2028 |
{ |
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2029 |
bool wasstarted; |
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2030 |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2031 |
_cocoa_video_dialog = true; |
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2032 |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2033 |
wasstarted = _cocoa_video_started; |
3036 | 2034 |
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
|
2035 |
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
|
2036 |
return; |
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2037 |
} |
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2038 |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2039 |
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
|
2040 |
|
3036 | 2041 |
if (!wasstarted) CocoaVideoStop(); |
2827
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2042 |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2043 |
_cocoa_video_dialog = false; |
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2044 |
} |
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2045 |
|
12c9eda7edcd
(svn r3375) -Add: [ FS#29 ] show an error dialog for OSX cocoa driver (egladil)
truelight
parents:
2743
diff
changeset
|
2046 |
|
2736
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2047 |
/* 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
|
2048 |
void cocoaSetWorkingDirectory(void) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2049 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2050 |
char parentdir[MAXPATHLEN]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2051 |
int chdir_ret; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2052 |
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2053 |
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); |
3036 | 2054 |
if (CFURLGetFileSystemRepresentation(url2, true, (unsigned char*)parentdir, MAXPATHLEN)) { |
2055 |
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
|
2056 |
assert(chdir_ret == 0); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2057 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2058 |
CFRelease(url); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2059 |
CFRelease(url2); |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2060 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2061 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2062 |
/* 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
|
2063 |
* 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
|
2064 |
*/ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2065 |
void cocoaSetupAutoreleasePool(void) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2066 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2067 |
_ottd_autorelease_pool = [[NSAutoreleasePool alloc] init]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2068 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2069 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2070 |
void cocoaReleaseAutoreleasePool(void) |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2071 |
{ |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2072 |
[_ottd_autorelease_pool release]; |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2073 |
} |
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2074 |
|
3d6487cbbb69
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents:
diff
changeset
|
2075 |
#endif /* WITH_COCOA */ |