First draft of ios_menu

This commit is contained in:
Jay McCarthy 2014-11-04 22:01:01 -05:00
parent cf7d975b19
commit f2f96bcac8
7 changed files with 234 additions and 2 deletions

View File

@ -21,6 +21,9 @@
#include <file/file_path.h>
#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:^{

View File

@ -26,6 +26,8 @@
#include "bluetooth/btdynamic.h"
#include "bluetooth/btpad.h"
#include "../../menu/disp/ios.h"
id<RetroArch_Platform> 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();
}

View File

@ -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

View File

@ -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;

View File

@ -702,6 +702,10 @@ MENU
#endif
#ifdef IOS
#include "../menu/disp/ios.c"
#endif
#ifdef HAVE_COMMAND
#include "../command.c"
#endif

92
menu/disp/ios.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#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",
};

18
menu/disp/ios.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
typedef struct ios_handle {
void (*switch_to_ios)(void);
} ios_handle_t;