(Apple) Style nits

This commit is contained in:
twinaphex 2014-04-26 03:58:07 +02:00
parent 2fc75bb4c5
commit 91faa161af
4 changed files with 80 additions and 60 deletions

View File

@ -34,20 +34,20 @@ static void* const associated_core_key = (void*)&associated_core_key;
{
[super sendEvent:event];
NSEventType event_type = [event type];
NSEventType event_type = event.type;
if (event_type == NSKeyDown || event_type == NSKeyUp)
{
NSString* ch = [event characters];
NSString* ch = (NSString*)event.characters;
if (!ch || [ch length] == 0)
apple_input_keyboard_event(event_type == NSKeyDown, [event keyCode], 0, 0);
if (!ch || ch.length == 0)
apple_input_keyboard_event(event_type == NSKeyDown, event.keyCode, 0, 0);
else
{
apple_input_keyboard_event(event_type == NSKeyDown, [event keyCode], [ch characterAtIndex:0], [event modifierFlags]);
apple_input_keyboard_event(event_type == NSKeyDown, event.keyCode, [ch characterAtIndex:0], event.modifierFlags);
for (unsigned i = 1; i != [ch length]; i ++)
apple_input_keyboard_event(event_type == NSKeyDown, 0, [ch characterAtIndex:i], [event modifierFlags]);
for (unsigned i = 1; i != ch.length; i ++)
apple_input_keyboard_event(event_type == NSKeyDown, 0, [ch characterAtIndex:i], event.modifierFlags);
}
}
else if (event_type == NSFlagsChanged)
@ -57,14 +57,14 @@ static void* const associated_core_key = (void*)&associated_core_key;
bool down = (new_flags & old_flags) == old_flags;
old_flags = new_flags;
apple_input_keyboard_event(down, [event keyCode], 0, [event modifierFlags]);
apple_input_keyboard_event(down, event.keyCode, 0, event.modifierFlags);
}
else if (event_type == NSMouseMoved || event_type == NSLeftMouseDragged ||
event_type == NSRightMouseDragged || event_type == NSOtherMouseDragged)
{
// Relative
g_current_input_data.mouse_delta[0] += [event deltaX];
g_current_input_data.mouse_delta[1] += [event deltaY];
g_current_input_data.mouse_delta[0] += event.deltaX;
g_current_input_data.mouse_delta[1] += event.deltaY;
// Absolute
NSPoint pos = [[RAGameView get] convertPoint:[event locationInWindow] fromView:nil];
@ -73,12 +73,12 @@ static void* const associated_core_key = (void*)&associated_core_key;
}
else if (event_type == NSLeftMouseDown || event_type == NSRightMouseDown || event_type == NSOtherMouseDown)
{
g_current_input_data.mouse_buttons |= 1 << [event buttonNumber];
g_current_input_data.mouse_buttons |= 1 << event.buttonNumber;
g_current_input_data.touch_count = 1;
}
else if (event_type == NSLeftMouseUp || event_type == NSRightMouseUp || event_type == NSOtherMouseUp)
{
g_current_input_data.mouse_buttons &= ~(1 << [event buttonNumber]);
g_current_input_data.mouse_buttons &= ~(1 << event.buttonNumber);
g_current_input_data.touch_count = 0;
}
}
@ -129,8 +129,8 @@ static char** waiting_argv;
apple_platform = self;
_loaded = true;
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
self.configDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"RetroArch"];
NSArray* paths = (NSArray*)NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
self.configDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:BOXSTRING("RetroArch")];
self.globalConfigFile = [NSString stringWithFormat:@"%@/retroarch.cfg", self.configDirectory];
self.coreDirectory = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Contents/Resources/modules"];
@ -152,12 +152,13 @@ static char** waiting_argv;
// Create core select list
NSComboBox* cb = (NSComboBox*)[[self.coreSelectSheet contentView] viewWithTag:1];
apple_core_info_set_core_path([self.coreDirectory UTF8String]);
apple_core_info_set_config_path([self.configDirectory UTF8String]);
const core_info_list_t* cores = apple_core_info_list_get();
apple_core_info_set_core_path(self.coreDirectory.UTF8String);
apple_core_info_set_config_path(self.configDirectory.UTF8String);
const core_info_list_t* cores = (const core_info_list_t*)apple_core_info_list_get();
for (int i = 0; cores && i != cores->count; i ++)
{
NSString* desc = BOXSTRING(cores->list[i].display_name);
NSString* desc = (NSString*)BOXSTRING(cores->list[i].display_name);
#if defined(MAC_OS_X_VERSION_10_6)
/* FIXME - Rewrite this so that this is no longer an associated object - requires ObjC 2.0 runtime */
objc_setAssociatedObject(desc, associated_core_key, apple_get_core_id(&cores->list[i]), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
@ -165,7 +166,7 @@ static char** waiting_argv;
[cb addItemWithObjectValue:desc];
}
if ([cb numberOfItems])
if (cb.numberOfItems)
[cb selectItemAtIndex:0];
else
apple_display_alert(BOXSTRING("No libretro cores were found.\nSelect \"Go->Cores Directory\" from the menu and place libretro dylib files there."), BOXSTRING("RetroArch"));
@ -233,9 +234,10 @@ static char** waiting_argv;
{
[[NSApplication sharedApplication] stopModal];
if (result == NSOKButton && [panel URL])
if (result == NSOKButton && panel.URL)
{
self.file = [[panel URL] path];
NSURL *url = (NSURL*)panel.URL;
self.file = url.path;
[self performSelector:@selector(chooseCore) withObject:nil afterDelay:.5f];
}
}];
@ -251,7 +253,7 @@ static char** waiting_argv;
_wantReload = apple_is_running;
if (!apple_is_running)
apple_run_core(self.core, [self.file UTF8String]);
apple_run_core(self.core, self.file.UTF8String);
else
apple_event_basic_command(QUIT);
}
@ -293,7 +295,7 @@ static char** waiting_argv;
[[NSApplication sharedApplication] terminate:nil];
if (_wantReload)
apple_run_core(self.core, [self.file UTF8String]);
apple_run_core(self.core, self.file.UTF8String);
else if(apple_use_tv_mode)
apple_run_core(nil, 0);
else

View File

@ -144,7 +144,7 @@ NSWindowDelegate>
setting_data_load_current();
const rarch_setting_t* setting_data = setting_data_get_list();
const rarch_setting_t *setting_data = (const rarch_setting_t *)setting_data_get_list();
for (int i = 0; setting_data[i].type; i ++)
{
@ -264,11 +264,11 @@ NSWindowDelegate>
{
#ifdef MAC_OS_X_VERSION_10_6
/* FIXME - Rewrite this so that this is no longer an associated object - requires ObjC 2.0 runtime */
if ([[tableColumn identifier] isEqualToString:@"left"])
if ([[tableColumn identifier] isEqualToString:BOXSTRING("left")])
return objc_getAssociatedObject(item, associated_name_tag);
else
#endif
return @"";
return BOXSTRING("");
}
else
{
@ -276,7 +276,7 @@ NSWindowDelegate>
const rarch_setting_t* setting = &setting_data[[item intValue]];
char buffer[PATH_MAX];
if ([[tableColumn identifier] isEqualToString:@"left"])
if ([[tableColumn identifier] isEqualToString:BOXSTRING("left")])
return BOXSTRING(setting->short_description);
else
{
@ -297,17 +297,20 @@ NSWindowDelegate>
if ([item isKindOfClass:[NSArray class]])
return [tableColumn dataCell];
if ([[tableColumn identifier] isEqualToString:@"left"])
if ([[tableColumn identifier] isEqualToString:BOXSTRING("left")])
return [tableColumn dataCell];
const rarch_setting_t* setting_data = setting_data_get_list();
const rarch_setting_t* setting = &setting_data[[item intValue]];
const rarch_setting_t* setting_data = (const rarch_setting_t *)setting_data_get_list();
const rarch_setting_t* setting = (const rarch_setting_t *)&setting_data[[item intValue]];
switch (setting->type)
{
case ST_BOOL: return self.booleanCell;
case ST_BIND: return self.binderCell;
default: return [tableColumn dataCell];
case ST_BOOL:
return self.booleanCell;
case ST_BIND:
return self.binderCell;
default:
return tableColumn.dataCell;
}
}
@ -319,14 +322,19 @@ NSWindowDelegate>
if ([item isKindOfClass:[NSNumber class]])
{
const rarch_setting_t* setting_data = setting_data_get_list();
const rarch_setting_t* setting = &setting_data[[item intValue]];
const rarch_setting_t* setting_data = (const rarch_setting_t*)setting_data_get_list();
const rarch_setting_t* setting = (const rarch_setting_t*)&setting_data[[item intValue]];
switch (setting->type)
{
case ST_BOOL: *setting->value.boolean = !*setting->value.boolean; return;
case ST_BIND: [self.binderWindow runForSetting:setting onWindow:[self.outline window]]; return;
default: return;
case ST_BOOL:
*setting->value.boolean = !*setting->value.boolean;
break;
case ST_BIND:
[self.binderWindow runForSetting:setting onWindow:[self.outline window]];
break;
default:
break;
}
}
}
@ -336,16 +344,17 @@ NSWindowDelegate>
{
if ([notification object] == self.outline)
{
NSText* editor = [[notification userInfo] objectForKey:@"NSFieldEditor"];
NSText* editor = [[notification userInfo] objectForKey:BOXSTRING("NSFieldEditor")];
id item = [self.outline itemAtRow:[self.outline selectedRow]];
if ([item isKindOfClass:[NSNumber class]])
{
const rarch_setting_t* setting_data = setting_data_get_list();
const rarch_setting_t* setting = &setting_data[[item intValue]];
const rarch_setting_t* setting_data = (const rarch_setting_t *)setting_data_get_list();
const rarch_setting_t* setting = (const rarch_setting_t*)&setting_data[[item intValue]];
NSString *editor_string = (NSString*)editor.string;
setting_data_set_with_string_representation(setting, [editor.string UTF8String]);
setting_data_set_with_string_representation(setting, editor_string.UTF8String);
}
}
}

View File

@ -35,15 +35,15 @@ void apple_core_info_set_config_path(const char* config_path)
*core_config_path = '\0';
}
core_info_list_t* apple_core_info_list_get(void)
core_info_list_t *apple_core_info_list_get(void)
{
if (!global_core_list)
RARCH_WARN("apple_core_info_list_get() called before apple_core_info_set_core_path()");
RARCH_WARN("core_info_list_get() called before core_info_set_core_path()");
return global_core_list;
}
const core_info_t* apple_core_info_list_get_by_id(const char* core_id)
const core_info_t *apple_core_info_list_get_by_id(const char* core_id)
{
if (core_id)
{
@ -57,7 +57,7 @@ const core_info_t* apple_core_info_list_get_by_id(const char* core_id)
return 0;
}
const char* apple_core_info_get_id(const core_info_t* info, char* buffer, size_t buffer_length)
const char *apple_core_info_get_id(const core_info_t* info, char* buffer, size_t buffer_length)
{
if (!buffer || !buffer_length)
return "";
@ -69,7 +69,7 @@ const char* apple_core_info_get_id(const core_info_t* info, char* buffer, size_t
return buffer;
}
const char* apple_core_info_get_custom_config(const char* core_id, char* buffer, size_t buffer_length)
const char *apple_core_info_get_custom_config(const char* core_id, char* buffer, size_t buffer_length)
{
if (!core_id || !buffer || !buffer_length)
return 0;
@ -81,10 +81,10 @@ const char* apple_core_info_get_custom_config(const char* core_id, char* buffer,
bool apple_core_info_has_custom_config(const char* core_id)
{
char path[PATH_MAX];
if (!core_id)
return false;
char path[PATH_MAX];
apple_core_info_get_custom_config(core_id, path, sizeof(path));
return path_file_exists(path);
}
@ -94,19 +94,28 @@ const char* apple_rom_history_get_path(rom_history_t* history, uint32_t index)
{
const char *path, *core_path, *core_name;
rom_history_get_index(history, index, &path, &core_path, &core_name);
return path ? path : "";
if (path)
return path;
return "";
}
const char* apple_rom_history_get_core_path(rom_history_t* history, uint32_t index)
const char *apple_rom_history_get_core_path(rom_history_t* history, uint32_t index)
{
const char *path, *core_path, *core_name;
rom_history_get_index(history, index, &path, &core_path, &core_name);
return core_path ? core_path : "";
if (core_path)
return core_path;
return "";
}
const char* apple_rom_history_get_core_name(rom_history_t* history, uint32_t index)
const char *apple_rom_history_get_core_name(rom_history_t* history, uint32_t index)
{
const char *path, *core_path, *core_name;
rom_history_get_index(history, index, &path, &core_path, &core_name);
return core_name ? core_name : "";
if (core_name)
return core_name;
return "";
}

View File

@ -24,16 +24,16 @@
void apple_display_alert(NSString* message, NSString* title)
{
#ifdef IOS
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:title ? title : @"RetroArch"
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:title ? title : BOXSTRING("RetroArch")
message:message
delegate:nil
cancelButtonTitle:@"OK"
cancelButtonTitle:BOXSTRING("OK")
otherButtonTitles:nil];
[alert show];
#else
NSAlert* alert = [[NSAlert new] autorelease];
[alert setMessageText:title ? title : @"RetroArch"];
[alert setMessageText:title ? title : BOXSTRING("RetroArch")];
[alert setInformativeText:message];
[alert setAlertStyle:NSInformationalAlertStyle];
[alert beginSheetModalForWindow:[RetroArch_OSX get].window
@ -91,14 +91,14 @@ NSString *apple_get_core_display_name(NSString *core_id)
{
bool hasDot = false;
if ([partialString length])
for (int i = 0; i != [partialString length]; i ++)
if (partialString.length)
for (int i = 0; i < partialString.length; i ++)
{
unichar ch = [partialString characterAtIndex:i];
if (i == 0 && (![self minimum] || [[self minimum] intValue] < 0) && ch == '-')
if (i == 0 && (!self.minimum || [[self minimum] intValue] < 0) && ch == '-')
continue;
else if ([self allowsFloats] && !hasDot && ch == '.')
else if (self.allowsFloats && !hasDot && ch == '.')
hasDot = true;
else if (!isdigit(ch))
return NO;