1 /*
2  ** i_common.h
3  **
4  **---------------------------------------------------------------------------
5  ** Copyright 2012-2015 Alexey Lysiuk
6  ** All rights reserved.
7  **
8  ** Redistribution and use in source and binary forms, with or without
9  ** modification, are permitted provided that the following conditions
10  ** are met:
11  **
12  ** 1. Redistributions of source code must retain the above copyright
13  **    notice, this list of conditions and the following disclaimer.
14  ** 2. Redistributions in binary form must reproduce the above copyright
15  **    notice, this list of conditions and the following disclaimer in the
16  **    documentation and/or other materials provided with the distribution.
17  ** 3. The name of the author may not be used to endorse or promote products
18  **    derived from this software without specific prior written permission.
19  **
20  ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  **---------------------------------------------------------------------------
31  **
32  */
33 
34 #ifndef COCOA_I_COMMON_INCLUDED
35 #define COCOA_I_COMMON_INCLUDED
36 
37 #import <AppKit/AppKit.h>
38 
39 
40 struct RenderBufferOptions
41 {
42 	float pixelScale;
43 
44 	float shiftX;
45 	float shiftY;
46 
47 	float width;
48 	float height;
49 
50 	bool dirty;
51 };
52 
53 extern RenderBufferOptions rbOpts;
54 
55 
56 // Version of AppKit framework we are interested in
57 // The following values are needed to build with earlier SDKs
58 
59 #define AppKit10_4  824
60 #define AppKit10_5  949
61 #define AppKit10_6 1038
62 #define AppKit10_7 1138
63 
64 
65 @interface NSWindow(ExitAppOnClose)
66 - (void)exitAppOnClose;
67 @end
68 
69 
I_IsHiDPISupported()70 inline bool I_IsHiDPISupported()
71 {
72 	return NSAppKitVersionNumber >= AppKit10_7;
73 }
74 
75 void I_ProcessEvent(NSEvent* event);
76 
77 void I_ProcessJoysticks();
78 
79 NSSize I_GetContentViewSize(const NSWindow* window);
80 void I_SetMainWindowVisible(bool visible);
81 void I_SetNativeMouse(bool wantNative);
82 
83 
84 // The following definitions are required to build with older OS X SDKs
85 
86 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
87 
88 typedef unsigned int NSUInteger;
89 typedef          int NSInteger;
90 
91 typedef float CGFloat;
92 
93 // From HIToolbox/Events.h
94 enum
95 {
96 	kVK_ANSI_F        = 0x03,
97 	kVK_Return        = 0x24,
98 	kVK_Tab           = 0x30,
99 	kVK_Space         = 0x31,
100 	kVK_Delete        = 0x33,
101 	kVK_Escape        = 0x35,
102 	kVK_Command       = 0x37,
103 	kVK_Shift         = 0x38,
104 	kVK_CapsLock      = 0x39,
105 	kVK_Option        = 0x3A,
106 	kVK_Control       = 0x3B,
107 	kVK_RightShift    = 0x3C,
108 	kVK_RightOption   = 0x3D,
109 	kVK_RightControl  = 0x3E,
110 	kVK_Function      = 0x3F,
111 	kVK_F17           = 0x40,
112 	kVK_VolumeUp      = 0x48,
113 	kVK_VolumeDown    = 0x49,
114 	kVK_Mute          = 0x4A,
115 	kVK_F18           = 0x4F,
116 	kVK_F19           = 0x50,
117 	kVK_F20           = 0x5A,
118 	kVK_F5            = 0x60,
119 	kVK_F6            = 0x61,
120 	kVK_F7            = 0x62,
121 	kVK_F3            = 0x63,
122 	kVK_F8            = 0x64,
123 	kVK_F9            = 0x65,
124 	kVK_F11           = 0x67,
125 	kVK_F13           = 0x69,
126 	kVK_F16           = 0x6A,
127 	kVK_F14           = 0x6B,
128 	kVK_F10           = 0x6D,
129 	kVK_F12           = 0x6F,
130 	kVK_F15           = 0x71,
131 	kVK_Help          = 0x72,
132 	kVK_Home          = 0x73,
133 	kVK_PageUp        = 0x74,
134 	kVK_ForwardDelete = 0x75,
135 	kVK_F4            = 0x76,
136 	kVK_End           = 0x77,
137 	kVK_F2            = 0x78,
138 	kVK_PageDown      = 0x79,
139 	kVK_F1            = 0x7A,
140 	kVK_LeftArrow     = 0x7B,
141 	kVK_RightArrow    = 0x7C,
142 	kVK_DownArrow     = 0x7D,
143 	kVK_UpArrow       = 0x7E
144 };
145 
146 static const NSOpenGLPixelFormatAttribute NSOpenGLPFAAllowOfflineRenderers = NSOpenGLPixelFormatAttribute(96);
147 
148 #endif // prior to 10.5
149 
150 
151 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1060
152 
153 enum
154 {
155 	NSApplicationActivationPolicyRegular
156 };
157 
158 typedef NSInteger NSApplicationActivationPolicy;
159 
160 @interface NSApplication(ActivationPolicy)
161 - (BOOL)setActivationPolicy:(NSApplicationActivationPolicy)activationPolicy;
162 @end
163 
164 @interface NSWindow(SetStyleMask)
165 - (void)setStyleMask:(NSUInteger)styleMask;
166 @end
167 
168 #endif // prior to 10.6
169 
170 
171 #if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
172 
173 @interface NSView(HiDPIStubs)
174 - (NSPoint)convertPointToBacking:(NSPoint)aPoint;
175 - (NSSize)convertSizeToBacking:(NSSize)aSize;
176 - (NSSize)convertSizeFromBacking:(NSSize)aSize;
177 
178 - (void)setWantsBestResolutionOpenGLSurface:(BOOL)flag;
179 @end
180 
181 @interface NSScreen(HiDPIStubs)
182 - (NSRect)convertRectToBacking:(NSRect)aRect;
183 @end
184 
185 #endif // prior to 10.7
186 
187 #endif // COCOA_I_COMMON_INCLUDED
188