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