Files
@ r28210:eaa3026e9a5f
Branch filter:
Location: cpp/openttd-patchpack/source/src/os/macosx/macos.mm - annotation
r28210:eaa3026e9a5f
7.6 KiB
text/x-objective-c++
Remove: ZOOM_LVL_COUNT
This is the only enumeration with a COUNT and END. The logic of the COUNT
implied that BEGIN could be non-zero, but all but two uses of zoom level
assume that BEGIN is zero, making the separate count only confusing.
This is the only enumeration with a COUNT and END. The logic of the COUNT
implied that BEGIN could be non-zero, but all but two uses of zoom level
assume that BEGIN is zero, making the separate count only confusing.
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r17872:b79cbd1ba78a r17872:b79cbd1ba78a r12386:d4d6ee913899 r12386:d4d6ee913899 r12386:d4d6ee913899 r13189:ab2ccc525850 r13191:af1540e675da r24556:fb8120e96ffe r22780:58edd93c83ed r7965:724a81116ee2 r12386:d4d6ee913899 r12386:d4d6ee913899 r5941:09e955ca9251 r12386:d4d6ee913899 r12386:d4d6ee913899 r5941:09e955ca9251 r22778:81fef1b7f626 r22778:81fef1b7f626 r22778:81fef1b7f626 r22778:81fef1b7f626 r5941:09e955ca9251 r5941:09e955ca9251 r5941:09e955ca9251 r5941:09e955ca9251 r5941:09e955ca9251 r13187:b8b0e4467fd1 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r22779:91258f0e49f5 r24559:48cbe57bb66b r24559:48cbe57bb66b r24559:48cbe57bb66b r24559:48cbe57bb66b r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r24559:48cbe57bb66b r24559:48cbe57bb66b r24559:48cbe57bb66b r22779:91258f0e49f5 r13187:b8b0e4467fd1 r13187:b8b0e4467fd1 r27989:4cf715122cf8 r5941:09e955ca9251 r13189:ab2ccc525850 r5941:09e955ca9251 r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r10647:62911ec68e89 r5941:09e955ca9251 r5941:09e955ca9251 r5941:09e955ca9251 r5941:09e955ca9251 r5941:09e955ca9251 r5941:09e955ca9251 r5941:09e955ca9251 r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r10647:62911ec68e89 r5941:09e955ca9251 r27405:f68bba683a4b r5941:09e955ca9251 r5941:09e955ca9251 r5941:09e955ca9251 r5941:09e955ca9251 r13189:ab2ccc525850 r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r13189:ab2ccc525850 r5941:09e955ca9251 r13189:ab2ccc525850 r13189:ab2ccc525850 r13189:ab2ccc525850 r13189:ab2ccc525850 r16153:a01a44cad10a r13189:ab2ccc525850 r5941:09e955ca9251 r7435:99b4080fabcb r28205:3e71ed293456 r18633:fe121c0d94f6 r28205:3e71ed293456 r18633:fe121c0d94f6 r7435:99b4080fabcb r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r7435:99b4080fabcb r7435:99b4080fabcb r7435:99b4080fabcb r13196:3cb3f432e842 r13196:3cb3f432e842 r13196:3cb3f432e842 r7435:99b4080fabcb r7984:4e4b70ff8d8e r24155:5b95a315c909 r24155:5b95a315c909 r7435:99b4080fabcb r7435:99b4080fabcb r7965:724a81116ee2 r7965:724a81116ee2 r13542:254a5af7943c r17872:b79cbd1ba78a r17872:b79cbd1ba78a r17872:b79cbd1ba78a r27479:6d2256bd62c8 r17872:b79cbd1ba78a r27479:6d2256bd62c8 r13191:af1540e675da r13191:af1540e675da r25719:14932b129f4d r13191:af1540e675da r13191:af1540e675da r13191:af1540e675da r27479:6d2256bd62c8 r13191:af1540e675da r25719:14932b129f4d r27479:6d2256bd62c8 r13191:af1540e675da r27479:6d2256bd62c8 r13191:af1540e675da r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r24556:fb8120e96ffe r13542:254a5af7943c r18624:af0d406ed005 r20625:eee38d09d194 r20625:eee38d09d194 r20625:eee38d09d194 r20625:eee38d09d194 r20625:eee38d09d194 r20625:eee38d09d194 r20625:eee38d09d194 r22778:81fef1b7f626 r20625:eee38d09d194 r24155:5b95a315c909 r20625:eee38d09d194 r22780:58edd93c83ed r22780:58edd93c83ed r22780:58edd93c83ed r22780:58edd93c83ed r22780:58edd93c83ed r22780:58edd93c83ed r22780:58edd93c83ed r22780:58edd93c83ed r22780:58edd93c83ed r22780:58edd93c83ed r22780:58edd93c83ed r22780:58edd93c83ed r24155:5b95a315c909 r22780:58edd93c83ed r22780:58edd93c83ed r22780:58edd93c83ed r27371:b9ad4c1bff08 r27737:728d55b97775 r27371:b9ad4c1bff08 r27371:b9ad4c1bff08 r27371:b9ad4c1bff08 | /*
* 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 macos.mm Code related to MacOSX. */
#include "../../stdafx.h"
#include "../../core/bitmath_func.hpp"
#include "../../rev.h"
#include "macos.h"
#include "../../string_func.h"
#include "../../fileio_func.h"
#include <pthread.h>
#define Rect OTTDRect
#define Point OTTDPoint
#include <AppKit/AppKit.h>
#undef Rect
#undef Point
#ifndef __clang__
#define __bridge
#endif
/*
* This file contains objective C
* Apple uses objective C instead of plain C to interact with OS specific/native functions
*/
#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_10)
typedef struct {
NSInteger majorVersion;
NSInteger minorVersion;
NSInteger patchVersion;
} OTTDOperatingSystemVersion;
#define NSOperatingSystemVersion OTTDOperatingSystemVersion
#endif
#ifdef WITH_COCOA
static NSAutoreleasePool *_ottd_autorelease_pool;
#endif
/**
* Get the version of the MacOS we are running under. Code adopted
* from http://www.cocoadev.com/index.pl?DeterminingOSVersion
* @param return_major major version of the os. This would be 10 in the case of 10.4.11
* @param return_minor minor version of the os. This would be 4 in the case of 10.4.11
* @param return_bugfix bugfix version of the os. This would be 11 in the case of 10.4.11
* A return value of -1 indicates that something went wrong and we don't know.
*/
void GetMacOSVersion(int *return_major, int *return_minor, int *return_bugfix)
{
*return_major = -1;
*return_minor = -1;
*return_bugfix = -1;
if ([[ NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion) ]) {
IMP sel = [ [ NSProcessInfo processInfo] methodForSelector:@selector(operatingSystemVersion) ];
NSOperatingSystemVersion ver = ((NSOperatingSystemVersion (*)(id, SEL))sel)([ NSProcessInfo processInfo], @selector(operatingSystemVersion));
*return_major = (int)ver.majorVersion;
*return_minor = (int)ver.minorVersion;
*return_bugfix = (int)ver.patchVersion;
return;
}
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10)
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
SInt32 systemVersion, version_major, version_minor, version_bugfix;
if (Gestalt(gestaltSystemVersion, &systemVersion) == noErr) {
if (systemVersion >= 0x1040) {
if (Gestalt(gestaltSystemVersionMajor, &version_major) == noErr) *return_major = (int)version_major;
if (Gestalt(gestaltSystemVersionMinor, &version_minor) == noErr) *return_minor = (int)version_minor;
if (Gestalt(gestaltSystemVersionBugFix, &version_bugfix) == noErr) *return_bugfix = (int)version_bugfix;
} else {
*return_major = (int)(GB(systemVersion, 12, 4) * 10 + GB(systemVersion, 8, 4));
*return_minor = (int)GB(systemVersion, 4, 4);
*return_bugfix = (int)GB(systemVersion, 0, 4);
}
}
#ifdef __clang__
# pragma clang diagnostic pop
#endif
#endif
}
#ifdef WITH_COCOA
extern void CocoaDialog(const char *title, const char *message, const char *buttonLabel);
/**
* Show the system dialogue message (Cocoa on MacOSX).
*
* @param title Window title.
* @param message Message text.
* @param buttonLabel Button text.
*/
void ShowMacDialog(const char *title, const char *message, const char *buttonLabel)
{
CocoaDialog(title, message, buttonLabel);
}
#else
/**
* Show the system dialogue message (console on MacOSX).
*
* @param title Window title.
* @param message Message text.
* @param buttonLabel Button text.
*/
void ShowMacDialog(const char *title, const char *message, const char *buttonLabel)
{
fmt::print(stderr, "{}: {}\n", title, message);
}
#endif
/**
* Show an error message.
*
* @param buf error message text.
* @param system message text originates from OS.
*/
void ShowOSErrorBox(const char *buf, bool system)
{
/* Display the error in the best way possible. */
if (system) {
ShowMacDialog("OpenTTD has encountered an error", buf, "Quit");
} else {
ShowMacDialog(buf, "See the readme for more info.", "Quit");
}
}
void OSOpenBrowser(const std::string &url)
{
[ [ NSWorkspace sharedWorkspace ] openURL:[ NSURL URLWithString:[ NSString stringWithUTF8String:url.c_str() ] ] ];
}
/**
* Determine and return the current user's locale.
*/
const char *GetCurrentLocale(const char *)
{
static char retbuf[32] = { '\0' };
NSUserDefaults *defs = [ NSUserDefaults standardUserDefaults ];
NSArray *languages = [ defs objectForKey:@"AppleLanguages" ];
NSString *preferredLang = [ languages objectAtIndex:0 ];
/* preferredLang is either 2 or 5 characters long ("xx" or "xx_YY"). */
[ preferredLang getCString:retbuf maxLength:32 encoding:NSASCIIStringEncoding ];
return retbuf;
}
#ifdef WITH_COCOA
/**
* Return the contents of the clipboard (COCOA).
*
* @return The (optional) clipboard contents.
*/
std::optional<std::string> GetClipboardContents()
{
NSPasteboard *pb = [ NSPasteboard generalPasteboard ];
NSArray *types = [ NSArray arrayWithObject:NSPasteboardTypeString ];
NSString *bestType = [ pb availableTypeFromArray:types ];
/* Clipboard has no text data available. */
if (bestType == nil) return std::nullopt;
NSString *string = [ pb stringForType:NSPasteboardTypeString ];
if (string == nil || [ string length ] == 0) return std::nullopt;
return [ string UTF8String ];
}
/** Set the application's bundle directory.
*
* This is needed since OS X application bundles do not have a
* current directory and the data files are 'somewhere' in the bundle.
*/
void CocoaSetApplicationBundleDir()
{
extern std::array<std::string, NUM_SEARCHPATHS> _searchpaths;
char tmp[MAXPATHLEN];
CFAutoRelease<CFURLRef> url(CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()));
if (CFURLGetFileSystemRepresentation(url.get(), true, (unsigned char *)tmp, MAXPATHLEN)) {
_searchpaths[SP_APPLICATION_BUNDLE_DIR] = tmp;
AppendPathSeparator(_searchpaths[SP_APPLICATION_BUNDLE_DIR]);
} else {
_searchpaths[SP_APPLICATION_BUNDLE_DIR].clear();
}
}
/**
* Setup autorelease for the application pool.
*
* These are called from main() to prevent a _NSAutoreleaseNoPool error when
* exiting before the cocoa video driver has been loaded
*/
void CocoaSetupAutoreleasePool()
{
_ottd_autorelease_pool = [ [ NSAutoreleasePool alloc ] init ];
}
/**
* Autorelease the application pool.
*/
void CocoaReleaseAutoreleasePool()
{
[ _ottd_autorelease_pool release ];
}
#endif
/**
* Check if a font is a monospace font.
* @param name Name of the font.
* @return True if the font is a monospace font.
*/
bool IsMonospaceFont(CFStringRef name)
{
NSFont *font = [ NSFont fontWithName:(__bridge NSString *)name size:0.0f ];
return font != nil ? [ font isFixedPitch ] : false;
}
/**
* Set the name of the current thread for the debugger.
* @param name The new name of the current thread.
*/
void MacOSSetThreadName(const char *name)
{
if (MacOSVersionIsAtLeast(10, 6, 0)) {
pthread_setname_np(name);
}
NSThread *cur = [ NSThread currentThread ];
if (cur != nil && [ cur respondsToSelector:@selector(setName:) ]) {
[ cur performSelector:@selector(setName:) withObject:[ NSString stringWithUTF8String:name ] ];
}
}
uint64_t MacOSGetPhysicalMemory()
{
return [ [ NSProcessInfo processInfo ] physicalMemory ];
}
|