Implement building of libopenrct2 and OpenRCT-UI for macOS

Initial setup of xcode for multiple targets

libopenrct2 partially working

Restore macOS mach_info init

Get macOS OpenRCT2-ui working if hackish

Implement UiContext for macOS properly

Put tabbing cancellation code back
This commit is contained in:
Richard Jenkins 2017-05-12 00:37:00 +01:00 committed by Gymnasiast
parent 3fa764321e
commit e8ec7ee58f
7 changed files with 2848 additions and 1345 deletions

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
*****************************************************************************/
#pragma endregion
#ifdef __linux__
#if defined(__linux__)
#include <dlfcn.h>
#include <sstream>
@ -49,6 +49,9 @@ namespace OpenRCT2 { namespace Ui
bool IsSteamOverlayAttached() override
{
#ifdef __APPLE__
return false;
#endif
// See http://syprog.blogspot.ru/2011/12/listing-loaded-shared-objects-in-linux.html
struct lmap
{

View File

@ -16,6 +16,8 @@
#include <algorithm>
#include <chrono>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <vector>
#include <SDL.h>
@ -495,10 +497,11 @@ public:
SDL_SetWindowMinimumSize(_window, 720, 480);
SetCursorTrap(gConfigGeneral.trap_cursor);
_platformUiContext->SetWindowIcon(_window);
#ifdef __MACOSX__
macos_disallow_automatic_window_tabbing();
#endif
#ifdef __MACOSX__
#endif
// Initialise the surface, palette and draw buffer
OnResize(width, height);
@ -508,6 +511,8 @@ public:
// Check if steam overlay renderer is loaded into the process
_steamOverlayActive = _platformUiContext->IsSteamOverlayAttached();
TriggerResize();
}
void CloseWindow() override

View File

@ -0,0 +1,186 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 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, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#if defined(__APPLE__) && defined(__MACH__)
#import <Cocoa/Cocoa.h>
#include <mach-o/dyld.h>
#include <dlfcn.h>
#include <openrct2/common.h>
#include <openrct2/core/String.hpp>
#include <openrct2/ui/UiContext.h>
#include "UiContext.h"
#include <SDL.h>
namespace OpenRCT2 { namespace Ui
{
class macOSContext final : public IPlatformUiContext
{
private:
public:
macOSContext()
{
@autoreleasepool {
if ([NSWindow respondsToSelector:@selector(setAllowsAutomaticWindowTabbing:)]) {
[NSWindow setAllowsAutomaticWindowTabbing:NO];
}
}
}
void SetWindowIcon(SDL_Window * window) override
{
}
bool IsSteamOverlayAttached() override
{
STUB();
return false;
}
void ShowMessageBox(SDL_Window * window, const std::string &message) override
{
@autoreleasepool
{
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert addButtonWithTitle:@"OK"];
alert.messageText = [NSString stringWithUTF8String:message.c_str()];
[alert runModal];
}
}
std::string ShowFileDialog(SDL_Window * window, const FileDialogDesc &desc) override
{
@autoreleasepool
{
NSMutableArray *extensions = [NSMutableArray new];
for (const OpenRCT2::Ui::FileDialogDesc::Filter &filter: desc.Filters) {
if (filter.Pattern != "") {
NSString *fp = [NSString stringWithUTF8String:filter.Pattern.c_str()];
fp = [fp stringByReplacingOccurrencesOfString:@"*." withString:@""];
[extensions addObjectsFromArray:[fp componentsSeparatedByString:@";"]];
}
}
NSString *directory;
NSSavePanel *panel;
if (desc.Type == FILE_DIALOG_TYPE::SAVE)
{
NSString *filePath = [NSString stringWithUTF8String:desc.DefaultFilename.c_str()];
directory = filePath.stringByDeletingLastPathComponent;
NSString *basename = filePath.lastPathComponent;
panel = [NSSavePanel savePanel];
panel.nameFieldStringValue = [NSString stringWithFormat:@"%@.%@", basename, extensions.firstObject];
}
else if (desc.Type == FILE_DIALOG_TYPE::OPEN)
{
directory = [NSString stringWithUTF8String:desc.InitialDirectory.c_str()];
NSOpenPanel *open = [NSOpenPanel openPanel];
open.canChooseDirectories = false;
open.canChooseFiles = true;
open.allowsMultipleSelection = false;
panel = open;
} else {
return std::string();
}
panel.title = [NSString stringWithUTF8String:desc.Title.c_str()];
panel.allowedFileTypes = extensions;
panel.directoryURL = [NSURL fileURLWithPath:directory];
if ([panel runModal] == NSFileHandlingPanelCancelButton){
return std::string();
} else {
return panel.URL.path.UTF8String;
}
}
}
std::string ShowDirectoryDialog(SDL_Window * window, const std::string &title) override
{
@autoreleasepool
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
panel.canChooseFiles = false;
panel.canChooseDirectories = true;
panel.allowsMultipleSelection = false;
utf8 *url = NULL;
if ([panel runModal] == NSFileHandlingPanelOKButton)
{
NSString *selectedPath = panel.URL.path;
const char *path = selectedPath.UTF8String;
url = _strdup(path);
}
return url;
}
}
private:
static sint32 Execute(const std::string &command, std::string * output = nullptr)
{
log_verbose("executing \"%s\"...\n", command.c_str());
FILE * fpipe = popen(command.c_str(), "r");
if (fpipe == nullptr)
{
return -1;
}
if (output != nullptr)
{
// Read output into buffer
std::vector<char> outputBuffer;
char buffer[1024];
size_t readBytes;
while ((readBytes = fread(buffer, 1, sizeof(buffer), fpipe)) > 0)
{
outputBuffer.insert(outputBuffer.begin(), buffer, buffer + readBytes);
}
// Trim line breaks
size_t outputLength = outputBuffer.size();
for (size_t i = outputLength - 1; i != SIZE_MAX; i--)
{
if (outputBuffer[i] == '\n')
{
outputLength = i;
}
else
{
break;
}
}
// Convert to string
*output = std::string(outputBuffer.data(), outputLength);
}
else
{
fflush(fpipe);
}
// Return exit code
return pclose(fpipe);
}
};
IPlatformUiContext * CreatePlatformUiContext()
{
return new macOSContext();
}
} }
#endif // __APPLE__ && __MACH__

View File

@ -114,25 +114,6 @@ void platform_show_messagebox(const char * message)
}
}
utf8 *platform_open_directory_browser(const utf8 *title)
{
@autoreleasepool
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
panel.canChooseFiles = false;
panel.canChooseDirectories = true;
panel.allowsMultipleSelection = false;
utf8 *url = NULL;
if ([panel runModal] == NSFileHandlingPanelOKButton)
{
NSString *selectedPath = panel.URL.path;
const char *path = selectedPath.UTF8String;
url = _strdup(path);
}
return url;
}
}
utf8* macos_str_decomp_to_precomp(utf8 *input)
{
@autoreleasepool
@ -146,54 +127,6 @@ utf8* macos_str_decomp_to_precomp(utf8 *input)
}
}
bool platform_open_common_file_dialog(utf8 *outFilename, file_dialog_desc *desc, size_t outSize) {
@autoreleasepool
{
NSMutableArray *extensions = [NSMutableArray new];
for (int i=0; i < countof(desc->filters); ++i) {
if (desc->filters[i].pattern != NULL) {
NSString *fp = [NSString stringWithUTF8String:desc->filters[i].pattern];
fp = [fp stringByReplacingOccurrencesOfString:@"*." withString:@""];
[extensions addObjectsFromArray:[fp componentsSeparatedByString:@";"]];
}
}
NSString *directory;
NSSavePanel *panel;
if (desc->type == FD_SAVE)
{
NSString *filePath = [NSString stringWithUTF8String:desc->default_filename];
directory = filePath.stringByDeletingLastPathComponent;
NSString *basename = filePath.lastPathComponent;
panel = [NSSavePanel savePanel];
panel.nameFieldStringValue = [NSString stringWithFormat:@"%@.%@", basename, extensions.firstObject];
}
else if (desc->type == FD_OPEN)
{
directory = [NSString stringWithUTF8String:desc->initial_directory];
NSOpenPanel *open = [NSOpenPanel openPanel];
open.canChooseDirectories = false;
open.canChooseFiles = true;
open.allowsMultipleSelection = false;
panel = open;
} else {
return false;
}
panel.title = [NSString stringWithUTF8String:desc->title];
panel.allowedFileTypes = extensions;
panel.directoryURL = [NSURL fileURLWithPath:directory];
if ([panel runModal] == NSFileHandlingPanelCancelButton){
SDL_RaiseWindow(gWindow);
return false;
} else {
safe_strcpy(outFilename, panel.URL.path.UTF8String, outSize);
SDL_RaiseWindow(gWindow);
return true;
}
}
}
bool platform_get_font_path(TTFFontDescriptor *font, utf8 *buffer, size_t size)
{
@autoreleasepool

View File

@ -47,6 +47,10 @@
#endif
#endif
#if defined(__APPLE__) && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200)
mach_timebase_info_data_t _mach_base_info = { 0 };
#endif
typedef void(*update_palette_func)(const uint8*, sint32, sint32);
rct_palette_entry gPalette[256];

View File

@ -1972,7 +1972,7 @@ static void window_options_paint(rct_window *w, rct_drawpixelinfo *dpi)
w->x + window_options_misc_widgets[WIDX_WINDOW_LIMIT].left + 1,
w->y + window_options_misc_widgets[WIDX_WINDOW_LIMIT].top
);
#ifdef __MACOSX__
#ifdef __APPLE__
set_format_arg(0, uintptr_t, (uintptr_t)macos_str_decomp_to_precomp(gConfigGeneral.rct1_path));
#else
set_format_arg(0, uintptr_t, (uintptr_t)gConfigGeneral.rct1_path);