(iOS) First draft of iCade support for iOS 7

This commit is contained in:
meancoot 2013-09-20 17:49:18 -04:00
parent a34cfadff1
commit 1b9b2f4cc2
6 changed files with 94 additions and 12 deletions

View File

@ -61,6 +61,7 @@ static const float ALMOST_INVISIBLE = .021f;
static GLKView* g_view;
static UIView* g_pause_view;
static UIView* g_pause_indicator_view;
static UITextField* g_text_hide;
#elif defined(OSX)
@ -161,11 +162,18 @@ static bool g_is_syncing = true;
[g_view addSubview:g_pause_view];
[g_view addSubview:g_pause_indicator_view];
if (is_ios_7())
{
g_text_hide = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[g_view addSubview:g_text_hide];
g_text_hide.hidden = YES;
[g_text_hide becomeFirstResponder];
}
self.view = g_view;
return self;
}
// Pause Menus
- (void)viewWillLayoutSubviews
{
@ -181,6 +189,9 @@ static bool g_is_syncing = true;
g_pause_view.frame = CGRectMake(width / 2.0f - 150.0f, height / 2.0f - 150.0f, 300.0f, 300.0f);
g_pause_indicator_view.frame = CGRectMake(tenpctw * 4.0f, 0.0f, tenpctw * 2.0f, tenpcth);
[g_pause_indicator_view viewWithTag:1].frame = CGRectMake(0, 0, tenpctw * 2.0f, tenpcth);
if (is_ios_7())
[g_text_hide becomeFirstResponder];
}
- (void)openPauseMenu

View File

@ -91,6 +91,11 @@ uint32_t apple_input_get_icade_buttons()
return icade_enabled ? icade_buttons : 0;
}
void apple_input_reset_icade_buttons()
{
icade_buttons = 0;
}
void apple_input_handle_key_event(unsigned keycode, bool down)
{
keycode = HIDKEY(keycode);
@ -116,7 +121,7 @@ int32_t apple_input_find_any_button(uint32_t port)
uint32_t buttons = g_current_input_data.pad_buttons[port] |
((port == 0) ? apple_input_get_icade_buttons() : 0);
if (g_current_input_data.pad_buttons[port])
if (buttons)
for (int i = 0; i != 32; i ++)
if (buttons & (1 << i))
return i;

View File

@ -48,8 +48,10 @@ extern apple_input_data_t g_polled_input_data; //< Game thread data
// Main thread only
void apple_input_enable_icade(bool on);
uint32_t apple_input_get_icade_buttons();
void apple_input_reset_icade_buttons();
void apple_input_handle_key_event(unsigned keycode, bool down);
extern int32_t apple_input_find_any_key();
extern int32_t apple_input_find_any_button(uint32_t port);
extern int32_t apple_input_find_any_axis(uint32_t port);

View File

@ -47,5 +47,6 @@
// modes are: keyboard, icade and btstack
void ios_set_bluetooth_mode(NSString* mode);
bool is_ios_7();
#endif

View File

@ -31,8 +31,17 @@
//#define HAVE_DEBUG_FILELOG
void ios_set_bluetooth_mode(NSString* mode)
{
#ifndef __IPHONE_7_0 // iOS7 iCade Support
apple_input_enable_icade([mode isEqualToString:@"icade"]);
btstack_set_poweron([mode isEqualToString:@"btstack"]);
#else
apple_input_enable_icade(true);
#endif
}
bool is_ios_7()
{
return [[UIDevice currentDevice].systemVersion compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending;
}
// Input helpers: This is kept here because it needs objective-c
@ -80,6 +89,33 @@ static void handle_touch_event(NSArray* touches)
}
}
#ifdef __IPHONE_7_0 // iOS7 iCade Support
- (NSArray*)keyCommands
{
static NSMutableArray* key_commands;
if (!key_commands)
{
key_commands = [NSMutableArray array];
for (int i = 0; i != 26; i ++)
{
[key_commands addObject:[UIKeyCommand keyCommandWithInput:[NSString stringWithFormat:@"%c", 'a' + i]
modifierFlags:0 action:@selector(keyGotten:)]];
}
}
return key_commands;
}
- (void)keyGotten:(UIKeyCommand *)keyCommand
{
apple_input_handle_key_event([keyCommand.input characterAtIndex:0] - 'a' + 4, true);
}
#endif
@end
@implementation RetroArch_iOS
@ -196,6 +232,8 @@ static void handle_touch_event(NSArray* touches)
// UINavigationController: Never animate when pushing onto, or popping, an RAGameView
- (void)pushViewController:(UIViewController*)theView animated:(BOOL)animated
{
apple_input_reset_icade_buttons();
if ([theView respondsToSelector:@selector(isSettingsView)] && [(id)theView isSettingsView])
_settingMenusInBackStack ++;
@ -204,6 +242,8 @@ static void handle_touch_event(NSArray* touches)
- (UIViewController*)popViewControllerAnimated:(BOOL)animated
{
apple_input_reset_icade_buttons();
if ([self.topViewController respondsToSelector:@selector(isSettingsView)] && [(id)self.topViewController isSettingsView])
_settingMenusInBackStack --;

View File

@ -105,7 +105,8 @@ enum SettingTypes
// Helper view definitions
@interface RAButtonGetter : NSObject<UIAlertViewDelegate>
- (id)initWithSetting:(RASettingData*)setting fromTable:(UITableView*)table;
- (id)initFromTable:(UITableView*)table;
- (void)runForSetting:(RASettingData*)setting;
@end
@interface RASettingEnumerationList : UITableViewController
@ -415,19 +416,23 @@ static void bluetooth_option_changed(RASettingData* setting)
}
#ifndef __IPHONE_7_0 // iOS7 iCade Support
NSArray* bluetoothOptions = [NSArray arrayWithObjects:@"keyboard", @"Keyboard",
@"icade", @"iCade Device",
btstack_try_load() ? @"btstack" : nil, @"WiiMote/SixAxis (BTstack)",
nil];
#endif
NSArray* settings = [NSArray arrayWithObjects:
[NSArray arrayWithObjects:@"Frontend",
custom_action(@"Diagnostic Log", nil, nil, 0),
boolean_setting(config, @"ios_tv_mode", @"TV Mode", @"false"),
nil],
#ifndef __IPHONE_7_0 // iOS7 iCade Support
[NSArray arrayWithObjects:@"Bluetooth",
change_notify(enumeration_setting(config, @"ios_btmode", @"Mode", @"keyboard", bluetoothOptions, true), bluetooth_option_changed),
nil],
#endif
[NSArray arrayWithObjects:@"Orientations",
boolean_setting(config, @"ios_allow_portrait", @"Portrait", @"true"),
boolean_setting(config, @"ios_allow_portrait_upside_down", @"Portrait Upside Down", @"true"),
@ -518,12 +523,17 @@ static void bluetooth_option_changed(RASettingData* setting)
@end
@implementation RASettingsSubList
{
RAButtonGetter* _binder;
}
- (id)initWithSettings:(NSMutableArray*)values title:(NSString*)title
{
self = [super initWithStyle:UITableViewStyleGrouped];
[self setTitle:title];
self.sections = values;
_binder = [[RAButtonGetter alloc] initFromTable:self.tableView];
return self;
}
@ -608,7 +618,7 @@ static void bluetooth_option_changed(RASettingData* setting)
break;
case ButtonSetting:
(void)[[RAButtonGetter alloc] initWithSetting:setting fromTable:(UITableView*)self.view];
[_binder runForSetting:setting];
break;
case GroupSetting:
@ -784,7 +794,6 @@ static void bluetooth_option_changed(RASettingData* setting)
@implementation RAButtonGetter
{
RAButtonGetter* _me;
RASettingData* _value;
UIAlertView* _alert;
UITableView* _view;
@ -792,23 +801,36 @@ static void bluetooth_option_changed(RASettingData* setting)
NSTimer* _btTimer;
}
- (id)initWithSetting:(RASettingData*)setting fromTable:(UITableView*)table
- (id)initFromTable:(UITableView*)table
{
self = [super init];
_value = setting;
_view = table;
_me = self;
_alert = [[UIAlertView alloc] initWithTitle:@"RetroArch"
message:_value->label
message:@""
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Clear Keyboard", @"Clear Joystick", @"Clear Axis", nil];
if (is_ios_7())
_alert.alertViewStyle = UIAlertViewStylePlainTextInput;
return self;
}
- (void)runForSetting:(RASettingData*)setting
{
apple_input_reset_icade_buttons();
_value = setting;
_alert.message = _value->name;
[_alert show];
_btTimer = [NSTimer scheduledTimerWithTimeInterval:.05f target:self selector:@selector(checkInput) userInfo:nil repeats:YES];
return self;
_finished = false;
}
- (void)finish
@ -817,12 +839,13 @@ static void bluetooth_option_changed(RASettingData* setting)
{
_finished = true;
apple_input_reset_icade_buttons();
[_btTimer invalidate];
_btTimer = nil;
[_alert dismissWithClickedButtonIndex:_alert.cancelButtonIndex animated:YES];
[_view reloadData];
_me = nil;
}
}