OpenTTD Source  12.1
cocoa_wnd.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef COCOA_WND_H
11 #define COCOA_WND_H
12 
13 #import <Cocoa/Cocoa.h>
14 #include "toolbar_gui.h"
15 #include "table/sprites.h"
16 
17 class VideoDriver_Cocoa;
18 
19 /* Right Mouse Button Emulation enum */
20 enum RightMouseButtonEmulationState {
21  RMBE_COMMAND = 0,
22  RMBE_CONTROL = 1,
23  RMBE_OFF = 2,
24 };
25 
26 extern NSString *OTTDMainLaunchGameEngine;
27 
30 + (NSCursor *) clearCocoaCursor;
31 @end
32 
33 #ifdef HAVE_OSX_1015_SDK
34 /* 9 items can be displayed on the touch bar when using default buttons. */
35 static NSArray *touchBarButtonIdentifiers = @[
36  @"openttd.pause",
37  @"openttd.fastforward",
38  @"openttd.zoom_in",
39  @"openttd.zoom_out",
40  @"openttd.build_rail",
41  @"openttd.build_road",
42  @"openttd.build_tram",
43  @"openttd.build_docks",
44  @"openttd.build_airport",
45  NSTouchBarItemIdentifierOtherItemsProxy
46 ];
47 
48 static NSDictionary *touchBarButtonSprites = @{
49  @"openttd.pause": [NSNumber numberWithInt:SPR_IMG_PAUSE],
50  @"openttd.fastforward": [NSNumber numberWithInt:SPR_IMG_FASTFORWARD],
51  @"openttd.zoom_in": [NSNumber numberWithInt:SPR_IMG_ZOOMIN],
52  @"openttd.zoom_out": [NSNumber numberWithInt:SPR_IMG_ZOOMOUT],
53  @"openttd.build_rail": [NSNumber numberWithInt:SPR_IMG_BUILDRAIL],
54  @"openttd.build_road": [NSNumber numberWithInt:SPR_IMG_BUILDROAD],
55  @"openttd.build_tram": [NSNumber numberWithInt:SPR_IMG_BUILDTRAMS],
56  @"openttd.build_docks": [NSNumber numberWithInt:SPR_IMG_BUILDWATER],
57  @"openttd.build_airport": [NSNumber numberWithInt:SPR_IMG_BUILDAIR],
58 };
59 
60 static NSDictionary *touchBarButtonActions = @{
61  @"openttd.pause": [NSNumber numberWithInt:MTHK_PAUSE],
62  @"openttd.fastforward": [NSNumber numberWithInt:MTHK_FASTFORWARD],
63  @"openttd.zoom_in": [NSNumber numberWithInt:MTHK_ZOOM_IN],
64  @"openttd.zoom_out": [NSNumber numberWithInt:MTHK_ZOOM_OUT],
65  @"openttd.build_rail": [NSNumber numberWithInt:MTHK_BUILD_RAIL],
66  @"openttd.build_road": [NSNumber numberWithInt:MTHK_BUILD_ROAD],
67  @"openttd.build_tram": [NSNumber numberWithInt:MTHK_BUILD_TRAM],
68  @"openttd.build_docks": [NSNumber numberWithInt:MTHK_BUILD_DOCKS],
69  @"openttd.build_airport": [NSNumber numberWithInt:MTHK_BUILD_AIRPORT],
70 };
71 
72 static NSDictionary *touchBarFallbackText = @{
73  @"openttd.pause": @"Pause",
74  @"openttd.fastforward": @"Fast Forward",
75  @"openttd.zoom_in": @"Zoom In",
76  @"openttd.zoom_out": @"Zoom Out",
77  @"openttd.build_rail": @"Rail",
78  @"openttd.build_road": @"Road",
79  @"openttd.build_tram": @"Tram",
80  @"openttd.build_docks": @"Docks",
81  @"openttd.build_airport": @"Airport",
82 };
83 #endif
84 
86 #ifdef HAVE_OSX_1015_SDK
87 @interface OTTD_CocoaWindow : NSWindow <NSTouchBarDelegate>
88 @property (strong) NSSet *touchbarItems;
89 - (NSImage*)generateImage:(int)spriteId;
90 #else
91 @interface OTTD_CocoaWindow : NSWindow
92 #endif
93 
94 - (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag driver:(VideoDriver_Cocoa *)drv;
95 
96 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
97 @end
98 
100 @interface OTTD_CocoaView : NSView <NSTextInputClient>
101 - (NSRect)getRealRect:(NSRect)rect;
102 - (NSRect)getVirtualRect:(NSRect)rect;
103 - (CGFloat)getContentsScale;
104 - (NSPoint)mousePositionFromEvent:(NSEvent *)e;
105 @end
106 
108 @interface OTTD_CocoaWindowDelegate : NSObject <NSWindowDelegate>
109 - (instancetype)initWithDriver:(VideoDriver_Cocoa *)drv;
110 
111 - (BOOL)windowShouldClose:(id)sender;
112 - (void)windowDidEnterFullScreen:(NSNotification *)aNotification;
113 - (void)windowDidChangeBackingProperties:(NSNotification *)notification;
114 - (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions;
115 @end
116 
117 
118 extern bool _allow_hidpi_window;
119 
120 bool CocoaSetupApplication();
121 void CocoaExitApplication();
122 
123 #endif /* COCOA_WND_H */
toolbar_gui.h
OTTD_CocoaWindowDelegate
Delegate for our NSWindow to send ask for quit on close.
Definition: cocoa_wnd.h:108
sprites.h
OTTD_CocoaView
Subclass of NSView to support mouse awareness and text input.
Definition: cocoa_wnd.h:100
NSCursor(OTTD_QuickdrawCursor)
Category of NSCursor to allow cursor showing/hiding.
Definition: cocoa_wnd.h:29
VideoDriver_Cocoa
Definition: cocoa_v.h:23
OTTD_CocoaWindow
Subclass of NSWindow to cater our special needs.
Definition: cocoa_wnd.h:91