summaryrefslogtreecommitdiff
path: root/src/video/cocoa/cocoa_wnd.h
blob: 6322bd1714ef89c69806fd1c09ea62c6ac796f6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * This file is part of OpenTTD.
 * 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.
 * 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.
 * 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/>.
 */

/** @file cocoa_wnd.h OS interface for the cocoa video driver. */

#ifndef COCOA_WND_H
#define COCOA_WND_H

#import <Cocoa/Cocoa.h>
#include "toolbar_gui.h"
#include "table/sprites.h"

#ifdef MAC_OS_X_VERSION_10_12_2
#	define HAVE_TOUCHBAR_SUPPORT
#endif

class VideoDriver_Cocoa;

/* Right Mouse Button Emulation enum */
enum RightMouseButtonEmulationState {
	RMBE_COMMAND = 0,
	RMBE_CONTROL = 1,
	RMBE_OFF     = 2,
};

extern NSString *OTTDMainLaunchGameEngine;

/** Category of NSCursor to allow cursor showing/hiding */
@interface NSCursor (OTTD_QuickdrawCursor)
+ (NSCursor *) clearCocoaCursor;
@end

#ifdef HAVE_TOUCHBAR_SUPPORT
/* 9 items can be displayed on the touch bar when using default buttons. */
static NSArray *touchBarButtonIdentifiers = @[
	@"openttd.pause",
	@"openttd.fastforward",
	@"openttd.zoom_in",
	@"openttd.zoom_out",
	@"openttd.build_rail",
	@"openttd.build_road",
	@"openttd.build_tram",
	@"openttd.build_docks",
	@"openttd.build_airport",
	NSTouchBarItemIdentifierOtherItemsProxy
];

static NSDictionary *touchBarButtonSprites = @{
	@"openttd.pause":           [NSNumber numberWithInt:SPR_IMG_PAUSE],
	@"openttd.fastforward":     [NSNumber numberWithInt:SPR_IMG_FASTFORWARD],
	@"openttd.zoom_in":         [NSNumber numberWithInt:SPR_IMG_ZOOMIN],
	@"openttd.zoom_out":        [NSNumber numberWithInt:SPR_IMG_ZOOMOUT],
	@"openttd.build_rail":      [NSNumber numberWithInt:SPR_IMG_BUILDRAIL],
	@"openttd.build_road":      [NSNumber numberWithInt:SPR_IMG_BUILDROAD],
	@"openttd.build_tram":      [NSNumber numberWithInt:SPR_IMG_BUILDTRAMS],
	@"openttd.build_docks":     [NSNumber numberWithInt:SPR_IMG_BUILDWATER],
	@"openttd.build_airport":   [NSNumber numberWithInt:SPR_IMG_BUILDAIR],
};

static NSDictionary *touchBarButtonActions = @{
	@"openttd.pause":           [NSNumber numberWithInt:MTHK_PAUSE],
	@"openttd.fastforward":     [NSNumber numberWithInt:MTHK_FASTFORWARD],
	@"openttd.zoom_in":         [NSNumber numberWithInt:MTHK_ZOOM_IN],
	@"openttd.zoom_out":        [NSNumber numberWithInt:MTHK_ZOOM_OUT],
	@"openttd.build_rail":      [NSNumber numberWithInt:MTHK_BUILD_RAIL],
	@"openttd.build_road":      [NSNumber numberWithInt:MTHK_BUILD_ROAD],
	@"openttd.build_tram":      [NSNumber numberWithInt:MTHK_BUILD_TRAM],
	@"openttd.build_docks":     [NSNumber numberWithInt:MTHK_BUILD_DOCKS],
	@"openttd.build_airport":   [NSNumber numberWithInt:MTHK_BUILD_AIRPORT],
};

static NSDictionary *touchBarFallbackText = @{
	@"openttd.pause":           @"Pause",
	@"openttd.fastforward":     @"Fast Forward",
	@"openttd.zoom_in":         @"Zoom In",
	@"openttd.zoom_out":        @"Zoom Out",
	@"openttd.build_rail":      @"Rail",
	@"openttd.build_road":      @"Road",
	@"openttd.build_tram":      @"Tram",
	@"openttd.build_docks":     @"Docks",
	@"openttd.build_airport":   @"Airport",
};
#endif

/** Subclass of NSWindow to cater our special needs */
@interface OTTD_CocoaWindow : NSWindow
#ifdef HAVE_TOUCHBAR_SUPPORT
	<NSTouchBarDelegate>
#endif

- (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag driver:(VideoDriver_Cocoa *)drv;

- (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
@end

/** Subclass of NSView to support mouse awareness and text input. */
@interface OTTD_CocoaView : NSView <NSTextInputClient>
- (NSRect)getRealRect:(NSRect)rect;
- (NSRect)getVirtualRect:(NSRect)rect;
- (CGFloat)getContentsScale;
- (NSPoint)mousePositionFromEvent:(NSEvent *)e;
@end

/** Delegate for our NSWindow to send ask for quit on close */
@interface OTTD_CocoaWindowDelegate : NSObject <NSWindowDelegate>
- (instancetype)initWithDriver:(VideoDriver_Cocoa *)drv;

- (BOOL)windowShouldClose:(id)sender;
- (void)windowDidEnterFullScreen:(NSNotification *)aNotification;
- (void)windowDidChangeBackingProperties:(NSNotification *)notification;
- (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions;
@end


extern bool _allow_hidpi_window;

bool CocoaSetupApplication();
void CocoaExitApplication();

#endif /* COCOA_WND_H */