diff --git a/griffin/griffin_objc.m b/griffin/griffin_objc.m index 7cdd444896..a1b7ea06bc 100644 --- a/griffin/griffin_objc.m +++ b/griffin/griffin_objc.m @@ -38,26 +38,25 @@ #endif #if defined(HAVE_COCOATOUCH) + #if TARGET_OS_IOS #include "../ui/drivers/cocoa/cocoatouch_menu.m" #endif #include "../ui/drivers/ui_cocoatouch.m" + #else #if defined(HAVE_COCOA) || defined(HAVE_COCOA_METAL) #include "../ui/drivers/cocoa/ui_cocoa_window.m" +#include "../ui/drivers/cocoa/ui_cocoa_browser_window.m" +#include "../ui/drivers/cocoa/ui_cocoa_application.m" +#include "../ui/drivers/cocoa/ui_cocoa_msg_window.m" #endif #if defined(HAVE_COCOA) #include "../ui/drivers/ui_cocoa.m" -#include "../ui/drivers/cocoa/ui_cocoa_browser_window.m" -#include "../ui/drivers/cocoa/ui_cocoa_msg_window.m" -#include "../ui/drivers/cocoa/ui_cocoa_application.m" #elif defined(HAVE_COCOA_METAL) #include "../ui/drivers/ui_cocoa_metal.m" -#include "../ui/drivers/cocoa/ui_cocoa_browser_window_metal.m" -#include "../ui/drivers/cocoa/ui_cocoa_msg_window_metal.m" -#include "../ui/drivers/cocoa/ui_cocoa_application_metal.m" #endif #endif diff --git a/ui/drivers/cocoa/ui_cocoa_application.m b/ui/drivers/cocoa/ui_cocoa_application.m index 14975b3c10..d81e79b3f8 100644 --- a/ui/drivers/cocoa/ui_cocoa_application.m +++ b/ui/drivers/cocoa/ui_cocoa_application.m @@ -20,7 +20,11 @@ #include #include +#if defined(HAVE_COCOA_METAL) +#include "cocoa_common_metal.h" +#elif defined(HAVE_COCOA) #include "cocoa_common.h" +#endif #include "../../ui_companion_driver.h" static void* ui_application_cocoa_initialize(void) @@ -30,7 +34,7 @@ static void* ui_application_cocoa_initialize(void) static bool ui_application_cocoa_pending_events(void) { - NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; + NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; if (!event) return false; return true; @@ -40,12 +44,16 @@ static void ui_application_cocoa_process_events(void) { while (1) { - NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; + NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; if (!event) break; +#ifndef HAVE_COCOA_METAL [event retain]; +#endif [NSApp sendEvent: event]; - [event release]; +#ifndef HAVE_COCOA_METAL + [event retain]; +#endif } } diff --git a/ui/drivers/cocoa/ui_cocoa_application_metal.m b/ui/drivers/cocoa/ui_cocoa_application_metal.m deleted file mode 100644 index f82b08ff8b..0000000000 --- a/ui/drivers/cocoa/ui_cocoa_application_metal.m +++ /dev/null @@ -1,62 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2011-2017 - Daniel De Matteis - * - * RetroArch 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 Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch 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 RetroArch. - * If not, see . - */ - -#include -#include -#include -#include -#include - -#include -#include "cocoa_common_metal.h" -#include "../../ui_companion_driver.h" - -static void* ui_application_cocoa_initialize(void) -{ - return NULL; -} - -static bool ui_application_cocoa_pending_events(void) -{ - NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; - if (!event) - return false; - return true; -} - -static void ui_application_cocoa_process_events(void) -{ - while (1) - { - NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; - if (!event) - break; - [NSApp sendEvent: event]; - } -} - -static void ui_application_cocoa_run(void *args) -{ - (void)args; -} - -ui_application_t ui_application_cocoa = { - ui_application_cocoa_initialize, - ui_application_cocoa_pending_events, - ui_application_cocoa_process_events, - ui_application_cocoa_run, - NULL, - "cocoa" -}; diff --git a/ui/drivers/cocoa/ui_cocoa_browser_window.m b/ui/drivers/cocoa/ui_cocoa_browser_window.m index f93bed7efd..24acd9057b 100644 --- a/ui/drivers/cocoa/ui_cocoa_browser_window.m +++ b/ui/drivers/cocoa/ui_cocoa_browser_window.m @@ -21,36 +21,53 @@ #include -#include "cocoa_common.h" +#if defined(HAVE_COCOA_METAL) +#include "cocoa_common_metal.h" +#elif defined(HAVE_COCOA) +#endif #include "../../ui_companion_driver.h" static bool ui_browser_window_cocoa_open(ui_browser_window_state_t *state) { - NSOpenPanel* panel = (NSOpenPanel*)[NSOpenPanel openPanel]; - NSArray *filetypes = NULL; + NSOpenPanel *panel = [NSOpenPanel openPanel]; + + if (!string_is_empty(state->filters)) + { +#ifdef HAVE_COCOA_METAL + [panel setAllowedFileTypes:@[BOXSTRING(state->filters), BOXSTRING(state->filters_title)]]; +#else + NSArray *filetypes = [[NSArray alloc] initWithObjects:BOXSTRING(state->filters), BOXSTRING(state->filters_title), nil]; + [panel setAllowedFileTypes:filetypes]; +#endif + } - if (!string_is_empty(state->filters)) - filetypes = [[NSArray alloc] initWithObjects:BOXSTRING(state->filters), BOXSTRING(state->filters_title), nil]; - [panel setAllowedFileTypes:filetypes]; #if defined(MAC_OS_X_VERSION_10_6) [panel setMessage:BOXSTRING(state->title)]; if ([panel runModalForDirectory:BOXSTRING(state->startdir) file:nil] != 1) - return false; + return false; #else - [panel setTitle:NSLocalizedString(BOXSTRING(state->title), BOXSTRING("open panel"))]; - [panel setDirectory:BOXSTRING(state->startdir)]; - [panel setCanChooseDirectories:NO]; - [panel setCanChooseFiles:YES]; - [panel setAllowsMultipleSelection:NO]; - [panel setTreatsFilePackagesAsDirectories:NO]; - NSInteger result = [panel runModal]; - if (result != 1) - return false; + panel.title = NSLocalizedString(BOXSTRING(state->title), BOXSTRING("open panel")); + panel.directoryURL = [NSURL fileURLWithPath:BOXSTRING(state->startdir)]; + panel.canChooseDirectories = NO; + panel.canChooseFiles = YES; + panel.allowsMultipleSelection = NO; + panel.treatsFilePackagesAsDirectories = NO; + +#if defined(HAVE_COCOA_METAL) + NSModalResponse result = [panel runModal]; + if (result != NSModalResponseOK) + return false; +#elif defined(HAVE_COCOA) + NSInteger result = [panel runModal]; + if (result != 1) + return false; #endif - NSURL *url = (NSURL*)panel.URL; - const char *res_path = [url.path UTF8String]; - state->result = strdup(res_path); +#endif + + NSURL *url = (NSURL*)panel.URL; + const char *res_path = [url.path UTF8String]; + state->result = strdup(res_path); return true; } diff --git a/ui/drivers/cocoa/ui_cocoa_browser_window_metal.m b/ui/drivers/cocoa/ui_cocoa_browser_window_metal.m deleted file mode 100644 index 98a46cc8e2..0000000000 --- a/ui/drivers/cocoa/ui_cocoa_browser_window_metal.m +++ /dev/null @@ -1,61 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2011-2017 - Daniel De Matteis - * - * RetroArch 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 Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch 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 RetroArch. - * If not, see . - */ - -#include -#include -#include -#include -#include - -#include - -#include "cocoa_common_metal.h" - -#include "../../ui_companion_driver.h" - -static bool ui_browser_window_cocoa_open(ui_browser_window_state_t *state) -{ - NSOpenPanel *panel = [NSOpenPanel openPanel]; - - if (!string_is_empty(state->filters)) - { - [panel setAllowedFileTypes:@[BOXSTRING(state->filters), BOXSTRING(state->filters_title)]]; - } - - panel.title = NSLocalizedString(BOXSTRING(state->title), BOXSTRING("open panel")); - panel.directoryURL = [NSURL fileURLWithPath:BOXSTRING(state->startdir)]; - panel.canChooseDirectories = NO; - panel.canChooseFiles = YES; - panel.allowsMultipleSelection = NO; - panel.treatsFilePackagesAsDirectories = NO; - NSModalResponse result = [panel runModal]; - if (result != NSModalResponseOK) - return false; - const char *res_path = [panel.URL.path UTF8String]; - state->result = strdup(res_path); - - return true; -} - -static bool ui_browser_window_cocoa_save(ui_browser_window_state_t *state) -{ - return false; -} - -ui_browser_window_t ui_browser_window_cocoa = { - ui_browser_window_cocoa_open, - ui_browser_window_cocoa_save, - "cocoa" -}; diff --git a/ui/drivers/cocoa/ui_cocoa_msg_window.m b/ui/drivers/cocoa/ui_cocoa_msg_window.m index 8b9ebb3e70..cf8e92cc43 100644 --- a/ui/drivers/cocoa/ui_cocoa_msg_window.m +++ b/ui/drivers/cocoa/ui_cocoa_msg_window.m @@ -21,92 +21,108 @@ #include +#if defined(HAVE_COCOA_METAL) +#include "cocoa_common_metal.h" +#elif defined(HAVE_COCOA) #include "cocoa_common.h" +extern id apple_platform; +#endif #include "../../ui_companion_driver.h" -extern id apple_platform; - static enum ui_msg_window_response ui_msg_window_cocoa_dialog(ui_msg_window_state *state, enum ui_msg_window_type type) { - NSInteger response; - NSAlert* alert = [[NSAlert new] autorelease]; +#if defined(HAVE_COCOA_METAL) + NSModalResponse response; + NSAlert *alert = [NSAlert new]; +#elif defined(HAVE_COCOA) + NSInteger response; + NSAlert* alert = [[NSAlert new] autorelease]; +#endif - if (!string_is_empty(state->title)) - [alert setMessageText:BOXSTRING(state->title)]; - [alert setInformativeText:BOXSTRING(state->text)]; + if (!string_is_empty(state->title)) + [alert setMessageText:BOXSTRING(state->title)]; + [alert setInformativeText:BOXSTRING(state->text)]; - switch (state->buttons) - { - case UI_MSG_WINDOW_OK: - [alert addButtonWithTitle:BOXSTRING("OK")]; - break; - case UI_MSG_WINDOW_YESNO: - [alert addButtonWithTitle:BOXSTRING("Yes")]; - [alert addButtonWithTitle:BOXSTRING("No")]; - break; - case UI_MSG_WINDOW_OKCANCEL: - [alert addButtonWithTitle:BOXSTRING("OK")]; - [alert addButtonWithTitle:BOXSTRING("Cancel")]; - break; - case UI_MSG_WINDOW_YESNOCANCEL: - [alert addButtonWithTitle:BOXSTRING("Yes")]; - [alert addButtonWithTitle:BOXSTRING("No")]; - [alert addButtonWithTitle:BOXSTRING("Cancel")]; - break; - } + switch (state->buttons) + { + case UI_MSG_WINDOW_OK: + [alert addButtonWithTitle:BOXSTRING("OK")]; + break; + case UI_MSG_WINDOW_YESNO: + [alert addButtonWithTitle:BOXSTRING("Yes")]; + [alert addButtonWithTitle:BOXSTRING("No")]; + break; + case UI_MSG_WINDOW_OKCANCEL: + [alert addButtonWithTitle:BOXSTRING("OK")]; + [alert addButtonWithTitle:BOXSTRING("Cancel")]; + break; + case UI_MSG_WINDOW_YESNOCANCEL: + [alert addButtonWithTitle:BOXSTRING("Yes")]; + [alert addButtonWithTitle:BOXSTRING("No")]; + [alert addButtonWithTitle:BOXSTRING("Cancel")]; + break; + } - switch (type) - { - case UI_MSG_WINDOW_TYPE_ERROR: - [alert setAlertStyle:NSCriticalAlertStyle]; - break; - case UI_MSG_WINDOW_TYPE_WARNING: - [alert setAlertStyle:NSWarningAlertStyle]; - break; - case UI_MSG_WINDOW_TYPE_QUESTION: - [alert setAlertStyle:NSInformationalAlertStyle]; - break; - case UI_MSG_WINDOW_TYPE_INFORMATION: - [alert setAlertStyle:NSInformationalAlertStyle]; - break; - } + switch (type) + { + case UI_MSG_WINDOW_TYPE_ERROR: + [alert setAlertStyle:NSAlertStyleCritical]; + break; + case UI_MSG_WINDOW_TYPE_WARNING: + [alert setAlertStyle:NSAlertStyleWarning]; + break; + case UI_MSG_WINDOW_TYPE_QUESTION: + [alert setAlertStyle:NSAlertStyleInformational]; + break; + case UI_MSG_WINDOW_TYPE_INFORMATION: + [alert setAlertStyle:NSAlertStyleInformational]; + break; + } +#if defined(HAVE_COCOA_METAL) + [alert beginSheetModalForWindow:(BRIDGE NSWindow *)ui_companion_driver_get_main_window() + completionHandler:^(NSModalResponse returnCode) { + [[NSApplication sharedApplication] stopModalWithCode:returnCode]; + }]; + response = [alert runModal]; +#elif defined(HAVE_COCOA) [alert beginSheetModalForWindow:ui_companion_driver_get_main_window() modalDelegate:apple_platform didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil]; response = [[NSApplication sharedApplication] runModalForWindow:[alert window]]; +#endif - switch (state->buttons) - { - case UI_MSG_WINDOW_OK: - if (response == NSAlertFirstButtonReturn) - return UI_MSG_RESPONSE_OK; - break; - case UI_MSG_WINDOW_OKCANCEL: - if (response == NSAlertFirstButtonReturn) - return UI_MSG_RESPONSE_OK; - if (response == NSAlertSecondButtonReturn) - return UI_MSG_RESPONSE_CANCEL; - break; - case UI_MSG_WINDOW_YESNO: - if (response == NSAlertFirstButtonReturn) - return UI_MSG_RESPONSE_YES; - if (response == NSAlertSecondButtonReturn) - return UI_MSG_RESPONSE_NO; - break; - case UI_MSG_WINDOW_YESNOCANCEL: - if (response == NSAlertFirstButtonReturn) - return UI_MSG_RESPONSE_YES; - if (response == NSAlertSecondButtonReturn) - return UI_MSG_RESPONSE_NO; - if (response == NSAlertThirdButtonReturn) - return UI_MSG_RESPONSE_CANCEL; - break; - } + switch (state->buttons) + { + case UI_MSG_WINDOW_OK: + if (response == NSAlertFirstButtonReturn) + return UI_MSG_RESPONSE_OK; + break; + case UI_MSG_WINDOW_OKCANCEL: + if (response == NSAlertFirstButtonReturn) + return UI_MSG_RESPONSE_OK; + if (response == NSAlertSecondButtonReturn) + return UI_MSG_RESPONSE_CANCEL; + break; + case UI_MSG_WINDOW_YESNO: + if (response == NSAlertFirstButtonReturn) + return UI_MSG_RESPONSE_YES; + if (response == NSAlertSecondButtonReturn) + return UI_MSG_RESPONSE_NO; + break; + case UI_MSG_WINDOW_YESNOCANCEL: + if (response == NSAlertFirstButtonReturn) + return UI_MSG_RESPONSE_YES; + if (response == NSAlertSecondButtonReturn) + return UI_MSG_RESPONSE_NO; + if (response == NSAlertThirdButtonReturn) + return UI_MSG_RESPONSE_CANCEL; + break; + } - return UI_MSG_RESPONSE_NA; + return UI_MSG_RESPONSE_NA; } static enum ui_msg_window_response ui_msg_window_cocoa_error(ui_msg_window_state *state) diff --git a/ui/drivers/cocoa/ui_cocoa_msg_window_metal.m b/ui/drivers/cocoa/ui_cocoa_msg_window_metal.m deleted file mode 100644 index cc103bdb36..0000000000 --- a/ui/drivers/cocoa/ui_cocoa_msg_window_metal.m +++ /dev/null @@ -1,136 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2011-2017 - Daniel De Matteis - * - * RetroArch 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 Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch 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 RetroArch. - * If not, see . - */ - -#include -#include -#include -#include -#include - -#include - -#include "cocoa_common_metal.h" - -#include "../../ui_companion_driver.h" - -static enum ui_msg_window_response ui_msg_window_cocoa_dialog(ui_msg_window_state *state, enum ui_msg_window_type type) -{ - NSModalResponse response; - NSAlert *alert = [NSAlert new]; - - if (!string_is_empty(state->title)) - [alert setMessageText:BOXSTRING(state->title)]; - [alert setInformativeText:BOXSTRING(state->text)]; - - switch (state->buttons) - { - case UI_MSG_WINDOW_OK: - [alert addButtonWithTitle:BOXSTRING("OK")]; - break; - case UI_MSG_WINDOW_YESNO: - [alert addButtonWithTitle:BOXSTRING("Yes")]; - [alert addButtonWithTitle:BOXSTRING("No")]; - break; - case UI_MSG_WINDOW_OKCANCEL: - [alert addButtonWithTitle:BOXSTRING("OK")]; - [alert addButtonWithTitle:BOXSTRING("Cancel")]; - break; - case UI_MSG_WINDOW_YESNOCANCEL: - [alert addButtonWithTitle:BOXSTRING("Yes")]; - [alert addButtonWithTitle:BOXSTRING("No")]; - [alert addButtonWithTitle:BOXSTRING("Cancel")]; - break; - } - - switch (type) - { - case UI_MSG_WINDOW_TYPE_ERROR: - [alert setAlertStyle:NSAlertStyleCritical]; - break; - case UI_MSG_WINDOW_TYPE_WARNING: - [alert setAlertStyle:NSAlertStyleWarning]; - break; - case UI_MSG_WINDOW_TYPE_QUESTION: - [alert setAlertStyle:NSAlertStyleInformational]; - break; - case UI_MSG_WINDOW_TYPE_INFORMATION: - [alert setAlertStyle:NSAlertStyleInformational]; - break; - } - - [alert beginSheetModalForWindow:(BRIDGE NSWindow *)ui_companion_driver_get_main_window() - completionHandler:^(NSModalResponse returnCode) { - [[NSApplication sharedApplication] stopModalWithCode:returnCode]; - }]; - response = [alert runModal]; - - switch (state->buttons) - { - case UI_MSG_WINDOW_OK: - if (response == NSAlertFirstButtonReturn) - return UI_MSG_RESPONSE_OK; - break; - case UI_MSG_WINDOW_OKCANCEL: - if (response == NSAlertFirstButtonReturn) - return UI_MSG_RESPONSE_OK; - if (response == NSAlertSecondButtonReturn) - return UI_MSG_RESPONSE_CANCEL; - break; - case UI_MSG_WINDOW_YESNO: - if (response == NSAlertFirstButtonReturn) - return UI_MSG_RESPONSE_YES; - if (response == NSAlertSecondButtonReturn) - return UI_MSG_RESPONSE_NO; - break; - case UI_MSG_WINDOW_YESNOCANCEL: - if (response == NSAlertFirstButtonReturn) - return UI_MSG_RESPONSE_YES; - if (response == NSAlertSecondButtonReturn) - return UI_MSG_RESPONSE_NO; - if (response == NSAlertThirdButtonReturn) - return UI_MSG_RESPONSE_CANCEL; - break; - } - - return UI_MSG_RESPONSE_NA; -} - -static enum ui_msg_window_response ui_msg_window_cocoa_error(ui_msg_window_state *state) -{ - return ui_msg_window_cocoa_dialog(state, UI_MSG_WINDOW_TYPE_ERROR); -} - -static enum ui_msg_window_response ui_msg_window_cocoa_information(ui_msg_window_state *state) -{ - return ui_msg_window_cocoa_dialog(state, UI_MSG_WINDOW_TYPE_INFORMATION); -} - -static enum ui_msg_window_response ui_msg_window_cocoa_question(ui_msg_window_state *state) -{ - return ui_msg_window_cocoa_dialog(state, UI_MSG_WINDOW_TYPE_QUESTION); -} - -static enum ui_msg_window_response ui_msg_window_cocoa_warning(ui_msg_window_state *state) -{ - return ui_msg_window_cocoa_dialog(state, UI_MSG_WINDOW_TYPE_WARNING); -} - -ui_msg_window_t ui_msg_window_cocoa = { - ui_msg_window_cocoa_error, - ui_msg_window_cocoa_information, - ui_msg_window_cocoa_question, - ui_msg_window_cocoa_warning, - "cocoa" -};