diff --git a/ios/RetroArch/settings/RASettingsList.m b/ios/RetroArch/settings/RASettingsList.m index 2d2e11cc93..2a7620641c 100644 --- a/ios/RetroArch/settings/RASettingsList.m +++ b/ios/RetroArch/settings/RASettingsList.m @@ -84,6 +84,15 @@ static RASettingData* subpath_setting(config_file_t* config, NSString* name, NSS return result; } +static RASettingData* range_setting(config_file_t* config, NSString* name, NSString* label, NSString* defaultValue, double minValue, double maxValue) +{ + RASettingData* result = [[RASettingData alloc] initWithType:RangeSetting label:label name:name]; + result.value = get_value_from_config(config, name, defaultValue); + result.rangeMin = minValue; + result.rangeMax = maxValue; + return result; +} + static RASettingData* aspect_setting(config_file_t* config, NSString* label) { // Why does this need to be so difficult? @@ -152,6 +161,7 @@ static RASettingData* custom_action(NSString* action) [NSArray arrayWithObjects:@"Input", subpath_setting(config, @"input_overlay", @"Input Overlay", @"", overlay_path, @"cfg"), + range_setting(config, @"input_overlay_opacity", @"Overlay Opacity", @"1.0", 0.0, 1.0), group_setting(@"Player 1 Keys", [NSArray arrayWithObjects: [NSArray arrayWithObjects:@"Player 1", button_setting(config, @"input_player1_up", @"Up", @"up"), diff --git a/ios/RetroArch/settings/RASettingsSubList.m b/ios/RetroArch/settings/RASettingsSubList.m index 5342134ee9..d53e1811e1 100644 --- a/ios/RetroArch/settings/RASettingsSubList.m +++ b/ios/RetroArch/settings/RASettingsSubList.m @@ -128,6 +128,12 @@ static const char* const SETTINGID = "SETTING"; setting.value = (swt.on ? @"true" : @"false"); } +- (void)handleSlider:(UISlider*)sld +{ + RASettingData* setting = objc_getAssociatedObject(sld, SETTINGID); + setting.value = [NSString stringWithFormat:@"%f", sld.value]; +} + - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { RASettingData* setting = [[settings objectAtIndex:indexPath.section] objectAtIndex:indexPath.row + 1]; @@ -156,6 +162,30 @@ static const char* const SETTINGID = "SETTING"; objc_setAssociatedObject(swt, SETTINGID, setting, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } break; + + case RangeSetting: + { + cell = [self.tableView dequeueReusableCellWithIdentifier:@"range"]; + + if (cell == nil) + { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"range"]; + + UISlider* accessory = [UISlider new]; + [accessory addTarget:self action:@selector(handleSlider:) forControlEvents:UIControlEventValueChanged]; + accessory.continuous = NO; + cell.accessoryView = accessory; + + [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; + } + + UISlider* sld = (UISlider*)cell.accessoryView; + sld.minimumValue = setting.rangeMin; + sld.maximumValue = setting.rangeMax; + sld.value = [setting.value doubleValue]; + objc_setAssociatedObject(sld, SETTINGID, setting, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } + break; case EnumerationSetting: case FileListSetting: @@ -168,7 +198,7 @@ static const char* const SETTINGID = "SETTING"; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } break; - + case GroupSetting: { cell = [self.tableView dequeueReusableCellWithIdentifier:@"group"]; diff --git a/ios/RetroArch/settings/settings.h b/ios/RetroArch/settings/settings.h index ce8a93c3e7..7d21abab33 100644 --- a/ios/RetroArch/settings/settings.h +++ b/ios/RetroArch/settings/settings.h @@ -16,7 +16,7 @@ enum SettingTypes { BooleanSetting, ButtonSetting, EnumerationSetting, FileListSetting, - GroupSetting, AspectSetting, CustomAction + GroupSetting, AspectSetting, RangeSetting, CustomAction }; @interface RASettingData : NSObject @@ -30,6 +30,9 @@ enum SettingTypes @property (strong) NSArray* subValues; @property (strong) NSMutableArray* msubValues; +@property double rangeMin; +@property double rangeMax; + - (id)initWithType:(enum SettingTypes)aType label:(NSString*)aLabel name:(NSString*)aName; @end