From 4d9233b02ab827c8c3a17abc1dde9bf21c086ffc Mon Sep 17 00:00:00 2001 From: meancoot Date: Fri, 8 Feb 2013 23:58:22 -0500 Subject: [PATCH] ios: Made things more simple. --- ios/RetroArch/RetroArch_iOS.h | 1 - ios/RetroArch/RetroArch_iOS.m | 9 ++---- ios/RetroArch/directory_list.m | 50 ++++++++++-------------------- ios/RetroArch/game_view.m | 47 +++++++++++++++------------- ios/RetroArch/module_list.m | 56 +++++++++------------------------- ios/RetroArch/views.h | 6 ++-- 6 files changed, 62 insertions(+), 107 deletions(-) diff --git a/ios/RetroArch/RetroArch_iOS.h b/ios/RetroArch/RetroArch_iOS.h index 3d55e4069e..8d137eab63 100644 --- a/ios/RetroArch/RetroArch_iOS.h +++ b/ios/RetroArch/RetroArch_iOS.h @@ -14,7 +14,6 @@ @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) NSString *module_path; @property (strong, nonatomic) UINavigationController *navigator; -@property (strong, nonatomic) NSString *nib_name; @property (strong, nonatomic) UIImage* file_icon; @property (strong, nonatomic) UIImage* folder_icon; @property (strong, nonatomic) UIBarButtonItem* settings_button; diff --git a/ios/RetroArch/RetroArch_iOS.m b/ios/RetroArch/RetroArch_iOS.m index f69f5c56e4..e10fd59b64 100644 --- a/ios/RetroArch/RetroArch_iOS.m +++ b/ios/RetroArch/RetroArch_iOS.m @@ -30,9 +30,6 @@ extern uint32_t ios_current_touch_count ; // TODO: Relocate this! self.system_directory = "/var/mobile/Library/RetroArch/"; mkdir(self.system_directory, 0755); - - bool is_iphone = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone; - self.nib_name = is_iphone ? @"ViewController_iPhone" : @"ViewController_iPad"; // Load icons self.file_icon = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ic_file" ofType:@"png"]]; @@ -44,9 +41,9 @@ extern uint32_t ios_current_touch_count ; style:UIBarButtonItemStyleBordered target:nil action:nil]; - - self.navigator = [[UINavigationController alloc] initWithNibName:self.nib_name bundle:nil]; - [self.navigator pushViewController: [[module_list alloc] initWithNibName:self.nib_name bundle:nil] animated:YES]; + // Setup window + self.navigator = [[UINavigationController alloc] init]; + [self.navigator pushViewController: [[module_list alloc] init] animated:YES]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = self.navigator; diff --git a/ios/RetroArch/directory_list.m b/ios/RetroArch/directory_list.m index 62aa9397a3..d3abc836ec 100644 --- a/ios/RetroArch/directory_list.m +++ b/ios/RetroArch/directory_list.m @@ -10,21 +10,18 @@ @implementation directory_list { - char* path; - - UITableView* table; + char* directory; struct dirent_list* files; }; -- (id)load_path:(const char*)directory +- (id)initWithPath:(const char*)path { - free_dirent_list(files); + self = [super initWithStyle:UITableViewStylePlain]; + + directory = strdup(path); files = build_dirent_list(directory); - [table reloadData]; - - free(path); - path = strdup(directory); - + + self.navigationItem.rightBarButtonItem = [RetroArch_iOS get].settings_button; [self setTitle: [[[NSString alloc] initWithUTF8String:directory] lastPathComponent]]; return self; @@ -33,20 +30,7 @@ - (void)dealloc { free_dirent_list(files); - free(path); -} - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) style:UITableViewStylePlain]; - table.dataSource = self; - table.delegate = self; - - self.navigationItem.rightBarButtonItem = [RetroArch_iOS get].settings_button; - - self.view = table; + free(directory); } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath @@ -56,20 +40,18 @@ if (!item) return; char new_path[4096]; - strcpy(new_path, path); - strcat(new_path, item->d_name); + snprintf(new_path, 4096, "%s/%s", directory, item->d_name); + new_path[4095] = 0; if (item->d_type) - { - strcat(new_path, "/"); - - [[RetroArch_iOS get].navigator pushViewController:[[[directory_list alloc] init] load_path: new_path] animated:YES]; + { + [[RetroArch_iOS get].navigator + pushViewController:[[directory_list alloc] initWithPath:new_path] + animated:YES]; } else { - [RetroArch_iOS get].window.rootViewController = [[game_view alloc] - initWithNibName: [RetroArch_iOS get].nib_name - bundle:nil]; + [RetroArch_iOS get].window.rootViewController = [[game_view alloc] init]; extern void ios_load_game(const char*); ios_load_game(new_path); @@ -83,7 +65,7 @@ - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell* cell = [table dequeueReusableCellWithIdentifier:@"path"]; + UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"path"]; cell = (cell != nil) ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"path"]; const struct dirent* item = get_dirent_at_index(files, indexPath.row); diff --git a/ios/RetroArch/game_view.m b/ios/RetroArch/game_view.m index ef16a371ea..dbdd2bd4b5 100644 --- a/ios/RetroArch/game_view.m +++ b/ios/RetroArch/game_view.m @@ -71,6 +71,31 @@ void ios_close_game() EAGLContext *gl_context; } +- (id)init +{ + self = [super init]; + + gl_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + [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]; + current_view = self; + + return self; +} + +- (void)dealloc +{ + if ([EAGLContext currentContext] == gl_context) [EAGLContext setCurrentContext:nil]; + gl_context = nil; + gl_view = nil; +} + + - (void)rarch_iterate:(id)sender { if (ra_initialized && !ra_done) @@ -86,28 +111,6 @@ void ios_close_game() } } -- (void)viewDidLoad -{ - [super viewDidLoad]; - - gl_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; - [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]; - current_view = self; -} - -- (void)dealloc -{ - if ([EAGLContext currentContext] == gl_context) [EAGLContext setCurrentContext:nil]; - gl_context = nil; - gl_view = nil; -} - @end void ios_flip_game_view() diff --git a/ios/RetroArch/module_list.m b/ios/RetroArch/module_list.m index 68ed5ee5a0..aab1416d28 100644 --- a/ios/RetroArch/module_list.m +++ b/ios/RetroArch/module_list.m @@ -8,55 +8,32 @@ @implementation module_list { - UITableView* table; - - NSString* module_dir; - NSMutableArray* modules; + NSArray* modules; }; -- (void)viewDidLoad +- (id)init { - [super viewDidLoad]; + self = [super initWithStyle:UITableViewStylePlain]; // Get the contents of the modules directory of the bundle. - module_dir = [NSString stringWithFormat:@"%@/%@", - [[NSBundle mainBundle] bundlePath], - @"modules"]; + NSString* module_dir = [NSString stringWithFormat:@"%@/%@", + [[NSBundle mainBundle] bundlePath], + @"modules"]; - NSArray *module_list = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:module_dir error:nil]; - - if (module_list == nil || [module_list count] == 0) - { - // TODO: Handle error! - } - - // Remove non .dylib files from the list - modules = [NSMutableArray arrayWithArray:module_list]; - for (int i = 0; i < [modules count];) - { - if (![[modules objectAtIndex:i] hasSuffix:@".dylib"]) - { - [modules removeObjectAtIndex:i]; - } - else - { - i ++; - } - } + modules = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:module_dir error:nil]; + modules = [module_dir stringsByAppendingPaths:modules]; + modules = [modules pathsMatchingExtensions:[NSArray arrayWithObject:@"dylib"]]; [self setTitle:@"Choose Emulator"]; - table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) style:UITableViewStylePlain]; - table.dataSource = self; - table.delegate = self; - self.view = table; - self.navigationItem.rightBarButtonItem = [RetroArch_iOS get].settings_button; + + return self; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - [RetroArch_iOS get].module_path = [NSString stringWithFormat:@"%@/%@", module_dir, [modules objectAtIndex:indexPath.row]]; - [[RetroArch_iOS get].navigator pushViewController:[[[directory_list alloc] init] load_path:"/"] animated:YES]; + [RetroArch_iOS get].module_path = [modules objectAtIndex:indexPath.row]; + [[RetroArch_iOS get].navigator pushViewController:[[directory_list alloc] initWithPath:"/"] animated:YES]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section @@ -66,13 +43,10 @@ - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell* cell = [table dequeueReusableCellWithIdentifier:@"module"]; + UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"module"]; cell = (cell != nil) ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"module"]; - if (modules) - { - cell.textLabel.text = [modules objectAtIndex:indexPath.row]; - } + cell.textLabel.text = [[modules objectAtIndex:indexPath.row] lastPathComponent]; return cell; } diff --git a/ios/RetroArch/views.h b/ios/RetroArch/views.h index 5b4f321ddd..aa712b18f1 100644 --- a/ios/RetroArch/views.h +++ b/ios/RetroArch/views.h @@ -5,10 +5,10 @@ @end -@interface module_list : UIViewController +@interface module_list : UITableViewController @end -@interface directory_list : UIViewController -- (id)load_path:(const char*)directory; +@interface directory_list : UITableViewController +- (id)initWithPath:(const char*)path; @end