(iOS) Cleanups

This commit is contained in:
twinaphex 2015-04-04 23:25:39 +02:00
parent 94c65d23e3
commit 38fe0d0119
2 changed files with 109 additions and 100 deletions

View File

@ -89,8 +89,8 @@ static void unzip_file(const char* path, const char* output_directory)
static void file_action(enum file_action action, NSString* source, NSString* target) static void file_action(enum file_action action, NSString* source, NSString* target)
{ {
NSError* error = nil; NSError* error = nil;
bool result = false; bool result = false;
NSFileManager* manager = [NSFileManager defaultManager]; NSFileManager* manager = [NSFileManager defaultManager];
switch (action) switch (action)
@ -122,8 +122,8 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
if (!item) if (!item)
return NULL; return NULL;
item.path = path; item.path = path;
item.isDirectory = path_is_directory(path.UTF8String); item.isDirectory = path_is_directory(path.UTF8String);
return item; return item;
} }
@ -135,24 +135,24 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
if (!item) if (!item)
return NULL; return NULL;
item.path = BOXSTRING(element->data); item.path = BOXSTRING(element->data);
item.isDirectory = (element->attr.i == RARCH_DIRECTORY); item.isDirectory = (element->attr.i == RARCH_DIRECTORY);
return item; return item;
} }
- (UITableViewCell*)cellForTableView:(UITableView *)tableView - (UITableViewCell*)cellForTableView:(UITableView *)tableView
{ {
static NSString* const cell_id = @"path_item"; static NSString* const cell_id = @"path_item";
static NSString* const icon_types[2] = { @"ic_file", @"ic_dir" }; static NSString* const icon_types[2] = { @"ic_file", @"ic_dir" };
uint32_t type_id = self.isDirectory ? 1 : 0; uint32_t type_id = self.isDirectory ? 1 : 0;
UITableViewCell* result = [tableView dequeueReusableCellWithIdentifier:cell_id]; UITableViewCell *result = [tableView dequeueReusableCellWithIdentifier:cell_id];
if (!result) if (!result)
result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_id]; result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_id];
result.textLabel.text = [self.path lastPathComponent]; result.textLabel.text = [self.path lastPathComponent];
result.imageView.image = [UIImage imageNamed:icon_types[type_id]]; result.imageView.image = [UIImage imageNamed:icon_types[type_id]];
return result; return result;
} }
@ -169,23 +169,24 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
@implementation RADirectoryList @implementation RADirectoryList
- (id)initWithPath:(NSString*)path extensions:(const char*)extensions action:(void (^)(RADirectoryList* list, RADirectoryItem* item))action - (id)initWithPath:(NSString*)path extensions:(const char*)extensions
action:(void (^)(RADirectoryList* list, RADirectoryItem* item))action
{ {
if ((self = [super initWithStyle:UITableViewStylePlain])) if ((self = [super initWithStyle:UITableViewStylePlain]))
{ {
self.path = path ? path : NSHomeDirectory(); NSMutableArray *toolbarButtons;
self.chooseAction = action; self.path = path ? path : NSHomeDirectory();
self.extensions = extensions ? BOXSTRING(extensions) : 0; self.chooseAction = action;
self.hidesHeaders = YES; self.extensions = extensions ? BOXSTRING(extensions) : 0;
self.hidesHeaders = YES;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:BOXSTRING("Up") style:UIBarButtonItemStyleBordered target:self self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:BOXSTRING("Up") style:UIBarButtonItemStyleBordered target:self
action:@selector(gotoParent)]; action:@selector(gotoParent)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self
action:@selector(cancelBrowser)]; action:@selector(cancelBrowser)];
// NOTE: The "App" and "Root" buttons aren't really needed for non-jailbreak devices. /* NOTE: The "App" and "Root" buttons aren't really needed for non-jailbreak devices. */
NSMutableArray* toolbarButtons = [NSMutableArray arrayWithObjects: toolbarButtons = [NSMutableArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithTitle:BOXSTRING("Home") style:UIBarButtonItemStyleBordered target:self [[UIBarButtonItem alloc] initWithTitle:BOXSTRING("Home") style:UIBarButtonItemStyleBordered target:self
action:@selector(gotoHomeDir)], action:@selector(gotoHomeDir)],
[[UIBarButtonItem alloc] initWithTitle:BOXSTRING("App") style:UIBarButtonItemStyleBordered target:self [[UIBarButtonItem alloc] initWithTitle:BOXSTRING("App") style:UIBarButtonItemStyleBordered target:self
@ -201,7 +202,7 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
nil nil
]; ];
self.toolbarItems = toolbarButtons; self.toolbarItems = toolbarButtons;
[self.tableView addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self [self.tableView addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(fileAction:)]]; action:@selector(fileAction:)]];
@ -242,19 +243,21 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
- (void)browseTo:(NSString*)path - (void)browseTo:(NSString*)path
{ {
settings_t *settings = config_get_ptr(); NSString *i;
struct string_list *contents = NULL;
settings_t *settings = config_get_ptr();
self.path = path; self.path = path;
self.title = self.path.lastPathComponent; self.title = self.path.lastPathComponent;
/* Need one array per section. */ /* Need one array per section. */
self.sections = [NSMutableArray array]; self.sections = [NSMutableArray array];
for (NSString* i in [self sectionIndexTitlesForTableView:self.tableView]) for (i in [self sectionIndexTitlesForTableView:self.tableView])
[self.sections addObject:[NSMutableArray arrayWithObject:i]]; [self.sections addObject:[NSMutableArray arrayWithObject:i]];
/* List contents */ /* List contents */
struct string_list *contents = dir_list_new(self.path.UTF8String, contents = dir_list_new(self.path.UTF8String,
settings->menu.navigation.browser.filter.supported_extensions_enable ? self.extensions.UTF8String : NULL, true); settings->menu.navigation.browser.filter.supported_extensions_enable ? self.extensions.UTF8String : NULL, true);
if (contents) if (contents)
@ -268,20 +271,16 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
if (self.forDirectory) if (self.forDirectory)
[self.sections[0] addObject:[RAMenuItemBasic itemWithDescription:BOXSTRING("[ Use This Folder ]") [self.sections[0] addObject:[RAMenuItemBasic itemWithDescription:BOXSTRING("[ Use This Folder ]")
action:^{ weakSelf.chooseAction(weakSelf, [RADirectoryItem directoryItemFromPath:path]); }]]; action:^{ weakSelf.chooseAction(weakSelf, [RADirectoryItem directoryItemFromPath:path]); }]];
dir_list_sort(contents, true); dir_list_sort(contents, true);
for (i = 0; i < contents->size; i ++) for (i = 0; i < contents->size; i ++)
{ {
const char* basename = path_basename(contents->elems[i].data); const char *basename = path_basename(contents->elems[i].data);
char is_directory = (contents->elems[i].attr.i == RARCH_DIRECTORY);
uint32_t section = is_directory ? 0 : isalpha(basename[0]) ? (toupper(basename[0]) - 'A') + 2 : 1;
uint32_t section = isalpha(basename[0]) ? (toupper(basename[0]) - 'A') + 2 : 1; if (! ( self.forDirectory && ! is_directory ))
char is_directory = (contents->elems[i].attr.i == RARCH_DIRECTORY); [self.sections[section] addObject:[RADirectoryItem directoryItemFromElement:&contents->elems[i]]];
section = is_directory ? 0 : section;
if (! ( self.forDirectory && ! is_directory )) {
[self.sections[section] addObject:[RADirectoryItem directoryItemFromElement:&contents->elems[i]]];
}
} }
dir_list_free(contents); dir_list_free(contents);
@ -317,23 +316,23 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
return names; return names;
} }
// File management /* File management
// Called as a selector from a toolbar button * Called as a selector from a toolbar button. */
- (void)createNewFolder - (void)createNewFolder
{ {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Enter new folder name") message:BOXSTRING("") delegate:self UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Enter new folder name") message:BOXSTRING("") delegate:self
cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil]; cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput; alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
alertView.tag = FA_CREATE; alertView.tag = FA_CREATE;
[alertView show]; [alertView show];
} }
// Called by the long press gesture recognizer /* Called by the long press gesture recognizer. */
- (void)fileAction:(UILongPressGestureRecognizer*)gesture - (void)fileAction:(UILongPressGestureRecognizer*)gesture
{ {
if (gesture.state == UIGestureRecognizerStateBegan) if (gesture.state == UIGestureRecognizerStateBegan)
{ {
CGPoint point = [gesture locationInView:self.tableView]; CGPoint point = [gesture locationInView:self.tableView];
NSIndexPath* idx_path = [self.tableView indexPathForRowAtPoint:point]; NSIndexPath* idx_path = [self.tableView indexPathForRowAtPoint:point];
if (idx_path) if (idx_path)
@ -343,12 +342,12 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
NSString *button4_name = (get_ios_version_major() >= 7) ? BOXSTRING("AirDrop") : BOXSTRING("Delete"); NSString *button4_name = (get_ios_version_major() >= 7) ? BOXSTRING("AirDrop") : BOXSTRING("Delete");
NSString *button5_name = (get_ios_version_major() >= 7) ? BOXSTRING("Delete") : nil; NSString *button5_name = (get_ios_version_major() >= 7) ? BOXSTRING("Delete") : nil;
self.selectedItem = [self itemForIndexPath:idx_path]; self.selectedItem = [self itemForIndexPath:idx_path];
is_zip = !(strcmp(self.selectedItem.path.pathExtension.UTF8String, "zip")); is_zip = !(strcmp(self.selectedItem.path.pathExtension.UTF8String, "zip"));
menu = [[UIActionSheet alloc] initWithTitle:self.selectedItem.path.lastPathComponent delegate:self menu = [[UIActionSheet alloc] initWithTitle:self.selectedItem.path.lastPathComponent delegate:self
cancelButtonTitle:BOXSTRING("Cancel") destructiveButtonTitle:nil cancelButtonTitle:BOXSTRING("Cancel") destructiveButtonTitle:nil
otherButtonTitles:is_zip ? BOXSTRING("Unzip") : BOXSTRING("Zip"), BOXSTRING("Move"), BOXSTRING("Rename"), button4_name, button5_name, nil]; otherButtonTitles:is_zip ? BOXSTRING("Unzip") : BOXSTRING("Zip"), BOXSTRING("Move"), BOXSTRING("Rename"), button4_name, button5_name, nil];
[menu showFromToolbar:self.navigationController.toolbar]; [menu showFromToolbar:self.navigationController.toolbar];
} }
@ -363,10 +362,10 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
if (!strcmp(action.UTF8String, "Unzip")) if (!strcmp(action.UTF8String, "Unzip"))
{ {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Enter target directory") message:@"" delegate:self UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Enter target directory") message:@"" delegate:self
cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil]; cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput; alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
alertView.tag = FA_UNZIP; alertView.tag = FA_UNZIP;
[alertView textFieldAtIndex:0].text = [[target lastPathComponent] stringByDeletingPathExtension]; [alertView textFieldAtIndex:0].text = [[target lastPathComponent] stringByDeletingPathExtension];
[alertView show]; [alertView show];
} }
@ -374,19 +373,20 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
[self.navigationController pushViewController:[[RAFoldersList alloc] initWithFilePath:target] animated:YES]; [self.navigationController pushViewController:[[RAFoldersList alloc] initWithFilePath:target] animated:YES];
else if (!strcmp(action.UTF8String, "Rename")) else if (!strcmp(action.UTF8String, "Rename"))
{ {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Enter new name") message:@"" delegate:self cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil]; UIAlertView* alertView = [[UIAlertView alloc]
alertView.alertViewStyle = UIAlertViewStylePlainTextInput; initWithTitle:BOXSTRING("Enter new name") message:@""
alertView.tag = FA_MOVE; delegate:self cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
alertView.tag = FA_MOVE;
[alertView textFieldAtIndex:0].text = target.lastPathComponent; [alertView textFieldAtIndex:0].text = target.lastPathComponent;
[alertView show]; [alertView show];
} }
#ifdef __IPHONE_7_0 #ifdef __IPHONE_7_0
else if (!strcmp(action.UTF8String, "AirDrop") && (get_ios_version_major() >= 7)) else if (!strcmp(action.UTF8String, "AirDrop") && (get_ios_version_major() >= 7))
{ {
// TODO: Zip if not already zipped /* TODO: ZIP if not already zipped. */
NSURL *url = [NSURL fileURLWithPath:self.selectedItem.path isDirectory:self.selectedItem.isDirectory];
NSURL* url = [NSURL fileURLWithPath:self.selectedItem.path isDirectory:self.selectedItem.isDirectory]; NSArray *items = [NSArray arrayWithObject:url];
NSArray* items = [NSArray arrayWithObject:url];
UIActivityViewController* avc = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil]; UIActivityViewController* avc = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[self presentViewController:avc animated:YES completion:nil]; [self presentViewController:avc animated:YES completion:nil];
@ -394,15 +394,16 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
#endif #endif
else if (!strcmp(action.UTF8String, "Delete")) else if (!strcmp(action.UTF8String, "Delete"))
{ {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Really delete?") message:@"" delegate:self cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil]; UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Really delete?") message:@"" delegate:self cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil];
alertView.tag = FA_DELETE; alertView.tag = FA_DELETE;
[alertView show]; [alertView show];
} }
else if (!strcmp(action.UTF8String, "Cancel")) /* Zip */ else if (!strcmp(action.UTF8String, "Cancel")) /* Zip */
apple_display_alert("Action not supported.", "Action Failed"); apple_display_alert("Action not supported.", "Action Failed");
} }
// Called by various alert views created in this class, the alertView.tag value is the action to take. /* Called by various alert views created in this class,
* the alertView.tag value is the action to take. */
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex - (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{ {
if (buttonIndex != alertView.firstOtherButtonIndex) if (buttonIndex != alertView.firstOtherButtonIndex)
@ -433,20 +434,23 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
{ {
if ((self = [super initWithStyle:UITableViewStyleGrouped])) if ((self = [super initWithStyle:UITableViewStyleGrouped]))
{ {
NSString *sourceItem;
RAMenuItemBasic *parentItem;
NSMutableArray *items;
struct string_list* contents;
RAFoldersList* __weak weakSelf = self; RAFoldersList* __weak weakSelf = self;
self.path = path; self.path = path;
// Parent item /* Parent item */
NSString* sourceItem = self.path.stringByDeletingLastPathComponent; sourceItem = self.path.stringByDeletingLastPathComponent;
RAMenuItemBasic* parentItem = [RAMenuItemBasic itemWithDescription:BOXSTRING("<Parent>") association:sourceItem.stringByDeletingLastPathComponent parentItem = [RAMenuItemBasic itemWithDescription:BOXSTRING("<Parent>") association:sourceItem.stringByDeletingLastPathComponent
action:^(id userdata){ [weakSelf moveInto:userdata]; } detail:NULL]; action:^(id userdata){ [weakSelf moveInto:userdata]; } detail:NULL];
[self.sections addObject:@[BOXSTRING(""), parentItem]]; [self.sections addObject:@[BOXSTRING(""), parentItem]];
/* List contents */
// List contents contents = dir_list_new([self.path stringByDeletingLastPathComponent].UTF8String, NULL, true);
struct string_list* contents = dir_list_new([self.path stringByDeletingLastPathComponent].UTF8String, NULL, true); items = [NSMutableArray arrayWithObject:BOXSTRING("")];
NSMutableArray* items = [NSMutableArray arrayWithObject:BOXSTRING("")];
if (contents) if (contents)
{ {
@ -457,19 +461,16 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
{ {
if (contents->elems[i].attr.i == RARCH_DIRECTORY) if (contents->elems[i].attr.i == RARCH_DIRECTORY)
{ {
const char* basename = path_basename(contents->elems[i].data); const char* basename = path_basename(contents->elems[i].data);
RAMenuItemBasic* item = [RAMenuItemBasic itemWithDescription:BOXSTRING(basename) association:BOXSTRING(contents->elems[i].data) RAMenuItemBasic* item = [RAMenuItemBasic itemWithDescription:BOXSTRING(basename) association:BOXSTRING(contents->elems[i].data)
action:^(id userdata){ [weakSelf moveInto:userdata]; } detail:NULL]; action:^(id userdata){ [weakSelf moveInto:userdata]; } detail:NULL];
[items addObject:item]; [items addObject:item];
} }
} }
dir_list_free(contents); dir_list_free(contents);
} }
[self setTitle:[BOXSTRING("Move ") stringByAppendingString: self.path.lastPathComponent]]; [self setTitle:[BOXSTRING("Move ") stringByAppendingString: self.path.lastPathComponent]];
[self.sections addObject:items]; [self.sections addObject:items];
} }

View File

@ -40,13 +40,13 @@ void main_exit_save_config(void);
static void rarch_draw(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) static void rarch_draw(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info)
{ {
runloop_t *runloop = rarch_main_get_ptr(); runloop_t *runloop = rarch_main_get_ptr();
int ret = 0; int ret = 0;
bool iterate = iterate_observer && !runloop->is_paused; bool iterate = iterate_observer && !runloop->is_paused;
if (!iterate) if (!iterate)
return; return;
ret = rarch_main_iterate(); ret = rarch_main_iterate();
if (ret == -1) if (ret == -1)
{ {
@ -83,15 +83,15 @@ int get_ios_version_major(void)
const void* apple_get_frontend_settings(void) const void* apple_get_frontend_settings(void)
{ {
static rarch_setting_t settings[9]; static rarch_setting_t settings[9];
if (settings[0].type == ST_NONE) if (settings[0].type == ST_NONE)
{ {
const char *GROUP_NAME = "Frontend Settings"; const char *GROUP_NAME = "Frontend Settings";
const char *SUBGROUP_NAME = "Frontend"; const char *SUBGROUP_NAME = "Frontend";
settings[0] = setting_group_setting(ST_GROUP, "Frontend Settings"); settings[0] = setting_group_setting(ST_GROUP, "Frontend Settings");
settings[1] = setting_group_setting(ST_SUB_GROUP, "Frontend"); settings[1] = setting_group_setting(ST_SUB_GROUP, "Frontend");
settings[2] = setting_string_setting(ST_STRING, "ios_btmode", "Bluetooth Input Type", apple_frontend_settings.bluetooth_mode, settings[2] = setting_string_setting(ST_STRING, "ios_btmode", "Bluetooth Input Type", apple_frontend_settings.bluetooth_mode,
sizeof(apple_frontend_settings.bluetooth_mode), "none", "<null>", GROUP_NAME, SUBGROUP_NAME, NULL, NULL); sizeof(apple_frontend_settings.bluetooth_mode), "none", "<null>", GROUP_NAME, SUBGROUP_NAME, NULL, NULL);
/* Set iOS_btmode options based on runtime environment. */ /* Set iOS_btmode options based on runtime environment. */
if (btstack_try_load()) if (btstack_try_load())
@ -100,12 +100,12 @@ const void* apple_get_frontend_settings(void)
settings[2].values = "icade|keyboard|small_keyboard"; settings[2].values = "icade|keyboard|small_keyboard";
settings[3] = setting_string_setting(ST_STRING, "ios_orientations", "Screen Orientations", apple_frontend_settings.orientations, settings[3] = setting_string_setting(ST_STRING, "ios_orientations", "Screen Orientations", apple_frontend_settings.orientations,
sizeof(apple_frontend_settings.orientations), "both", "<null>", GROUP_NAME, SUBGROUP_NAME, NULL, NULL); sizeof(apple_frontend_settings.orientations), "both", "<null>", GROUP_NAME, SUBGROUP_NAME, NULL, NULL);
settings[3].values = "both|landscape|portrait"; settings[3].values = "both|landscape|portrait";
settings[4] = setting_group_setting(ST_END_SUB_GROUP, 0); settings[4] = setting_group_setting(ST_END_SUB_GROUP, 0);
settings[5] = setting_group_setting(ST_END_GROUP, 0); settings[5] = setting_group_setting(ST_END_GROUP, 0);
} }
return settings; return settings;
} }
@ -114,7 +114,7 @@ extern float apple_gfx_ctx_get_native_scale(void);
/* Input helpers: This is kept here because it needs ObjC */ /* Input helpers: This is kept here because it needs ObjC */
static void handle_touch_event(NSArray* touches) static void handle_touch_event(NSArray* touches)
{ {
NSUInteger i; unsigned i;
driver_t *driver = driver_get_ptr(); driver_t *driver = driver_get_ptr();
apple_input_data_t *apple = (apple_input_data_t*)driver->input_data; apple_input_data_t *apple = (apple_input_data_t*)driver->input_data;
float scale = apple_gfx_ctx_get_native_scale(); float scale = apple_gfx_ctx_get_native_scale();
@ -126,7 +126,7 @@ static void handle_touch_event(NSArray* touches)
for (i = 0; i < touches.count && (apple->touch_count < MAX_TOUCHES); i++) for (i = 0; i < touches.count && (apple->touch_count < MAX_TOUCHES); i++)
{ {
UITouch* touch = [touches objectAtIndex:i]; UITouch *touch = [touches objectAtIndex:i];
if (touch.view != [RAGameView get].view) if (touch.view != [RAGameView get].view)
continue; continue;
@ -178,19 +178,20 @@ enum
- (id)_keyCommandForEvent:(UIEvent*)event - (id)_keyCommandForEvent:(UIEvent*)event
{ {
NSUInteger i; /* This gets called twice with the same timestamp
// This gets called twice with the same timestamp for each keypress, that's fine for polling * for each keypress, that's fine for polling
// but is bad for business with events. * but is bad for business with events. */
static double last_time_stamp; static double last_time_stamp;
if (last_time_stamp == event.timestamp) if (last_time_stamp == event.timestamp)
return [super _keyCommandForEvent:event]; return [super _keyCommandForEvent:event];
last_time_stamp = event.timestamp; last_time_stamp = event.timestamp;
// If the _hidEvent is null, [event _keyCode] will crash. (This happens with the on screen keyboard.) /* If the _hidEvent is null, [event _keyCode] will crash.
* (This happens with the on screen keyboard). */
if (event._hidEvent) if (event._hidEvent)
{ {
NSString* ch = (NSString*)event._privateInput; NSString *ch = (NSString*)event._privateInput;
uint32_t character = 0; uint32_t character = 0;
uint32_t mod = 0; uint32_t mod = 0;
@ -203,7 +204,9 @@ enum
if (ch && ch.length != 0) if (ch && ch.length != 0)
{ {
unsigned i;
character = [ch characterAtIndex:0]; character = [ch characterAtIndex:0];
apple_input_keyboard_event(event._isKeyDown, apple_input_keyboard_event(event._isKeyDown,
(uint32_t)event._keyCode, 0, mod, (uint32_t)event._keyCode, 0, mod,
RETRO_DEVICE_KEYBOARD); RETRO_DEVICE_KEYBOARD);
@ -228,19 +231,24 @@ enum
- (void)sendEvent:(UIEvent *)event - (void)sendEvent:(UIEvent *)event
{ {
[super sendEvent:event]; [super sendEvent:event];
if (event.allTouches.count) if (event.allTouches.count)
handle_touch_event(event.allTouches.allObjects); handle_touch_event(event.allTouches.allObjects);
if (!(get_ios_version_major() >= 7) && [event respondsToSelector:@selector(_gsEvent)]) if (!(get_ios_version_major() >= 7) && [event respondsToSelector:@selector(_gsEvent)])
{ {
// 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
const uint8_t* eventMem = objc_unretainedPointer([event performSelector:@selector(_gsEvent)]); const uint8_t *eventMem = objc_unretainedPointer([event performSelector:@selector(_gsEvent)]);
int eventType = eventMem ? *(int*)&eventMem[8] : 0; int eventType = eventMem ? *(int*)&eventMem[8] : 0;
if (eventType == GSEVENT_TYPE_KEYDOWN || eventType == GSEVENT_TYPE_KEYUP) switch (eventType)
apple_input_keyboard_event(eventType == GSEVENT_TYPE_KEYDOWN, {
*(uint16_t*)&eventMem[0x3C], 0, 0, RETRO_DEVICE_KEYBOARD); case GSEVENT_TYPE_KEYDOWN:
case GSEVENT_TYPE_KEYUP:
apple_input_keyboard_event(eventType == GSEVENT_TYPE_KEYDOWN,
*(uint16_t*)&eventMem[0x3C], 0, 0, RETRO_DEVICE_KEYBOARD);
break;
}
} }
} }
@ -278,15 +286,15 @@ void notify_content_loaded(void)
- (void)applicationDidFinishLaunching:(UIApplication *)application - (void)applicationDidFinishLaunching:(UIApplication *)application
{ {
driver_t *driver = NULL; driver_t *driver = NULL;
apple_platform = self;
apple_platform = self;
[self setDelegate:self]; [self setDelegate:self];
if (rarch_main(0, NULL)) if (rarch_main(0, NULL))
apple_rarch_exited(); apple_rarch_exited();
// Setup window /* Setup window */
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible]; [self.window makeKeyAndVisible];
[self pushViewController:[RAMainMenu new] animated:YES]; [self pushViewController:[RAMainMenu new] animated:YES];
@ -360,9 +368,9 @@ void notify_content_loaded(void)
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{ {
NSString* filename = (NSString*)url.path.lastPathComponent; NSString *filename = (NSString*)url.path.lastPathComponent;
NSError *error = nil;
NSError* error = nil;
[[NSFileManager defaultManager] moveItemAtPath:[url path] toPath:[self.documentsDirectory stringByAppendingPathComponent:filename] error:&error]; [[NSFileManager defaultManager] moveItemAtPath:[url path] toPath:[self.documentsDirectory stringByAppendingPathComponent:filename] error:&error];
if (error) if (error)