mirror of
https://github.com/libretro/RetroArch
synced 2025-03-01 07:13:35 +00:00
(iOS) Send touch events directly to a shared RAInputResponder instance, bypassing NSNotificationCenter.
This commit is contained in:
parent
2a4573854e
commit
00d809436b
@ -25,6 +25,12 @@ typedef struct touch_data
|
|||||||
} touch_data_t;
|
} touch_data_t;
|
||||||
|
|
||||||
@interface RAInputResponder : NSObject
|
@interface RAInputResponder : NSObject
|
||||||
|
+ (RAInputResponder*)sharedInstance;
|
||||||
|
|
||||||
|
- (void)reset;
|
||||||
|
|
||||||
|
- (void)handleTouches:(NSArray*)touches;
|
||||||
|
|
||||||
- (void)poll;
|
- (void)poll;
|
||||||
- (bool)isKeyPressed:(unsigned)index;
|
- (bool)isKeyPressed:(unsigned)index;
|
||||||
- (const touch_data_t*)getTouchDataAtIndex:(unsigned)index;
|
- (const touch_data_t*)getTouchDataAtIndex:(unsigned)index;
|
||||||
|
@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
extern NSString* const GSEventKeyDownNotification;
|
extern NSString* const GSEventKeyDownNotification;
|
||||||
extern NSString* const GSEventKeyUpNotification;
|
extern NSString* const GSEventKeyUpNotification;
|
||||||
extern NSString* const RATouchNotification;
|
|
||||||
|
static RAInputResponder* g_inputInstance;
|
||||||
|
|
||||||
@implementation RAInputResponder
|
@implementation RAInputResponder
|
||||||
{
|
{
|
||||||
@ -27,11 +28,18 @@ extern NSString* const RATouchNotification;
|
|||||||
bool _keys[MAX_KEYS];
|
bool _keys[MAX_KEYS];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (RAInputResponder*)sharedInstance
|
||||||
|
{
|
||||||
|
if (!g_inputInstance)
|
||||||
|
g_inputInstance = [RAInputResponder new];
|
||||||
|
|
||||||
|
return g_inputInstance;
|
||||||
|
}
|
||||||
|
|
||||||
-(id)init
|
-(id)init
|
||||||
{
|
{
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyPressed:) name: GSEventKeyDownNotification object:nil];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyPressed:) name: GSEventKeyDownNotification object:nil];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyReleased:) name: GSEventKeyUpNotification object:nil];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyReleased:) name: GSEventKeyUpNotification object:nil];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTouches:) name: RATouchNotification object:nil];
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +48,13 @@ extern NSString* const RATouchNotification;
|
|||||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)reset
|
||||||
|
{
|
||||||
|
_touchCount = 0;
|
||||||
|
memset(_touches, 0, sizeof(_touches));
|
||||||
|
memset(_keys, 0, sizeof(_keys));
|
||||||
|
}
|
||||||
|
|
||||||
- (void)poll
|
- (void)poll
|
||||||
{
|
{
|
||||||
for (int i = 0; i != _touchCount; i ++)
|
for (int i = 0; i != _touchCount; i ++)
|
||||||
@ -73,10 +88,8 @@ extern NSString* const RATouchNotification;
|
|||||||
if (keycode < MAX_KEYS) _keys[keycode] = false;
|
if (keycode < MAX_KEYS) _keys[keycode] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)handleTouches:(NSNotification*)notification
|
- (void)handleTouches:(NSArray*)touches
|
||||||
{
|
{
|
||||||
UIEvent* event = [notification.userInfo objectForKey:@"event"];
|
|
||||||
NSArray* touches = [[event allTouches] allObjects];
|
|
||||||
const int numTouches = [touches count];
|
const int numTouches = [touches count];
|
||||||
|
|
||||||
_touchCount = 0;
|
_touchCount = 0;
|
||||||
|
@ -31,9 +31,7 @@ static RAInputResponder* g_input_driver;
|
|||||||
static bool ios_key_pressed(enum retro_key key)
|
static bool ios_key_pressed(enum retro_key key)
|
||||||
{
|
{
|
||||||
if ((int)key >= 0 && key < RETROK_LAST)
|
if ((int)key >= 0 && key < RETROK_LAST)
|
||||||
{
|
|
||||||
return [g_input_driver isKeyPressed:input_translate_rk_to_keysym(key)];
|
return [g_input_driver isKeyPressed:input_translate_rk_to_keysym(key)];
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -46,8 +44,10 @@ static bool ios_is_pressed(unsigned port_num, const struct retro_keybind *key)
|
|||||||
// Exported input driver
|
// Exported input driver
|
||||||
static void *ios_input_init(void)
|
static void *ios_input_init(void)
|
||||||
{
|
{
|
||||||
|
g_input_driver = [RAInputResponder sharedInstance];
|
||||||
|
[g_input_driver reset];
|
||||||
|
|
||||||
input_init_keyboard_lut(rarch_key_map_hidusage);
|
input_init_keyboard_lut(rarch_key_map_hidusage);
|
||||||
g_input_driver = [RAInputResponder new];
|
|
||||||
return (void*)-1;
|
return (void*)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
#include "input/RAInputResponder.h"
|
||||||
|
|
||||||
#define GSEVENT_TYPE 2
|
#define GSEVENT_TYPE 2
|
||||||
#define GSEVENT_FLAGS 12
|
#define GSEVENT_FLAGS 12
|
||||||
@ -23,22 +24,28 @@
|
|||||||
|
|
||||||
NSString *const GSEventKeyDownNotification = @"GSEventKeyDownHackNotification";
|
NSString *const GSEventKeyDownNotification = @"GSEventKeyDownHackNotification";
|
||||||
NSString *const GSEventKeyUpNotification = @"GSEventKeyUpHackNotification";
|
NSString *const GSEventKeyUpNotification = @"GSEventKeyUpHackNotification";
|
||||||
NSString *const RATouchNotification = @"RATouchNotification";
|
|
||||||
|
static RAInputResponder* inputResponder;
|
||||||
|
|
||||||
@interface RApplication : UIApplication
|
@interface RApplication : UIApplication
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation RApplication
|
@implementation RApplication
|
||||||
|
|
||||||
|
- (RApplication*)init
|
||||||
|
{
|
||||||
|
self = [super init];
|
||||||
|
inputResponder = [RAInputResponder sharedInstance];
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)sendEvent:(UIEvent *)event
|
- (void)sendEvent:(UIEvent *)event
|
||||||
{
|
{
|
||||||
[super sendEvent:event];
|
[super sendEvent:event];
|
||||||
|
|
||||||
if ([[event allTouches] count])
|
if ([[event allTouches] count])
|
||||||
{
|
{
|
||||||
NSDictionary* inf = [[NSDictionary alloc] initWithObjectsAndKeys:
|
[inputResponder handleTouches:[[event allTouches] allObjects]];
|
||||||
event, @"event", nil];
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:RATouchNotification object:nil userInfo:inf];
|
|
||||||
}
|
}
|
||||||
// Stolen from: http://nacho4d-nacho4d.blogspot.com/2012/01/catching-keyboard-events-in-ios.html
|
// Stolen from: http://nacho4d-nacho4d.blogspot.com/2012/01/catching-keyboard-events-in-ios.html
|
||||||
else if ([event respondsToSelector:@selector(_gsEvent)])
|
else if ([event respondsToSelector:@selector(_gsEvent)])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user