From 96c93572733d415de1b6ac3f7ef7b666b66b2863 Mon Sep 17 00:00:00 2001 From: meancoot Date: Tue, 3 Dec 2013 19:46:30 -0500 Subject: [PATCH] (iOS) Add an enumeration type setting and use it for selecting screen orientations and bluetooth mode --- apple/iOS/menu.h | 8 +++++++ apple/iOS/menu.m | 50 ++++++++++++++++++++++++++++++++++++++++++++ apple/iOS/platform.h | 22 ++++++++----------- apple/iOS/platform.m | 49 +++++++++++++++---------------------------- 4 files changed, 84 insertions(+), 45 deletions(-) diff --git a/apple/iOS/menu.h b/apple/iOS/menu.h index da19a0f8c4..b4ed27513f 100644 --- a/apple/iOS/menu.h +++ b/apple/iOS/menu.h @@ -84,6 +84,14 @@ /*********************************************/ @interface RAMenuItemPathSetting : RAMenuItemGeneralSetting @end +/*********************************************/ +/* RAMenuItemEnumSetting */ +/* A menu item that displays and allows */ +/* a setting to be set from a list of */ +/* allowed choices. */ +/*********************************************/ +@interface RAMenuItemEnumSetting : RAMenuItemGeneralSetting @end + /*********************************************/ /* RAMenuItemBindSetting */ /* A menu item that displays and allows */ diff --git a/apple/iOS/menu.m b/apple/iOS/menu.m index 0d604113c1..8337dcbc05 100644 --- a/apple/iOS/menu.m +++ b/apple/iOS/menu.m @@ -136,6 +136,9 @@ default: break; } + if (setting->type == ST_STRING && setting->values) + return [[RAMenuItemEnumSetting alloc] initWithSetting:setting]; + RAMenuItemGeneralSetting* item = [[RAMenuItemGeneralSetting alloc] initWithSetting:setting]; if (item.setting->type == ST_INT || item.setting->type == ST_UINT || item.setting->type == ST_FLOAT) @@ -286,6 +289,51 @@ @end +/*********************************************/ +/* RAMenuItemEnumSetting */ +/* A menu item that displays and allows */ +/* a setting to be set from a list of */ +/* allowed choices. */ +/*********************************************/ +@interface RAMenuItemEnumSetting() +@property (nonatomic) UIActionSheet* actionSheet; +@end + +@implementation RAMenuItemEnumSetting + +- (void)wasSelectedOnTableView:(UITableView*)tableView ofController:(UIViewController*)controller +{ + struct string_list* options = string_split(self.setting->values, "|"); + + self.actionSheet = [UIActionSheet new]; + self.actionSheet.title = @(self.setting->short_description); + self.actionSheet.delegate = self; + + for (int i = 0; i < options->size; i ++) + { + [self.actionSheet addButtonWithTitle:@(options->elems[i].data)]; + } + + self.actionSheet.cancelButtonIndex = [self.actionSheet addButtonWithTitle:@"Cancel"]; + [self.actionSheet showInView:self.parentTable]; + + string_list_free(options); +} + +- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex +{ + if (buttonIndex != actionSheet.cancelButtonIndex) + { + setting_data_set_with_string_representation(self.setting, [actionSheet buttonTitleAtIndex:buttonIndex].UTF8String); + [self.parentTable reloadData]; + } + + self.actionSheet = nil; +} + +@end + + /*********************************************/ /* RAMenuItemBindSetting */ /* A menu item that displays and allows */ @@ -604,6 +652,8 @@ static const void* const associated_core_key = &associated_core_key; if ((self = [super initWithGroup:frontend_setting_data])) { + [[RetroArch_iOS get] refreshSystemConfig]; + RAFrontendSettingsMenu* __weak weakSelf = self; self.title = @"Frontend Settings"; diff --git a/apple/iOS/platform.h b/apple/iOS/platform.h index 12f4bfd314..f32572e6be 100644 --- a/apple/iOS/platform.h +++ b/apple/iOS/platform.h @@ -22,22 +22,18 @@ typedef struct { - bool portrait; - bool portrait_upside_down; - bool landscape_left; - bool landscape_right; + char orientations[32]; + bool logging_enabled; - bool logging_enabled; + char bluetooth_mode[64]; - char bluetooth_mode[64]; - - struct - { - int stdout; - int stderr; + struct + { + int stdout; + int stderr; - FILE* file; - } logging; + FILE* file; + } logging; } apple_frontend_settings_t; extern apple_frontend_settings_t apple_frontend_settings; diff --git a/apple/iOS/platform.m b/apple/iOS/platform.m index 2d51a1b01a..653283248d 100644 --- a/apple/iOS/platform.m +++ b/apple/iOS/platform.m @@ -57,33 +57,24 @@ void ios_set_bluetooth_mode(NSString* mode) const void* apple_get_frontend_settings(void) { - static rarch_setting_t settings[16]; + static rarch_setting_t settings[8]; if (settings[0].type == ST_NONE) { - settings[0] = setting_data_group_setting(ST_GROUP, "Frontend Settings"); - settings[1] = setting_data_group_setting(ST_SUB_GROUP, "Frontend"); - settings[2] = setting_data_bool_setting("ios_use_file_log", "Enable File Logging", + settings[0] = setting_data_group_setting(ST_GROUP, "Frontend Settings"); + settings[1] = setting_data_group_setting(ST_SUB_GROUP, "Frontend"); + settings[2] = setting_data_bool_setting("ios_use_file_log", "Enable File Logging", &apple_frontend_settings.logging_enabled, false); - settings[3] = setting_data_bool_setting("ios_tv_mode", "TV Mode", &apple_use_tv_mode, false); - settings[4] = setting_data_group_setting(ST_END_SUB_GROUP, 0); - - settings[5] = setting_data_group_setting(ST_SUB_GROUP, "Bluetooth"); - settings[6] = setting_data_string_setting(ST_STRING, "ios_btmode", "Mode", apple_frontend_settings.bluetooth_mode, + settings[3] = setting_data_bool_setting("ios_tv_mode", "TV Mode", &apple_use_tv_mode, false); + settings[4] = setting_data_string_setting(ST_STRING, "ios_btmode", "Bluetooth Input Type", apple_frontend_settings.bluetooth_mode, sizeof(apple_frontend_settings.bluetooth_mode), "keyboard"); - settings[7] = setting_data_group_setting(ST_END_SUB_GROUP, 0); + settings[4].values = "icade|keyboard|btstack"; + settings[5] = setting_data_string_setting(ST_STRING, "ios_orientations", "Screen Orientations", apple_frontend_settings.orientations, + sizeof(apple_frontend_settings.orientations), "both"); + settings[5].values = "both|landscape|portrait"; + settings[6] = setting_data_group_setting(ST_END_SUB_GROUP, 0); - settings[8] = setting_data_group_setting(ST_SUB_GROUP, "Orientations"); - settings[9] = setting_data_bool_setting("ios_allow_portrait", "Portrait", - &apple_frontend_settings.portrait, true); - settings[10] = setting_data_bool_setting("ios_allow_portrait_upside_down", "Portrait Upside Down", - &apple_frontend_settings.portrait_upside_down, true); - settings[11] = setting_data_bool_setting("ios_allow_landscape_left", "Landscape Left", - &apple_frontend_settings.landscape_left, true); - settings[12] = setting_data_bool_setting("ios_allow_landscape_right", "Landscape Right", - &apple_frontend_settings.landscape_right, true); - settings[13] = setting_data_group_setting(ST_END_SUB_GROUP, 0); - settings[14] = setting_data_group_setting(ST_END_GROUP, 0); + settings[7] = setting_data_group_setting(ST_END_GROUP, 0); } return settings; @@ -339,18 +330,12 @@ static void handle_touch_event(NSArray* touches) setting_data_load_config_path(frontend_settings, self.systemConfigPath.UTF8String); // Get enabled orientations - static const struct { const bool* value; uint32_t orientation; } orientationSettings[4] = - { - { &apple_frontend_settings.portrait, UIInterfaceOrientationMaskPortrait }, - { &apple_frontend_settings.portrait_upside_down, UIInterfaceOrientationMaskPortraitUpsideDown }, - { &apple_frontend_settings.landscape_left, UIInterfaceOrientationMaskLandscapeLeft }, - { &apple_frontend_settings.landscape_right, UIInterfaceOrientationMaskLandscapeRight } - }; + _enabledOrientations = UIInterfaceOrientationMaskAll; - _enabledOrientations = 0; - - for (int i = 0; i < 4; i ++) - _enabledOrientations |= (*orientationSettings[i].value) ? orientationSettings[i].orientation : 0; + if (strcmp(apple_frontend_settings.orientations, "landscape") == 0) + _enabledOrientations = UIInterfaceOrientationMaskLandscape; + else if (strcmp(apple_frontend_settings.orientations, "portrait") == 0) + _enabledOrientations = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; // Set bluetooth mode ios_set_bluetooth_mode(@(apple_frontend_settings.bluetooth_mode));