diff --git a/apple/iOS/menu.m b/apple/iOS/menu.m index 601855faa3..84998afbe2 100644 --- a/apple/iOS/menu.m +++ b/apple/iOS/menu.m @@ -21,6 +21,9 @@ #include #include "menu.h" +#include "../../menu/menu_common.h" +#include "../../menu/disp/shared.h" + /*********************************************/ /* RunActionSheet */ /* Creates and displays a UIActionSheet with */ @@ -546,8 +549,105 @@ static void RunActionSheet(const char* title, const struct string_list* items, U { RAMainMenu* __weak weakSelf = self; self.sections = [NSMutableArray array]; + + menu_handle_t *mh = driver.menu; + // XXX Writing these down for reference + mh->list_mainmenu; + mh->list_settings; + mh->menu_list; + + char title[256]; + const char *dir = NULL; + const char *label = NULL; + unsigned menu_type = 0; + menu_list_get_last_stack(driver.menu->menu_list, + &dir, &label, &menu_type); + + get_title(label, dir, menu_type, title, sizeof(title)); + + const char *core_name = g_extern.menu.info.library_name; + if (!core_name) + core_name = g_extern.system.info.library_name; + if (!core_name) + core_name = "No Core"; + + const char *core_version = g_extern.menu.info.library_version; + if (!core_version) + core_version = g_extern.system.info.library_version; + if (!core_version) + core_version = ""; + + char title_msg[256]; + snprintf(title_msg, sizeof(title_msg), "%s - %s %s", PACKAGE_VERSION, + core_name, core_version); + self.title = BOXSTRING(title_msg); + + NSMutableArray *everything = [NSMutableArray array]; + [everything addObject:BOXSTRING(title)]; + + size_t end = menu_list_get_size(driver.menu->menu_list); + for (size_t i = driver.menu->begin; i < end; i++) { + char message[PATH_MAX], type_str[PATH_MAX], + entry_title_buf[PATH_MAX], type_str_buf[PATH_MAX], + path_buf[PATH_MAX]; + const char *path = NULL, *entry_label = NULL; + unsigned type = 0, w = 0; + bool selected = false; + + menu_list_get_at_offset(driver.menu->menu_list->selection_buf, i, &path, + &entry_label, &type); + rarch_setting_t *setting = + (rarch_setting_t*)setting_data_find_setting + (driver.menu->list_settings, + driver.menu->menu_list->selection_buf->list[i].label); + (void)setting; + + disp_set_label + (driver.menu->menu_list->selection_buf, &w, type, i, label, + type_str, sizeof(type_str), + entry_label, path, + path_buf, sizeof(path_buf)); + + [everything addObject: + // XXX Look at the type and maybe make a different + // kind, such as for a setting. Right now, assume + // everything is a button. + [RAMenuItemBasic + itemWithDescription:BOXSTRING(path_buf) + action:^{ + // XXX This is not doing what I expect. In + // particular, "Settings" doesn't open a new + // menu. (I assumed it would call some command + // that would go out, change the driver.menu + // value, then call back into here with a new + // thing. + // + // Idea 1: setting->action_ok doesn't work like that. + // + // Idea 2: I need to explicitly go back to + // gameView and let RA run. + // + // Idea 3: setting is actually totally busted + // because this is an ObjC block and I need to + // store it in a ObjC object that is controlled + // by the GC. [I don't think this is the case, + // because saving a new config works, but if it + // is, this is actually quite easy to fix.] + if ( setting != NULL ) { + setting->action_ok(setting, MENU_ACTION_OK); + } + }]]; + } - [self.sections addObject:[NSArray arrayWithObjects:BOXSTRING("Content"), + [self.sections addObject:everything]; +} + +- (void)willReloadDataOLD +{ + RAMainMenu* __weak weakSelf = self; + self.sections = [NSMutableArray array]; + + [self.sections addObject:[NSArray arrayWithObjects:BOXSTRING("Content"), [RAMenuItemBasic itemWithDescription:BOXSTRING("Core") action:^{ [weakSelf chooseCoreWithPath:nil]; } detail:^{ diff --git a/apple/iOS/platform.m b/apple/iOS/platform.m index b8b426f6bb..fc9c399b6e 100644 --- a/apple/iOS/platform.m +++ b/apple/iOS/platform.m @@ -26,6 +26,8 @@ #include "bluetooth/btdynamic.h" #include "bluetooth/btpad.h" +#include "../../menu/disp/ios.h" + id apple_platform; void apple_rarch_exited(void); @@ -211,6 +213,13 @@ enum return (RetroArch_iOS*)[[UIApplication sharedApplication] delegate]; } +void switch_to_ios() { + if ( apple_platform != NULL ) { + RetroArch_iOS *ap = (RetroArch_iOS *)apple_platform; + [ap showPauseMenu:ap]; + } +} + - (void)applicationDidFinishLaunching:(UIApplication *)application { apple_platform = self; @@ -224,9 +233,14 @@ enum [self pushViewController:[RAMainMenu new] animated:YES]; [apple_platform loadingCore:nil withFile:nil]; - + if (rarch_main(0, NULL)) apple_rarch_exited(); + + if ( driver.menu != NULL && driver.menu->userdata != NULL ) { + ios_handle_t *ih = (ios_handle_t*)driver.menu->userdata; + ih->switch_to_ios = switch_to_ios; + } apple_gamecontroller_init(); } diff --git a/driver.c b/driver.c index 83ee375acd..6c538082cc 100644 --- a/driver.c +++ b/driver.c @@ -227,6 +227,9 @@ static const location_driver_t *location_drivers[] = { #ifdef HAVE_MENU static const menu_ctx_driver_t *menu_ctx_drivers[] = { +#ifdef IOS + &menu_ctx_ios, +#endif #if defined(HAVE_RMENU) &menu_ctx_rmenu, #endif diff --git a/driver.h b/driver.h index c03318da51..171d621033 100644 --- a/driver.h +++ b/driver.h @@ -694,6 +694,7 @@ extern menu_ctx_driver_t menu_ctx_rgui; extern menu_ctx_driver_t menu_ctx_glui; extern menu_ctx_driver_t menu_ctx_xmb; extern menu_ctx_driver_t menu_ctx_lakka; +extern menu_ctx_driver_t menu_ctx_ios; extern menu_ctx_driver_backend_t menu_ctx_backend_common; extern menu_ctx_driver_backend_t menu_ctx_backend_lakka; diff --git a/griffin/griffin.c b/griffin/griffin.c index 1fe1904e69..703bb2da7f 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -702,6 +702,10 @@ MENU #endif +#ifdef IOS +#include "../menu/disp/ios.c" +#endif + #ifdef HAVE_COMMAND #include "../command.c" #endif diff --git a/menu/disp/ios.c b/menu/disp/ios.c new file mode 100644 index 0000000000..73f10c6c21 --- /dev/null +++ b/menu/disp/ios.c @@ -0,0 +1,92 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2014 - Jay McCarthy + * + * 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 "../menu_common.h" +#include "../../general.h" +#include "ios.h" + +static void* ios_init () { + menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu)); + if (menu == NULL) { + return NULL; + } + + menu->userdata = (ios_handle_t*)calloc(1, sizeof(ios_handle_t)); + if (menu->userdata == NULL) { + free(menu); + return NULL; + } + + return menu; +} + +static void ios_free ( void* data ) { + menu_handle_t *menu = (menu_handle_t*)data; + if (menu == NULL) { + return; + } + + if (menu->userdata != NULL) { + free(menu->userdata); + } + + free(menu); + return; +} + +static void ios_render() { + ios_handle_t *ih = NULL; + if (driver.menu == NULL) { + return; + } + + ih = (ios_handle_t*)driver.menu->userdata; + if ( ih->switch_to_ios != NULL ) { + ih->switch_to_ios(); + } + + return; +} + +menu_ctx_driver_t menu_ctx_ios = { + NULL, // set_texture + NULL, // render_messagebox + ios_render, // render + NULL, // frame + ios_init, // init + NULL, // init_lists + ios_free, // free + NULL, // context_reset + NULL, // context_destroy + NULL, // populate_entries + NULL, // iterate + NULL, // input_postprocess + NULL, // navigation_clear + NULL, // navigation_decrement + NULL, // navigation_increment + NULL, // navigation_set + NULL, // navigation_set_last + NULL, // navigation_descend_alphabet + NULL, // navigation_ascend_alphabet + NULL, // list_insert + NULL, // list_delete + NULL, // list_clear + NULL, // list_set_selection + NULL, // init_core_info + &menu_ctx_backend_common, // backend + "ios", +}; diff --git a/menu/disp/ios.h b/menu/disp/ios.h new file mode 100644 index 0000000000..0f09edded7 --- /dev/null +++ b/menu/disp/ios.h @@ -0,0 +1,18 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2014 - Jay McCarthy + * + * 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 . + */ + +typedef struct ios_handle { + void (*switch_to_ios)(void); +} ios_handle_t;