From ed2724e5ee59612824aa60a5f1b1fa259ccf2301 Mon Sep 17 00:00:00 2001 From: meancoot Date: Wed, 11 Dec 2013 17:55:42 -0500 Subject: [PATCH] (iOS 7) Bring back keyboard mode --- apple/common/RAGameView.m | 18 --------- apple/iOS/menu.m | 3 -- apple/iOS/platform.h | 2 - apple/iOS/platform.m | 80 ++++++++++----------------------------- 4 files changed, 21 insertions(+), 82 deletions(-) diff --git a/apple/common/RAGameView.m b/apple/common/RAGameView.m index 35dc274058..012cedc8f9 100644 --- a/apple/common/RAGameView.m +++ b/apple/common/RAGameView.m @@ -70,7 +70,6 @@ static const float ALMOST_INVISIBLE = .021f; static GLKView* g_view; static UIView* g_pause_indicator_view; -static UITextField* g_text_hide; // Camera static AVCaptureSession *_session; @@ -156,14 +155,6 @@ static bool g_is_syncing = true; g_view.enableSetNeedsDisplay = NO; [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; } @@ -182,9 +173,6 @@ static bool g_is_syncing = true; 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)hidePauseButton @@ -195,12 +183,6 @@ static bool g_is_syncing = true; ]; } -- (void)iOS7SetiCadeMode:(bool)on -{ - g_text_hide.enabled = on; - [self viewWillLayoutSubviews]; -} - void event_process_camera_frame(void* pixelBufferPtr) { CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)pixelBufferPtr; diff --git a/apple/iOS/menu.m b/apple/iOS/menu.m index f28e96678a..ecb422a16c 100644 --- a/apple/iOS/menu.m +++ b/apple/iOS/menu.m @@ -359,9 +359,6 @@ static void RunActionSheet(const char* title, const struct string_list* items, U delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Clear Keyboard", @"Clear Joystick", @"Clear Axis", nil]; - - if (is_ios_7()) - self.alert.alertViewStyle = UIAlertViewStylePlainTextInput; [self.alert show]; diff --git a/apple/iOS/platform.h b/apple/iOS/platform.h index f32572e6be..fd65071fb8 100644 --- a/apple/iOS/platform.h +++ b/apple/iOS/platform.h @@ -42,7 +42,6 @@ const void* apple_get_frontend_settings(void); @interface RAGameView : UIViewController + (RAGameView*)get; -- (void)iOS7SetiCadeMode:(bool)on; @end @interface RetroArch_iOS : UINavigationController @@ -67,6 +66,5 @@ const void* apple_get_frontend_settings(void); // modes are: keyboard, icade and btstack void ios_set_bluetooth_mode(NSString* mode); -bool is_ios_7(); #endif diff --git a/apple/iOS/platform.m b/apple/iOS/platform.m index abcd688853..ddfbbe6ac7 100644 --- a/apple/iOS/platform.m +++ b/apple/iOS/platform.m @@ -32,27 +32,10 @@ apple_frontend_settings_t apple_frontend_settings; -//#define HAVE_DEBUG_FILELOG -bool is_ios_7() -{ - return [[UIDevice currentDevice].systemVersion compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending; -} - void ios_set_bluetooth_mode(NSString* mode) { - if (!is_ios_7()) - { - apple_input_enable_icade([mode isEqualToString:@"icade"]); - btstack_set_poweron([mode isEqualToString:@"btstack"]); - } -#ifdef __IPHONE_7_0 // iOS7 iCade Support - else - { - bool enabled = [mode isEqualToString:@"icade"]; - apple_input_enable_icade(enabled); - [[RAGameView get] iOS7SetiCadeMode:enabled]; - } -#endif + apple_input_enable_icade([mode isEqualToString:@"icade"]); + btstack_set_poweron([mode isEqualToString:@"btstack"]); } const void* apple_get_frontend_settings(void) @@ -70,9 +53,7 @@ const void* apple_get_frontend_settings(void) sizeof(apple_frontend_settings.bluetooth_mode), "none"); // Set ios_btmode options based on runtime environment - if (is_ios_7()) - settings[4].values = "none|icade"; - else if (btstack_try_load()) + if (btstack_try_load()) settings[4].values = "none|icade|keyboard|btstack"; else settings[4].values = "none|icade|keyboard"; @@ -138,52 +119,33 @@ static void handle_touch_event(NSArray* touches) @implementation RApplication +// iOS7: This method is called instead of sendEvent for key events; do not try to merge it +// with the sendEvent method. +- (void)handleKeyUIEvent:(UIEvent*)event +{ + if ([event respondsToSelector:@selector(_gsEvent)]) + { + // Stolen from: http://nacho4d-nacho4d.blogspot.com/2012/01/catching-keyboard-events-in-ios.html + uint8_t* eventMem = (uint8_t*)(void*)CFBridgingRetain([event performSelector:@selector(_gsEvent)]); + int eventType = eventMem ? *(int*)&eventMem[8] : 0; + + if (eventType == GSEVENT_TYPE_KEYDOWN || eventType == GSEVENT_TYPE_KEYUP) + apple_input_handle_key_event(*(uint16_t*)&eventMem[0x3C], eventType == GSEVENT_TYPE_KEYDOWN); + + CFBridgingRelease(eventMem); + } +} + - (void)sendEvent:(UIEvent *)event { [super sendEvent:event]; if ([[event allTouches] count]) handle_touch_event(event.allTouches.allObjects); - else if ([event respondsToSelector:@selector(_gsEvent)]) - { - // Stolen from: http://nacho4d-nacho4d.blogspot.com/2012/01/catching-keyboard-events-in-ios.html - uint8_t* eventMem = (uint8_t*)(void*)CFBridgingRetain([event performSelector:@selector(_gsEvent)]); - int eventType = eventMem ? *(int*)&eventMem[8] : 0; - if (eventType == GSEVENT_TYPE_KEYDOWN || eventType == GSEVENT_TYPE_KEYUP) - apple_input_handle_key_event(*(uint16_t*)&eventMem[0x3C], eventType == GSEVENT_TYPE_KEYDOWN); - - CFBridgingRelease(eventMem); - } + [self handleKeyUIEvent:event]; } -#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