From 5f5be7c4dc4023bafc0cd8ffb7ac7bb786498903 Mon Sep 17 00:00:00 2001 From: meancoot Date: Thu, 7 Feb 2013 16:10:56 -0500 Subject: [PATCH] ios: Multi-touch support --- ios/RetroArch/AppDelegate.m | 51 +++++++++++++++++++++++++------------ ios/RetroArch/dirlist.m | 2 -- ios/RetroArch/gameview.m | 1 + ios/RetroArch/ios_input.c | 30 ++++++++++++++-------- 4 files changed, 55 insertions(+), 29 deletions(-) diff --git a/ios/RetroArch/AppDelegate.m b/ios/RetroArch/AppDelegate.m index 5226907a47..0bc7e022f6 100644 --- a/ios/RetroArch/AppDelegate.m +++ b/ios/RetroArch/AppDelegate.m @@ -8,8 +8,16 @@ #import "AppDelegate.h" #import "dirlist.h" -extern bool IOS_is_down; -extern int16_t IOS_touch_x, IOS_touch_y; +#define MAX_TOUCH 16 +extern struct +{ + bool is_down; + int16_t screen_x, screen_y; + int16_t fixed_x, fixed_y; + int16_t full_x, full_y; +} ios_touches[MAX_TOUCH]; + +extern uint32_t ios_current_touch_count ; @implementation AppDelegate @@ -26,34 +34,45 @@ extern int16_t IOS_touch_x, IOS_touch_y; [self.window makeKeyAndVisible]; } +- (void)processTouches:(NSArray*)touches +{ + ios_current_touch_count = [touches count]; + + for(int i = 0; i != [touches count]; i ++) + { + UITouch *touch = [touches objectAtIndex:i]; + CGPoint coord = [touch locationInView:self.window.rootViewController.view]; + float scale = [[UIScreen mainScreen] scale]; + + ios_touches[i].is_down = (touch.phase != UITouchPhaseEnded) && (touch.phase != UITouchPhaseCancelled); + + ios_touches[i].screen_x = coord.x * scale; + ios_touches[i].screen_y = coord.y * scale; + } +} + - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { - UITouch *touch = [[event allTouches] anyObject]; - CGPoint coord = [touch locationInView:self.window.rootViewController.view]; - float scale = [[UIScreen mainScreen] scale]; - - IOS_is_down = true; - IOS_touch_x = coord.x * scale; - IOS_touch_y = coord.y * scale; + [super touchesBegan:touches withEvent:event]; + [self processTouches:[[event allTouches] allObjects]]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - UITouch *touch = [[event allTouches] anyObject]; - CGPoint coord = [touch locationInView:self.window.rootViewController.view]; - IOS_is_down = true; - IOS_touch_x = coord.x; - IOS_touch_y = coord.y; + [super touchesMoved:touches withEvent:event]; + [self processTouches:[[event allTouches] allObjects]]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - IOS_is_down = false; + [super touchesEnded:touches withEvent:event]; + [self processTouches:[[event allTouches] allObjects]]; } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { - IOS_is_down = false; + [super touchesCancelled:touches withEvent:event]; + [self processTouches:[[event allTouches] allObjects]]; } - (void)applicationWillTerminate:(UIApplication *)application diff --git a/ios/RetroArch/dirlist.m b/ios/RetroArch/dirlist.m index 759df1eee5..74076b4ee3 100644 --- a/ios/RetroArch/dirlist.m +++ b/ios/RetroArch/dirlist.m @@ -142,8 +142,6 @@ struct dirent_list* build_dirent_list(const char* path) else window.rootViewController = [[game_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil]; - game_view* game = (game_view*)window.rootViewController; - extern void ios_load_game(const char*); ios_load_game(path); } diff --git a/ios/RetroArch/gameview.m b/ios/RetroArch/gameview.m index 33d837abb8..a191798ef3 100644 --- a/ios/RetroArch/gameview.m +++ b/ios/RetroArch/gameview.m @@ -50,6 +50,7 @@ static bool ra_done = false; [EAGLContext setCurrentContext:gl_context]; gl_view = [[GLKView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) context:gl_context]; + gl_view.multipleTouchEnabled = YES; self.view = gl_view; screen_scale = [[UIScreen mainScreen] scale]; diff --git a/ios/RetroArch/ios_input.c b/ios/RetroArch/ios_input.c index 05f99cd687..54df016725 100644 --- a/ios/RetroArch/ios_input.c +++ b/ios/RetroArch/ios_input.c @@ -23,37 +23,45 @@ #define MAX_TOUCH 16 -bool IOS_is_down; -int16_t IOS_touch_x, IOS_fix_x; -int16_t IOS_touch_y, IOS_fix_y; -int16_t IOS_full_x, IOS_full_y; +struct +{ + bool is_down; + int16_t screen_x, screen_y; + int16_t fixed_x, fixed_y; + int16_t full_x, full_y; +} ios_touches[MAX_TOUCH]; + +uint32_t ios_current_touch_count = 0; static void *ios_input_init(void) { + memset(ios_touches, 0, sizeof(ios_touches)); return (void*)-1; } static void ios_input_poll(void *data) { - input_translate_coord_viewport(IOS_touch_x, IOS_touch_y, - &IOS_fix_x, &IOS_fix_y, - &IOS_full_x, &IOS_full_y); + for (int i = 0; i != ios_current_touch_count; i ++) + { + input_translate_coord_viewport(ios_touches[i].screen_x, ios_touches[i].screen_y, + &ios_touches[i].fixed_x, &ios_touches[i].fixed_y, + &ios_touches[i].full_x, &ios_touches[i].full_y); + } } static int16_t ios_input_state(void *data, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned index, unsigned id) { - if (index != 0) return 0; switch (device) { case RARCH_DEVICE_POINTER_SCREEN: switch (id) { case RETRO_DEVICE_ID_POINTER_X: - return IOS_full_x; + return (index < ios_current_touch_count) ? ios_touches[index].full_x : 0; case RETRO_DEVICE_ID_POINTER_Y: - return IOS_full_y; + return (index < ios_current_touch_count) ? ios_touches[index].full_y : 0; case RETRO_DEVICE_ID_POINTER_PRESSED: - return IOS_is_down; + return (index < ios_current_touch_count) ? ios_touches[index].is_down : 0; default: return 0; }