ios: Multi-touch support
This commit is contained in:
parent
cb484546b2
commit
5f5be7c4dc
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue