(OSX) More settings menu work

This commit is contained in:
meancoot 2013-08-26 00:37:17 -04:00
parent 2ef2b4e778
commit 54b672d6b7
2 changed files with 1058 additions and 352 deletions

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,50 @@
struct settings fake_settings;
struct global fake_extern;
static const void* associated_name_tag = (void*)&associated_name_tag;
@interface RASettingCell : NSTableCellView
@property (strong) NSString* stringValue;
@property (nonatomic) IBOutlet NSNumber* numericValue;
@property (nonatomic) bool booleanValue;
@property (nonatomic) const rarch_setting_t* setting;
@end
@implementation RASettingCell
- (void)setSetting:(const rarch_setting_t *)aSetting
{
_setting = aSetting;
switch (aSetting->type)
{
case ST_INT: self.numericValue = @(*(int*)aSetting->value); break;
case ST_FLOAT: self.numericValue = @(*(float*)aSetting->value); break;
case ST_STRING: self.stringValue = @((const char*)aSetting->value); break;
case ST_PATH: self.stringValue = @((const char*)aSetting->value); break;
case ST_BOOL: self.booleanValue = *(bool*)aSetting->value; break;
}
}
- (IBAction)doBrowse:(id)sender
{
NSOpenPanel* panel = [NSOpenPanel new];
[panel runModal];
if (panel.URLs.count == 1)
self.stringValue = panel.URL.path;
}
- (IBAction)valueChanged:(id)sender
{
printf("GABOR\n");
}
@end
@protocol RASettingView
@property const rarch_setting_t* setting;
@end
@interface RASettingsDelegate : NSObject<NSTableViewDataSource, NSTableViewDelegate,
NSOutlineViewDataSource, NSOutlineViewDelegate>
@end
@ -50,7 +94,7 @@ struct global fake_extern;
case ST_GROUP:
{
thisGroup = [NSMutableArray array];
objc_setAssociatedObject(thisGroup, "NAME", [NSString stringWithFormat:@"%s", setting_data[i].name], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(thisGroup, associated_name_tag, [NSString stringWithFormat:@"%s", setting_data[i].name], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
break;
}
@ -64,7 +108,7 @@ struct global fake_extern;
case ST_SUB_GROUP:
{
thisSubGroup = [NSMutableArray array];
objc_setAssociatedObject(thisSubGroup, "NAME", [NSString stringWithFormat:@"%s", setting_data[i].name], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(thisSubGroup, associated_name_tag, [NSString stringWithFormat:@"%s", setting_data[i].name], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
break;
}
@ -138,43 +182,11 @@ struct global fake_extern;
#pragma mark View Builders
- (NSView*)labelAccessoryFor:(NSString*)text onTable:(NSTableView*)table
{
NSTextField* result = [table makeViewWithIdentifier:@"label" owner:self];
if (result == nil)
{
result = [NSTextField new];
result.bordered = NO;
result.drawsBackground = NO;
result.identifier = @"label";
}
RASettingCell* result = [table makeViewWithIdentifier:@"RALabelSetting" owner:nil];
result.stringValue = text;
return result;
}
- (NSView*)booleanAccessoryFor:(const rarch_setting_t*)setting index:(NSNumber*)index onTable:(NSTableView*)table
{
NSButton* result = [table makeViewWithIdentifier:@"boolean" owner:self];
if (!result)
{
result = [NSButton new];
result.buttonType = NSSwitchButton;
result.title = @"";
result.target = self;
result.action = @selector(booleanChanged:);
}
result.state = *(bool*)setting->value;
objc_setAssociatedObject(result, "INDEX", index, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return result;
}
- (void)booleanChanged:(NSButton*)sender
{
int index = [objc_getAssociatedObject(sender, "INDEX") intValue];
*(bool*)setting_data[index].value = sender.state;
}
#pragma mark Section Table
- (NSInteger)numberOfRowsInTableView:(NSTableView*)view
{
@ -183,7 +195,7 @@ struct global fake_extern;
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
return [self labelAccessoryFor:objc_getAssociatedObject(_settings[row], "NAME") onTable:tableView];
return [self labelAccessoryFor:objc_getAssociatedObject(_settings[row], associated_name_tag) onTable:tableView];
}
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
@ -208,12 +220,16 @@ struct global fake_extern;
return [item isKindOfClass:[NSArray class]];
}
- (BOOL)validateProposedFirstResponder:(NSResponder *)responder forEvent:(NSEvent *)event {
return YES;
}
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
if ([item isKindOfClass:[NSArray class]])
{
if ([tableColumn.identifier isEqualToString:@"title"])
return [self labelAccessoryFor:objc_getAssociatedObject(item, "NAME") onTable:outlineView];
return [self labelAccessoryFor:objc_getAssociatedObject(item, associated_name_tag) onTable:outlineView];
else
return [self labelAccessoryFor:[NSString stringWithFormat:@"%d items", (int)[item count]] onTable:outlineView];
}
@ -222,25 +238,20 @@ struct global fake_extern;
const rarch_setting_t* setting = &setting_data[[item intValue]];
if ([tableColumn.identifier isEqualToString:@"title"])
return [self labelAccessoryFor:[NSString stringWithFormat:@"%s", setting->short_description] onTable:outlineView]; // < The outlineView will fill the value
return [self labelAccessoryFor:@(setting->short_description) onTable:outlineView];
else if([tableColumn.identifier isEqualToString:@"accessory"])
{
RASettingCell* s = nil;
switch (setting->type)
{
case ST_BOOL: return [self booleanAccessoryFor:setting index:item onTable:outlineView];
case ST_PATH:
case ST_STRING:
return [self labelAccessoryFor:[NSString stringWithFormat:@"%s", (const char*)setting->value] onTable:outlineView];
case ST_INT:
return [self labelAccessoryFor:[NSString stringWithFormat:@"%d", *(int*)setting->value] onTable:outlineView];
case ST_FLOAT:
return [self labelAccessoryFor:[NSString stringWithFormat:@"%f", *(float*)setting->value] onTable:outlineView];
default: abort();
case ST_BOOL: s = [outlineView makeViewWithIdentifier:@"RABooleanSetting" owner:nil]; break;
case ST_INT: s = [outlineView makeViewWithIdentifier:@"RANumericSetting" owner:nil]; break;
case ST_FLOAT: s = [outlineView makeViewWithIdentifier:@"RANumericSetting" owner:nil]; break;
case ST_PATH: s = [outlineView makeViewWithIdentifier:@"RAPathSetting" owner:nil]; break;
case ST_STRING: s = [outlineView makeViewWithIdentifier:@"RAStringSetting" owner:nil]; break;
}
s.setting = setting;
return s;
}
}