From dbc1758a990d0324d031ff5bf1205bc01fb259ec Mon Sep 17 00:00:00 2001 From: meancoot Date: Mon, 26 Aug 2013 14:05:16 -0400 Subject: [PATCH 1/3] (OSX) The settings panel now works --- apple/OSX/platform.h | 1 + apple/OSX/platform.m | 5 ++++ apple/OSX/settings.m | 60 ++++++++++++++++++++++++++++++++++++++------ 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/apple/OSX/platform.h b/apple/OSX/platform.h index b35cf774af..8078979caf 100644 --- a/apple/OSX/platform.h +++ b/apple/OSX/platform.h @@ -36,6 +36,7 @@ - (void)loadingCore:(RAModuleInfo*)core withFile:(const char*)file; - (void)unloadingCore:(RAModuleInfo*)core; +- (NSString*)configPath; @end diff --git a/apple/OSX/platform.m b/apple/OSX/platform.m index 1f21d5aae8..e263afbf4a 100644 --- a/apple/OSX/platform.m +++ b/apple/OSX/platform.m @@ -227,6 +227,11 @@ _wantReload = false; } +- (NSString*)configPath +{ + return [[self retroarchConfigPath] stringByAppendingPathComponent:@"retroarch.cfg"]; +} + - (NSString*)retroarchConfigPath { NSArray* paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); diff --git a/apple/OSX/settings.m b/apple/OSX/settings.m index e24d3bf7f9..3875346cbf 100644 --- a/apple/OSX/settings.m +++ b/apple/OSX/settings.m @@ -23,7 +23,7 @@ struct global fake_extern; static const void* associated_name_tag = (void*)&associated_name_tag; @interface RASettingCell : NSTableCellView -@property (strong) NSString* stringValue; +@property (nonatomic) NSString* stringValue; @property (nonatomic) IBOutlet NSNumber* numericValue; @property (nonatomic) bool booleanValue; @property (nonatomic) const rarch_setting_t* setting; @@ -34,6 +34,9 @@ static const void* associated_name_tag = (void*)&associated_name_tag; { _setting = aSetting; + if (!_setting) + return; + switch (aSetting->type) { case ST_INT: self.numericValue = @(*(int*)aSetting->value); break; @@ -53,9 +56,30 @@ static const void* associated_name_tag = (void*)&associated_name_tag; self.stringValue = panel.URL.path; } -- (IBAction)valueChanged:(id)sender +- (void)setNumericValue:(NSNumber *)numericValue { - printf("GABOR\n"); + _numericValue = numericValue; + + if (_setting && _setting->type == ST_INT) + *(int*)_setting->value = [_numericValue intValue]; + else if (_setting && _setting->type == ST_FLOAT) + *(float*)_setting->value = [_numericValue floatValue]; +} + +- (void)setBooleanValue:(bool)booleanValue +{ + _booleanValue = booleanValue; + + if (_setting && _setting->type == ST_BOOL) + *(bool*)_setting->value = _booleanValue; +} + +- (void)setStringValue:(NSString *)stringValue +{ + _stringValue = stringValue; + + if (_setting && (_setting->type == ST_STRING || _setting->type == ST_PATH)) + strlcpy(_setting->value, _stringValue.UTF8String, _setting->size); } @end @@ -127,14 +151,15 @@ static const void* associated_name_tag = (void*)&associated_name_tag; } } + [self load]; + [NSApplication.sharedApplication beginSheet:_window modalForWindow:RetroArch_OSX.get->window modalDelegate:nil didEndSelector:nil contextInfo:nil]; [NSApplication.sharedApplication runModalForWindow:_window]; } -- (IBAction)close:(id)sender +- (void)load { -#if 0 - config_file_t* conf = config_file_new(0); + config_file_t* conf = config_file_new([RetroArch_OSX get].configPath.UTF8String); for (int i = 0; setting_data[i].type; i ++) { switch (setting_data[i].type) @@ -149,7 +174,28 @@ static const void* associated_name_tag = (void*)&associated_name_tag; } } config_file_free(conf); -#endif +} + +- (IBAction)close:(id)sender +{ + config_file_t* conf = config_file_new(0); + for (int i = 0; setting_data[i].type; i ++) + { + switch (setting_data[i].type) + { + case ST_BOOL: config_set_bool (conf, setting_data[i].name, * (bool*)setting_data[i].value); break; + case ST_INT: config_set_int (conf, setting_data[i].name, * (int*)setting_data[i].value); break; + case ST_FLOAT: config_set_float (conf, setting_data[i].name, *(float*)setting_data[i].value); break; + case ST_PATH: config_set_string(conf, setting_data[i].name, (char*)setting_data[i].value); break; + case ST_STRING: config_set_string(conf, setting_data[i].name, (char*)setting_data[i].value); break; + case ST_HEX: break; + default: break; + } + } + config_file_write(conf, [RetroArch_OSX get].configPath.UTF8String); + config_file_free(conf); + + apple_refresh_config(); [NSApplication.sharedApplication stopModal]; [NSApplication.sharedApplication endSheet:_window returnCode:0]; From 29b8a6f8e4be9658dab4d031029b89447f184d44 Mon Sep 17 00:00:00 2001 From: meancoot Date: Mon, 26 Aug 2013 22:12:22 -0400 Subject: [PATCH 2/3] (OSX) Start keybind setting support --- apple/OSX/InputBinder.xib | 384 ++++++ apple/OSX/Settings.xib | 1115 ++++++++++------- apple/OSX/hid_pad.c | 6 +- apple/OSX/platform.m | 3 +- apple/OSX/settings.m | 163 ++- apple/RetroArch/setting_data.h | 87 +- apple/RetroArch_OSX.xcodeproj/project.pbxproj | 4 + 7 files changed, 1238 insertions(+), 524 deletions(-) create mode 100644 apple/OSX/InputBinder.xib diff --git a/apple/OSX/InputBinder.xib b/apple/OSX/InputBinder.xib new file mode 100644 index 0000000000..1dc324d900 --- /dev/null +++ b/apple/OSX/InputBinder.xib @@ -0,0 +1,384 @@ + + + + 1080 + 12E55 + 3084 + 1187.39 + 626.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 3084 + + + IBNSLayoutConstraint + NSButton + NSButtonCell + NSCustomObject + NSTextField + NSTextFieldCell + NSView + NSWindowTemplate + + + com.apple.InterfaceBuilder.CocoaPlugin + + + PluginDependencyRecalculationVersion + + + + + NSWindowController + + + FirstResponder + + + NSApplication + + + 15 + 2 + {{196, 240}, {480, 109}} + 544735232 + Window + RAInputBinder + + + + + 256 + + + + 268 + {{17, 72}, {446, 17}} + + + + _NS:1535 + YES + + 68157504 + 138413056 + Press a Key, Joystick Button, or move a Joystick Axis + + LucidaGrande + 13 + 1044 + + _NS:1535 + + + 6 + System + controlColor + + 3 + MC42NjY2NjY2NjY3AA + + + + 6 + System + controlTextColor + + 3 + MAA + + + + NO + + + + 268 + {{384, 13}, {82, 32}} + + + _NS:9 + YES + + 67108864 + 134217728 + Cancel + + _NS:9 + + -2038284288 + 129 + + + Gw + 200 + 25 + + NO + + + {480, 109} + + + + + {{0, 0}, {2560, 1418}} + {10000000000000, 10000000000000} + YES + + + + + + + window + + + + 3 + + + + goAway: + + + + 20 + + + + + + 0 + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 1 + + + + + + + + 2 + + + + + 4 + 0 + + 4 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 6 + 0 + + 6 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 3 + 0 + + 3 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 6 + 0 + + 6 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 5 + 0 + + 5 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + + + + + 4 + + + + + + + + 5 + + + + + 9 + + + + + 10 + + + + + 11 + + + + + 12 + + + + + + + + 13 + + + + + 14 + + + + + 15 + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{357, 418}, {480, 270}} + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + + + 20 + + + + + NSLayoutConstraint + NSObject + + IBProjectSource + ./Classes/NSLayoutConstraint.h + + + + RAInputBinder + NSWindow + + IBProjectSource + ./Classes/RAInputBinder.h + + + + + 0 + IBCocoaFramework + YES + 3 + YES + + diff --git a/apple/OSX/Settings.xib b/apple/OSX/Settings.xib index 4d9255c61f..03a3147273 100644 --- a/apple/OSX/Settings.xib +++ b/apple/OSX/Settings.xib @@ -36,7 +36,7 @@ - NSObject + NSWindowController FirstResponder @@ -45,11 +45,11 @@ NSApplication - 15 + 3 2 - {{196, 240}, {671, 597}} + {{196, 240}, {759, 597}} 544735232 - Window + RetroArch Settings NSWindow @@ -69,10 +69,10 @@ 256 - {148, 514} + {148, 555} - + _NS:13 YES NO @@ -176,7 +176,7 @@ 1 - {{1, 1}, {148, 514}} + {{1, 1}, {148, 555}} @@ -213,7 +213,7 @@ 0.99404761904761907 - {{20, 61}, {150, 516}} + {{20, 20}, {150, 557}} @@ -227,31 +227,6 @@ 4 1 - - - 268 - {{582, 13}, {75, 32}} - - - - _NS:9 - YES - - 67108864 - 134217728 - Close - - _NS:9 - - -2038284288 - 129 - - - 200 - 25 - - NO - 268 @@ -264,7 +239,7 @@ 256 - {471, 498} + {559, 539} @@ -273,10 +248,10 @@ NO YES - + 256 - {471, 17} - + {559, 17} + @@ -293,7 +268,7 @@ title - 101 + 276 16 1000 @@ -323,7 +298,7 @@ accessory - 364 + 277 40 1000 @@ -364,9 +339,10 @@ 0 1 NO + 4 - {{1, 17}, {471, 498}} + {{1, 17}, {559, 539}} @@ -386,29 +362,29 @@ NO _doScroller: - 0.99799599198396793 + 0.9721706864564007 -2147483392 - {{1, 499}, {471, 16}} + {{1, 541}, {486, 15}} - + _NS:60 NO 1 _doScroller: - 0.82055749128919864 + 0.55290102389078499 - + 2304 - {{1, 0}, {471, 17}} + {{1, 0}, {559, 17}} @@ -418,16 +394,16 @@ - {{178, 61}, {473, 516}} + {{178, 20}, {561, 557}} - + _NS:9 133682 - + QSAAAEEgAABCAAAAQgAAAA 0.25 @@ -435,7 +411,7 @@ 1 - {671, 597} + {759, 597} @@ -450,6 +426,22 @@ + + + window + + + + 422 + + + + delegate + + + + 356 + dataSource @@ -482,14 +474,6 @@ 104 - - - close: - - - - 122 - _outline @@ -524,7 +508,7 @@ 266 - {{0, 7}, {101, 17}} + {{0, 7}, {276, 17}} {250, 750} @@ -546,7 +530,7 @@ NO - {{1, 1}, {101, 30}} + {{1, 1}, {276, 30}} @@ -579,7 +563,7 @@ 266 - {{0, 7}, {364, 17}} + {{0, 7}, {277, 17}} {250, 750} @@ -596,7 +580,7 @@ NO - {{105, 1}, {364, 30}} + {{280, 1}, {277, 30}} @@ -629,7 +613,7 @@ 266 - {{0, 7}, {364, 17}} + {{0, 7}, {277, 17}} {250, 750} @@ -646,7 +630,7 @@ NO - {{105, 65}, {364, 30}} + {{280, 65}, {277, 30}} @@ -709,7 +693,7 @@ - {{105, 33}, {364, 30}} + {{280, 33}, {277, 30}} @@ -733,7 +717,7 @@ 266 - {{0, 7}, {320, 17}} + {{0, 7}, {233, 17}} {250, 750} @@ -752,9 +736,9 @@ 268 - {{319, -2}, {48, 32}} + {{232, -2}, {48, 32}} - + _NS:9 YES @@ -774,7 +758,7 @@ NO - {{105, 97}, {364, 30}} + {{280, 97}, {277, 30}} @@ -808,24 +792,24 @@ textField - + 274 - - + + 266 {{0, 7}, {145, 17}} - + {250, 750} YES - + 67108928 272631808 - + @@ -833,20 +817,20 @@ {{1, 1}, {145, 30}} - + - + 326 value: stringValue - - + + - - + + value: stringValue value stringValue @@ -855,6 +839,80 @@ 327 + + + doGetBind: + + + 274 + + + + 268 + {{232, -2}, {48, 32}} + + + _NS:9 + YES + + 67108864 + 134217728 + ... + + _NS:9 + + -2038284288 + 129 + + + 200 + 25 + + NO + + + + 266 + {{0, 7}, {233, 17}} + + + {250, 750} + YES + + 67108928 + 272631872 + + + + + + + NO + + + {{280, 129}, {277, 30}} + + + + + 564 + + + + value: stringValue + + + + + + value: stringValue + value + stringValue + 2 + + + 578 + @@ -894,29 +952,11 @@ 2 - - 4 0 - - 4 - 1 - - 20 - - 1000 - - 8 - 29 - 3 - - - - 3 - 0 4 1 @@ -925,22 +965,6 @@ 1000 - 6 - 24 - 3 - - - - 6 - 0 - - 6 - 1 - - 20 - - 1000 - 8 29 3 @@ -961,22 +985,6 @@ 29 3 - - - 4 - 0 - - 4 - 1 - - 0.0 - - 1000 - - 6 - 24 - 2 - 5 @@ -1025,6 +1033,22 @@ 29 3 + + + 4 + 0 + + 4 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + 5 @@ -1057,6 +1081,7 @@ 29 3 + @@ -1093,7 +1118,7 @@ - + @@ -1107,19 +1132,6 @@ - - 116 - - - - - - - - 117 - - - 148 @@ -1159,23 +1171,6 @@ - - 154 - - - - - - - - - - - - 155 - - - 156 @@ -1251,73 +1246,73 @@ - 169 - + 320 + - - - - 5 - 0 - - 5 - 1 - - 3 - - 1000 - - 8 - 29 - 3 - - - + + 10 0 - + 10 1 0.0 1000 - + 5 22 2 - - + + + 5 + 0 + + 5 + 1 + + 3 + + 1000 + + 8 + 29 + 3 + + + 6 0 - + 6 1 3 1000 - + 8 29 3 + - + - 170 - + 324 + - + - + - 171 - - + 325 + + 179 @@ -1325,73 +1320,210 @@ - 224 - + 353 + + + + + 276 + + + + + 272 + + + + + 271 + + + + + 267 + + + + + 354 + + + + + 273 + + + + + 268 + + + + + 317 + + + + + 281 + + + + + 280 + + + + + 323 + + + + + 322 + + + + + 321 + + + + + 154 + - - - + + + + + + + + + + + 328 + + + + + 5 + 0 + + 6 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + + + 6 0 - + 6 1 3 1000 - + 8 29 3 - - + + 10 0 - + 10 1 0.0 1000 - + 5 22 2 - - + + 5 0 - + 5 1 3 1000 - + 8 29 3 + + + 10 + 0 + + 10 + 1 + + 0.0 + + 1000 + + 6 + 24 + 2 + + + - 225 - + 335 + - + + + + 7 + 0 + + 0 + 1 + + 36 + + 1000 + + 3 + 9 + 1 + - + - 226 - - + 345 + + + + + 336 + + 242 @@ -1458,120 +1590,30 @@ - 250 - - - - - 267 - - - - - 268 - - - - - 269 - - - - - 270 - - - - - 271 - - - - - 272 - - - - - 273 - - - - - 274 - - - - - 275 - - - - - 276 - - - - - 280 - - - - - 281 - - - - - 285 - - - - - 287 - - - - - 288 - - - - - 289 - - + 291 + + 290 - - 291 - - - 292 - 293 - - - - - 294 - - + 250 + + 295 - + 5 0 @@ -1587,7 +1629,7 @@ 24 3 - + 6 0 @@ -1603,6 +1645,22 @@ 29 3 + + + 10 + 0 + + 10 + 1 + + 0.0 + + 1000 + + 5 + 22 + 2 + 10 @@ -1619,22 +1677,6 @@ 24 2 - - - 10 - 0 - - 10 - 1 - - 0.0 - - 1000 - - 5 - 22 - 2 - 5 @@ -1651,8 +1693,8 @@ 29 3 - + @@ -1669,11 +1711,6 @@ - - 300 - - - 303 @@ -1698,25 +1735,188 @@ - - 304 - - - - - 308 - - - 309 - 310 - - + 304 + + + + + 169 + + + + + + 5 + 0 + + 5 + 1 + + 3 + + 1000 + + 8 + 29 + 3 + + + + 10 + 0 + + 10 + 1 + + 0.0 + + 1000 + + 5 + 22 + 2 + + + + 6 + 0 + + 6 + 1 + + 3 + + 1000 + + 8 + 29 + 3 + + + + + + 170 + + + + + + + + 289 + + + + + 288 + + + + + 287 + + + + + 171 + + + + + 224 + + + + + + 6 + 0 + + 6 + 1 + + 3 + + 1000 + + 8 + 29 + 3 + + + + 10 + 0 + + 10 + 1 + + 0.0 + + 1000 + + 5 + 22 + 2 + + + + 5 + 0 + + 5 + 1 + + 3 + + 1000 + + 8 + 29 + 3 + + + + + + 225 + + + + + + + + 294 + + + + + 293 + + + + + 285 + + + + + 226 + + + + + 155 + + 311 @@ -1724,98 +1924,62 @@ - 316 - + 300 + - 317 - - + 476 + + - 320 - + 547 + + + + + 548 + + + + + 561 + + + + + 565 + - - - 10 - 0 - - 10 - 1 - - 0.0 - - 1000 - - 5 - 22 - 2 - - - - 5 - 0 - - 5 - 1 - - 3 - - 1000 - - 8 - 29 - 3 - - - - 6 - 0 - - 6 - 1 - - 3 - - 1000 - - 8 - 29 - 3 - - + - + - 321 - - + 566 + + - 322 - - + 574 + + - 323 - - + 575 + + - 324 - - - - - + 576 + + - 325 - - + 572 + + @@ -1826,9 +1990,6 @@ com.apple.InterfaceBuilder.CocoaPlugin {{357, 418}, {480, 270}} - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1847,6 +2008,7 @@ + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1873,16 +2035,14 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - + + - - - com.apple.InterfaceBuilder.CocoaPlugin @@ -1912,13 +2072,9 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1932,12 +2088,12 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin RASettingCell - + - - - + + + com.apple.InterfaceBuilder.CocoaPlugin RAPathSetting @@ -1951,17 +2107,14 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin RASettingCell - + com.apple.InterfaceBuilder.CocoaPlugin RALabelSetting @@ -1971,6 +2124,27 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + RASettingCell + + + + + + + + + com.apple.InterfaceBuilder.CocoaPlugin + RABindSetting + + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1980,16 +2154,26 @@ com.apple.InterfaceBuilder.CocoaPlugin - + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - 327 + 581 @@ -2004,20 +2188,6 @@ RASettingCell NSTableCellView - - id - id - - - - doBrowse: - id - - - valueChanged: - id - - numericValue NSNumber @@ -2037,23 +2207,16 @@ RASettingsDelegate NSObject - - close: - id - - - close: - - close: - id - - + NSWindow NSOutlineView NSTableView - NSWindow + + _inputWindow + NSWindow + _outline NSOutlineView @@ -2062,10 +2225,6 @@ _table NSTableView - - _window - NSWindow - IBProjectSource diff --git a/apple/OSX/hid_pad.c b/apple/OSX/hid_pad.c index 33bb819b9e..59904f8996 100644 --- a/apple/OSX/hid_pad.c +++ b/apple/OSX/hid_pad.c @@ -94,7 +94,7 @@ static void hid_device_attached(void* inContext, IOReturn inResult, void* inSend } IOHIDDeviceOpen(inDevice, kIOHIDOptionsTypeNone); - IOHIDDeviceScheduleWithRunLoop(inDevice, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); + IOHIDDeviceScheduleWithRunLoop(inDevice, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); IOHIDDeviceRegisterInputValueCallback(inDevice, hid_input_callback, context); } @@ -139,7 +139,7 @@ void osx_pad_init() IOHIDManagerRegisterDeviceMatchingCallback(g_hid_manager, hid_device_attached, 0); IOHIDManagerRegisterDeviceRemovalCallback(g_hid_manager, hid_device_removed, 0); - IOHIDManagerScheduleWithRunLoop(g_hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); + IOHIDManagerScheduleWithRunLoop(g_hid_manager, CFRunLoopGetMain(), kCFRunLoopCommonModes); IOHIDManagerOpen(g_hid_manager, kIOHIDOptionsTypeNone); } @@ -150,7 +150,7 @@ void osx_pad_quit() if (g_hid_manager) { IOHIDManagerClose(g_hid_manager, kIOHIDOptionsTypeNone); - IOHIDManagerUnscheduleFromRunLoop(g_hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); + IOHIDManagerUnscheduleFromRunLoop(g_hid_manager, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); CFRelease(g_hid_manager); } diff --git a/apple/OSX/platform.m b/apple/OSX/platform.m index e263afbf4a..41f1c6e516 100644 --- a/apple/OSX/platform.m +++ b/apple/OSX/platform.m @@ -251,7 +251,8 @@ - (IBAction)showPreferences:(id)sender { - [[[NSWindowController alloc] initWithWindowNibName:@"Settings"] window]; + NSWindowController* wc = [[NSWindowController alloc] initWithWindowNibName:@"Settings"]; + [NSApp runModalForWindow:wc.window]; } - (IBAction)basicEvent:(id)sender diff --git a/apple/OSX/settings.m b/apple/OSX/settings.m index 3875346cbf..5d248a2b26 100644 --- a/apple/OSX/settings.m +++ b/apple/OSX/settings.m @@ -16,17 +16,65 @@ #import #import "../RetroArch/RetroArch_Apple.h" #include "../RetroArch/setting_data.h" +#include "../RetroArch/apple_input.h" + +#include "driver.h" +#include "input/input_common.h" struct settings fake_settings; struct global fake_extern; static const void* associated_name_tag = (void*)&associated_name_tag; +#define BINDFOR(s) (*(struct retro_keybind*)(&s)->value) + +static const char* key_name_for_id(uint32_t hidkey) +{ + for (int i = 0; apple_key_name_map[i].hid_id; i ++) + if (apple_key_name_map[i].hid_id == hidkey) + return apple_key_name_map[i].keyname; + + return "nul"; +} + +static uint32_t key_id_for_name(const char* name) +{ + for (int i = 0; apple_key_name_map[i].hid_id; i ++) + if (strcmp(name, apple_key_name_map[i].keyname) == 0) + return apple_key_name_map[i].hid_id; + + return 0; +} + +#define key_name_for_rk(X) key_name_for_id(input_translate_rk_to_keysym(X)) +#define key_rk_for_name(X) input_translate_keysym_to_rk(key_id_for_name(X)) + +@interface RAInputBinder : NSWindow +@end + +@implementation RAInputBinder + +- (IBAction)goAway:(id)sender +{ + [NSApp endSheet:self]; + [self orderOut:nil]; +} + +// Stop the annoying sound when pressing a key +- (void)keyDown:(NSEvent*)theEvent +{ +} + +@end + @interface RASettingCell : NSTableCellView +@property (nonatomic) const rarch_setting_t* setting; + @property (nonatomic) NSString* stringValue; @property (nonatomic) IBOutlet NSNumber* numericValue; @property (nonatomic) bool booleanValue; -@property (nonatomic) const rarch_setting_t* setting; + +@property (nonatomic) NSTimer* bindTimer; @end @implementation RASettingCell @@ -44,6 +92,7 @@ static const void* associated_name_tag = (void*)&associated_name_tag; 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; + case ST_BIND: [self updateInputString]; break; } } @@ -61,9 +110,9 @@ static const void* associated_name_tag = (void*)&associated_name_tag; _numericValue = numericValue; if (_setting && _setting->type == ST_INT) - *(int*)_setting->value = [_numericValue intValue]; + *(int*)_setting->value = _numericValue.intValue; else if (_setting && _setting->type == ST_FLOAT) - *(float*)_setting->value = [_numericValue floatValue]; + *(float*)_setting->value = _numericValue.floatValue; } - (void)setBooleanValue:(bool)booleanValue @@ -82,6 +131,63 @@ static const void* associated_name_tag = (void*)&associated_name_tag; strlcpy(_setting->value, _stringValue.UTF8String, _setting->size); } +// Input Binding +- (void)updateInputString +{ + self.stringValue = [NSString stringWithFormat:@"[KB:%s] [JS:%lld] [AX:nul]", key_name_for_rk(BINDFOR(*_setting).key), + BINDFOR(*_setting).joykey]; +} + +- (void)dismissBinder +{ + [self.bindTimer invalidate]; + self.bindTimer = nil; + + [self updateInputString]; + + [(id)self.window.attachedSheet goAway:nil]; +} + +- (void)checkBind:(NSTimer*)send +{ + // Keyboard + for (int i = 0; apple_key_name_map[i].hid_id; i++) + { + if (g_current_input_data.keys[apple_key_name_map[i].hid_id]) + { + BINDFOR(*_setting).key = input_translate_keysym_to_rk(apple_key_name_map[i].hid_id); + [self dismissBinder]; + return; + } + } + + // Joystick + if (g_current_input_data.pad_buttons[0]) + { + for (int i = 0; i != 32; i ++) + { + if (g_current_input_data.pad_buttons[0] & (1 << i)) + { + BINDFOR(*_setting).joykey = i; + [self dismissBinder]; + return; + } + } + } +} + +- (IBAction)doGetBind:(id)sender +{ + static NSWindowController* controller; + if (!controller) + controller = [[NSWindowController alloc] initWithWindowNibName:@"InputBinder"]; + + self.bindTimer = [NSTimer timerWithTimeInterval:.1f target:self selector:@selector(checkBind:) userInfo:nil repeats:YES]; + [[NSRunLoop currentRunLoop] addTimer:self.bindTimer forMode:NSModalPanelRunLoopMode]; + + [NSApp beginSheet:controller.window modalForWindow:self.window modalDelegate:nil didEndSelector:nil contextInfo:nil]; +} + @end @protocol RASettingView @@ -89,12 +195,13 @@ static const void* associated_name_tag = (void*)&associated_name_tag; @end @interface RASettingsDelegate : NSObject + NSOutlineViewDataSource, NSOutlineViewDelegate, + NSWindowDelegate> @end @implementation RASettingsDelegate { - NSWindow IBOutlet* _window; + NSWindow IBOutlet* _inputWindow; NSTableView IBOutlet* _table; NSOutlineView IBOutlet* _outline; @@ -152,9 +259,6 @@ static const void* associated_name_tag = (void*)&associated_name_tag; } [self load]; - - [NSApplication.sharedApplication beginSheet:_window modalForWindow:RetroArch_OSX.get->window modalDelegate:nil didEndSelector:nil contextInfo:nil]; - [NSApplication.sharedApplication runModalForWindow:_window]; } - (void)load @@ -169,6 +273,12 @@ static const void* associated_name_tag = (void*)&associated_name_tag; case ST_FLOAT: config_set_float (conf, setting_data[i].name, *(float*)setting_data[i].value); break; case ST_PATH: config_set_string(conf, setting_data[i].name, (char*)setting_data[i].value); break; case ST_STRING: config_set_string(conf, setting_data[i].name, (char*)setting_data[i].value); break; + + case ST_BIND: input_config_parse_key(conf, "input_player1", input_config_bind_map[0].base, setting_data[i].value); + input_config_parse_joy_button(conf, "input_player1", input_config_bind_map[0].base, setting_data[i].value); + input_config_parse_joy_axis(conf, "input_player1", input_config_bind_map[0].base, setting_data[i].value); + break; + case ST_HEX: break; default: break; } @@ -176,7 +286,7 @@ static const void* associated_name_tag = (void*)&associated_name_tag; config_file_free(conf); } -- (IBAction)close:(id)sender +- (void)windowWillClose:(NSNotification *)notification { config_file_t* conf = config_file_new(0); for (int i = 0; setting_data[i].type; i ++) @@ -188,6 +298,13 @@ static const void* associated_name_tag = (void*)&associated_name_tag; case ST_FLOAT: config_set_float (conf, setting_data[i].name, *(float*)setting_data[i].value); break; case ST_PATH: config_set_string(conf, setting_data[i].name, (char*)setting_data[i].value); break; case ST_STRING: config_set_string(conf, setting_data[i].name, (char*)setting_data[i].value); break; + + case ST_BIND: + { + config_set_string(conf, setting_data[i].name, key_name_for_rk(BINDFOR(setting_data[i]).key)); + break; + } + case ST_HEX: break; default: break; } @@ -197,32 +314,7 @@ static const void* associated_name_tag = (void*)&associated_name_tag; apple_refresh_config(); - [NSApplication.sharedApplication stopModal]; - [NSApplication.sharedApplication endSheet:_window returnCode:0]; - [_window orderOut:nil]; -} - -- (void)readConfigFile:(const char*)path -{ - config_file_t* conf = config_file_new(path); - if (conf) - { - for (int i = 0; setting_data[i].type; i ++) - { - switch (setting_data[i].type) - { - case ST_BOOL: config_get_bool (conf, setting_data[i].name, (bool*)setting_data[i].value); break; - case ST_INT: config_get_int (conf, setting_data[i].name, (int*)setting_data[i].value); break; - case ST_FLOAT: config_get_float(conf, setting_data[i].name, (float*)setting_data[i].value); break; - case ST_PATH: config_get_array(conf, setting_data[i].name, (char*)setting_data[i].value, setting_data[i].size); break; - case ST_STRING: config_get_array(conf, setting_data[i].name, (char*)setting_data[i].value, setting_data[i].size); break; - case ST_HEX: break; - default: break; - } - } - - config_file_free(conf); - } + [NSApp stopModal]; } #pragma mark View Builders @@ -295,6 +387,7 @@ static const void* associated_name_tag = (void*)&associated_name_tag; 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; + case ST_BIND: s = [outlineView makeViewWithIdentifier:@"RABindSetting" owner:nil]; break; } s.setting = setting; return s; diff --git a/apple/RetroArch/setting_data.h b/apple/RetroArch/setting_data.h index 409c22e24b..a1faaddd44 100644 --- a/apple/RetroArch/setting_data.h +++ b/apple/RetroArch/setting_data.h @@ -18,8 +18,8 @@ #include "general.h" -enum setting_type { ST_NONE, ST_BOOL, ST_INT, ST_FLOAT, ST_PATH, ST_STRING, ST_HEX, ST_GROUP, ST_SUB_GROUP, - ST_END_GROUP, ST_END_SUB_GROUP }; +enum setting_type { ST_NONE, ST_BOOL, ST_INT, ST_FLOAT, ST_PATH, ST_STRING, ST_HEX, ST_BIND, + ST_GROUP, ST_SUB_GROUP, ST_END_GROUP, ST_END_SUB_GROUP }; typedef struct { @@ -52,14 +52,13 @@ extern struct global fake_extern; #define END_GROUP() { ST_END_GROUP }, #define START_SUB_GROUP(NAME) { ST_SUB_GROUP, NAME }, #define END_SUB_GROUP() { ST_END_SUB_GROUP }, -#define START_GROUP(NAME) { ST_GROUP, NAME, 0, 0, 0, 0, 0, 0, 0.0, 0.0, false }, -#define END_GROUP() { ST_END_GROUP, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0, false }, #define CONFIG_BOOL(TARGET, NAME, SHORT) { ST_BOOL, NAME, &TARGET, sizeof(TARGET), SHORT, 0, 0, 0, 0.0, 0.0, false }, #define CONFIG_INT(TARGET, NAME, SHORT) { ST_INT, NAME, &TARGET, sizeof(TARGET), SHORT, 0, 0, 0, 0.0, 0.0, false }, #define CONFIG_FLOAT(TARGET, NAME, SHORT) { ST_FLOAT, NAME, &TARGET, sizeof(TARGET), SHORT, 0, 0, 0, 0.0, 0.0, false }, #define CONFIG_PATH(TARGET, NAME, SHORT) { ST_PATH, NAME, &TARGET, sizeof(TARGET), SHORT, 0, 0, 0, 0.0, 0.0, false }, #define CONFIG_STRING(TARGET, NAME, SHORT) { ST_STRING, NAME, &TARGET, sizeof(TARGET), SHORT, 0, 0, 0, 0.0, 0.0, false }, #define CONFIG_HEX(TARGET, NAME, SHORT) { ST_HEX, NAME, &TARGET, sizeof(TARGET), SHORT, 0, 0, 0, 0.0, 0.0, false }, +#define CONFIG_BIND(TARGET, NAME, SHORT) { ST_BIND, NAME, &TARGET, sizeof(TARGET), SHORT }, const rarch_setting_t setting_data[] = { @@ -100,7 +99,6 @@ const rarch_setting_t setting_data[] = END_GROUP() - /*************/ /* EMULATION */ /*************/ @@ -183,6 +181,25 @@ const rarch_setting_t setting_data[] = CONFIG_INT(g_settings.input.icade_profile[3], "input_autodetect_icade_profile_pad4", "iCade 4") #endif END_SUB_GROUP() + + START_SUB_GROUP("Player 1") + CONFIG_BIND(g_settings.input.binds[0][ 0], "input_player1_b", "B button (down)") + CONFIG_BIND(g_settings.input.binds[0][ 1], "input_player1_y", "Y button (left)") + CONFIG_BIND(g_settings.input.binds[0][ 2], "input_player1_select", "Select button") + CONFIG_BIND(g_settings.input.binds[0][ 3], "input_player1_start", "Start button") + CONFIG_BIND(g_settings.input.binds[0][ 4], "input_player1_up", "Up D-pad") + CONFIG_BIND(g_settings.input.binds[0][ 5], "input_player1_down", "Down D-pad") + CONFIG_BIND(g_settings.input.binds[0][ 6], "input_player1_left", "Left D-pad") + CONFIG_BIND(g_settings.input.binds[0][ 7], "input_player1_right", "Right D-pad") + CONFIG_BIND(g_settings.input.binds[0][ 8], "input_player1_a", "A button (right)") + CONFIG_BIND(g_settings.input.binds[0][ 9], "input_player1_x", "X button (top)") + CONFIG_BIND(g_settings.input.binds[0][10], "input_player1_l", "L button (left shoulder)") + CONFIG_BIND(g_settings.input.binds[0][11], "input_player1_r", "R button (right shoulder)") + CONFIG_BIND(g_settings.input.binds[0][12], "input_player1_l2", "L2 button (left shoulder #2)") + CONFIG_BIND(g_settings.input.binds[0][13], "input_player1_r2", "R2 button (right shoulder #2)") + CONFIG_BIND(g_settings.input.binds[0][14], "input_player1_l3", "L3 button (left analog button)") + CONFIG_BIND(g_settings.input.binds[0][15], "input_player1_r3", "R3 button (right analog button)") + END_SUB_GROUP() END_GROUP() /*********/ @@ -275,7 +292,63 @@ const rarch_setting_t setting_data[] = }; // HACK -#undef g_settings fake_settings -#undef g_extern fake_extern +#undef g_settings +#undef g_extern + +// Keyboard +#include "keycode.h" +static const struct +{ + const char* const keyname; + const uint32_t hid_id; +} apple_key_name_map[] = { + { "left", KEY_Left }, { "right", KEY_Right }, + { "up", KEY_Up }, { "down", KEY_Down }, + { "enter", KEY_Enter }, { "kp_enter", KP_Enter }, + { "space", KEY_Space }, { "tab", KEY_Tab }, + { "shift", KEY_LeftShift }, { "rshift", KEY_RightShift }, + { "ctrl", KEY_LeftControl }, { "alt", KEY_LeftAlt }, + { "escape", KEY_Escape }, { "backspace", KEY_DeleteForward }, + { "backquote", KEY_Grave }, { "pause", KEY_Pause }, + + { "f1", KEY_F1 }, { "f2", KEY_F2 }, + { "f3", KEY_F3 }, { "f4", KEY_F4 }, + { "f5", KEY_F5 }, { "f6", KEY_F6 }, + { "f7", KEY_F7 }, { "f8", KEY_F8 }, + { "f9", KEY_F9 }, { "f10", KEY_F10 }, + { "f11", KEY_F11 }, { "f12", KEY_F12 }, + + { "num0", KEY_0 }, { "num1", KEY_1 }, + { "num2", KEY_2 }, { "num3", KEY_3 }, + { "num4", KEY_4 }, { "num5", KEY_5 }, + { "num6", KEY_6 }, { "num7", KEY_7 }, + { "num8", KEY_8 }, { "num9", KEY_9 }, + + { "insert", KEY_Insert }, { "del", KEY_DeleteForward }, + { "home", KEY_Home }, { "end", KEY_End }, + { "pageup", KEY_PageUp }, { "pagedown", KEY_PageDown }, + + { "add", KP_Add }, { "subtract", KP_Subtract }, + { "multiply", KP_Multiply }, { "divide", KP_Divide }, + { "keypad0", KP_0 }, { "keypad1", KP_1 }, + { "keypad2", KP_2 }, { "keypad3", KP_3 }, + { "keypad4", KP_4 }, { "keypad5", KP_5 }, + { "keypad6", KP_6 }, { "keypad7", KP_7 }, + { "keypad8", KP_8 }, { "keypad9", KP_9 }, + + { "period", KEY_Period }, { "capslock", KEY_CapsLock }, + { "numlock", KP_NumLock }, { "print_screen", KEY_PrintScreen }, + { "scroll_lock", KEY_ScrollLock }, + + { "a", KEY_A }, { "b", KEY_B }, { "c", KEY_C }, { "d", KEY_D }, + { "e", KEY_E }, { "f", KEY_F }, { "g", KEY_G }, { "h", KEY_H }, + { "i", KEY_I }, { "j", KEY_J }, { "k", KEY_K }, { "l", KEY_L }, + { "m", KEY_M }, { "n", KEY_N }, { "o", KEY_O }, { "p", KEY_P }, + { "q", KEY_Q }, { "r", KEY_R }, { "s", KEY_S }, { "t", KEY_T }, + { "u", KEY_U }, { "v", KEY_V }, { "w", KEY_W }, { "x", KEY_X }, + { "y", KEY_Y }, { "z", KEY_Z }, + + { "nul", 0x00}, +}; #endif \ No newline at end of file diff --git a/apple/RetroArch_OSX.xcodeproj/project.pbxproj b/apple/RetroArch_OSX.xcodeproj/project.pbxproj index 67e0df9ae7..c67900681c 100644 --- a/apple/RetroArch_OSX.xcodeproj/project.pbxproj +++ b/apple/RetroArch_OSX.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 962EE0E2178B3DF6004224FF /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 962EE0E1178B3DF6004224FF /* IOKit.framework */; }; 96355CE31788E72A0010DBFA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96355CE21788E72A0010DBFA /* Cocoa.framework */; }; 9646869817BBC14E00C5EA69 /* platform.m in Sources */ = {isa = PBXBuildFile; fileRef = 9646869617BBC14E00C5EA69 /* platform.m */; }; + 965A44C817CC114D0086F78F /* InputBinder.xib in Resources */ = {isa = PBXBuildFile; fileRef = 965A44C717CC114D0086F78F /* InputBinder.xib */; }; 967894931788ECDB00D6CA69 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9678948F1788ECDB00D6CA69 /* InfoPlist.strings */; }; 967894941788ECDB00D6CA69 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 967894911788ECDB00D6CA69 /* MainMenu.xib */; }; 967894961788ED1100D6CA69 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 967894951788ED1100D6CA69 /* main.m */; }; @@ -38,6 +39,7 @@ 96355CE71788E72A0010DBFA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 9646869617BBC14E00C5EA69 /* platform.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = platform.m; path = OSX/platform.m; sourceTree = SOURCE_ROOT; }; 9646869717BBC14E00C5EA69 /* platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = platform.h; path = OSX/platform.h; sourceTree = SOURCE_ROOT; }; + 965A44C717CC114D0086F78F /* InputBinder.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = InputBinder.xib; path = OSX/InputBinder.xib; sourceTree = ""; }; 9678948D1788ECCA00D6CA69 /* RetroArch-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "RetroArch-Info.plist"; path = "OSX/RetroArch-Info.plist"; sourceTree = SOURCE_ROOT; }; 967894901788ECDB00D6CA69 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = OSX/en.lproj/InfoPlist.strings; sourceTree = SOURCE_ROOT; }; 967894921788ECDB00D6CA69 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = OSX/en.lproj/MainMenu.xib; sourceTree = SOURCE_ROOT; }; @@ -144,6 +146,7 @@ 967894911788ECDB00D6CA69 /* MainMenu.xib */, C15874EE178F2094001171D4 /* RetroArch.icns */, 9620F6641790004F001B3B81 /* Settings.xib */, + 965A44C717CC114D0086F78F /* InputBinder.xib */, ); name = Assets; sourceTree = ""; @@ -203,6 +206,7 @@ 967894E9178A2EB400D6CA69 /* modules in Resources */, C15874EF178F2094001171D4 /* RetroArch.icns in Resources */, 9620F6651790004F001B3B81 /* Settings.xib in Resources */, + 965A44C817CC114D0086F78F /* InputBinder.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; From 253bb88bfce016c981530eb352f27898e0be26c5 Mon Sep 17 00:00:00 2001 From: meancoot Date: Mon, 26 Aug 2013 23:56:26 -0400 Subject: [PATCH 3/3] (OSX) More settings menu work (now supports all input bindings for player 1) --- apple/OSX/settings.m | 86 ++++++++++++++++++++++++++++------ apple/RetroArch/setting_data.h | 60 ++++++++++++++---------- 2 files changed, 105 insertions(+), 41 deletions(-) diff --git a/apple/OSX/settings.m b/apple/OSX/settings.m index 5d248a2b26..1bf695befc 100644 --- a/apple/OSX/settings.m +++ b/apple/OSX/settings.m @@ -49,6 +49,40 @@ static uint32_t key_id_for_name(const char* name) #define key_name_for_rk(X) key_name_for_id(input_translate_rk_to_keysym(X)) #define key_rk_for_name(X) input_translate_keysym_to_rk(key_id_for_name(X)) +static const char* get_input_config_key(const rarch_setting_t* setting, const char* type) +{ + static char buffer[32]; + snprintf(buffer, 32, "input_player%d_%s%c%s", setting->input_player, setting->name, type ? '_' : '\0', type); + return buffer; +} + +static const char* get_button_name(const rarch_setting_t* setting) +{ + static char buffer[32]; + + if (BINDFOR(*setting).joykey == NO_BTN) + return "nul"; + + snprintf(buffer, 32, "%lld", BINDFOR(*setting).joykey); + return buffer; +} + +static const char* get_axis_name(const rarch_setting_t* setting) +{ + static char buffer[32]; + + uint32_t joyaxis = BINDFOR(*setting).joyaxis; + + if (AXIS_NEG_GET(joyaxis) != AXIS_DIR_NONE) + snprintf(buffer, 8, "-%d", AXIS_NEG_GET(joyaxis)); + else if (AXIS_POS_GET(joyaxis) != AXIS_DIR_NONE) + snprintf(buffer, 8, "+%d", AXIS_POS_GET(joyaxis)); + else + return "nul"; + + return buffer; +} + @interface RAInputBinder : NSWindow @end @@ -134,8 +168,9 @@ static uint32_t key_id_for_name(const char* name) // Input Binding - (void)updateInputString { - self.stringValue = [NSString stringWithFormat:@"[KB:%s] [JS:%lld] [AX:nul]", key_name_for_rk(BINDFOR(*_setting).key), - BINDFOR(*_setting).joykey]; + self.stringValue = [NSString stringWithFormat:@"[KB:%s] [JS:%s] [AX:%s]", key_name_for_rk(BINDFOR(*_setting).key), + get_button_name(_setting), + get_axis_name(_setting)]; } - (void)dismissBinder @@ -174,6 +209,19 @@ static uint32_t key_id_for_name(const char* name) } } } + + // Pad Axis + for (int i = 0; i < 4; i++) + { + int16_t value = g_current_input_data.pad_axis[0][i]; + + if (abs(value) > 0x4000) + { + BINDFOR(*_setting).joyaxis = (value > 0x1000) ? AXIS_POS(i) : AXIS_NEG(i); + [self dismissBinder]; + break; + } + } } - (IBAction)doGetBind:(id)sender @@ -214,10 +262,10 @@ static uint32_t key_id_for_name(const char* name) NSMutableArray* thisGroup = nil; NSMutableArray* thisSubGroup = nil; _settings = [NSMutableArray array]; - + memcpy(&fake_settings, &g_settings, sizeof(struct settings)); memcpy(&fake_extern, &g_extern, sizeof(struct global)); - + for (int i = 0; setting_data[i].type; i ++) { switch (setting_data[i].type) @@ -264,20 +312,24 @@ static uint32_t key_id_for_name(const char* name) - (void)load { config_file_t* conf = config_file_new([RetroArch_OSX get].configPath.UTF8String); + for (int i = 0; setting_data[i].type; i ++) { switch (setting_data[i].type) { - case ST_BOOL: config_set_bool (conf, setting_data[i].name, * (bool*)setting_data[i].value); break; - case ST_INT: config_set_int (conf, setting_data[i].name, * (int*)setting_data[i].value); break; - case ST_FLOAT: config_set_float (conf, setting_data[i].name, *(float*)setting_data[i].value); break; - case ST_PATH: config_set_string(conf, setting_data[i].name, (char*)setting_data[i].value); break; - case ST_STRING: config_set_string(conf, setting_data[i].name, (char*)setting_data[i].value); break; + case ST_BOOL: config_get_bool (conf, setting_data[i].name, (bool*)setting_data[i].value); break; + case ST_INT: config_get_int (conf, setting_data[i].name, (int*)setting_data[i].value); break; + case ST_FLOAT: config_get_float (conf, setting_data[i].name, (float*)setting_data[i].value); break; + case ST_PATH: config_get_array (conf, setting_data[i].name, (char*)setting_data[i].value, setting_data[i].size); break; + case ST_STRING: config_get_array (conf, setting_data[i].name, (char*)setting_data[i].value, setting_data[i].size); break; - case ST_BIND: input_config_parse_key(conf, "input_player1", input_config_bind_map[0].base, setting_data[i].value); - input_config_parse_joy_button(conf, "input_player1", input_config_bind_map[0].base, setting_data[i].value); - input_config_parse_joy_axis(conf, "input_player1", input_config_bind_map[0].base, setting_data[i].value); - break; + case ST_BIND: + { + input_config_parse_key (conf, "input_player1", setting_data[i].name, setting_data[i].value); + input_config_parse_joy_button(conf, "input_player1", setting_data[i].name, setting_data[i].value); + input_config_parse_joy_axis (conf, "input_player1", setting_data[i].name, setting_data[i].value); + break; + } case ST_HEX: break; default: break; @@ -288,7 +340,9 @@ static uint32_t key_id_for_name(const char* name) - (void)windowWillClose:(NSNotification *)notification { - config_file_t* conf = config_file_new(0); + config_file_t* conf = config_file_new([RetroArch_OSX get].configPath.UTF8String); + conf = conf ? conf : config_file_new(0); + for (int i = 0; setting_data[i].type; i ++) { switch (setting_data[i].type) @@ -301,7 +355,9 @@ static uint32_t key_id_for_name(const char* name) case ST_BIND: { - config_set_string(conf, setting_data[i].name, key_name_for_rk(BINDFOR(setting_data[i]).key)); + config_set_string(conf, get_input_config_key(&setting_data[i], 0 ), key_name_for_rk(BINDFOR(setting_data[i]).key)); + config_set_string(conf, get_input_config_key(&setting_data[i], "btn" ), get_button_name(&setting_data[i])); + config_set_string(conf, get_input_config_key(&setting_data[i], "axis"), get_axis_name(&setting_data[i])); break; } diff --git a/apple/RetroArch/setting_data.h b/apple/RetroArch/setting_data.h index a1faaddd44..3fcac23459 100644 --- a/apple/RetroArch/setting_data.h +++ b/apple/RetroArch/setting_data.h @@ -31,11 +31,9 @@ typedef struct uint32_t size; const char* short_description; - const char* long_description; - - const char** values; uint32_t input_player; + double min; double max; bool allow_blank; @@ -52,13 +50,14 @@ extern struct global fake_extern; #define END_GROUP() { ST_END_GROUP }, #define START_SUB_GROUP(NAME) { ST_SUB_GROUP, NAME }, #define END_SUB_GROUP() { ST_END_SUB_GROUP }, -#define CONFIG_BOOL(TARGET, NAME, SHORT) { ST_BOOL, NAME, &TARGET, sizeof(TARGET), SHORT, 0, 0, 0, 0.0, 0.0, false }, -#define CONFIG_INT(TARGET, NAME, SHORT) { ST_INT, NAME, &TARGET, sizeof(TARGET), SHORT, 0, 0, 0, 0.0, 0.0, false }, -#define CONFIG_FLOAT(TARGET, NAME, SHORT) { ST_FLOAT, NAME, &TARGET, sizeof(TARGET), SHORT, 0, 0, 0, 0.0, 0.0, false }, -#define CONFIG_PATH(TARGET, NAME, SHORT) { ST_PATH, NAME, &TARGET, sizeof(TARGET), SHORT, 0, 0, 0, 0.0, 0.0, false }, -#define CONFIG_STRING(TARGET, NAME, SHORT) { ST_STRING, NAME, &TARGET, sizeof(TARGET), SHORT, 0, 0, 0, 0.0, 0.0, false }, -#define CONFIG_HEX(TARGET, NAME, SHORT) { ST_HEX, NAME, &TARGET, sizeof(TARGET), SHORT, 0, 0, 0, 0.0, 0.0, false }, -#define CONFIG_BIND(TARGET, NAME, SHORT) { ST_BIND, NAME, &TARGET, sizeof(TARGET), SHORT }, +#define CONFIG_BOOL(TARGET, NAME, SHORT) { ST_BOOL, NAME, &TARGET, sizeof(TARGET), SHORT }, +#define CONFIG_INT(TARGET, NAME, SHORT) { ST_INT, NAME, &TARGET, sizeof(TARGET), SHORT }, +#define CONFIG_FLOAT(TARGET, NAME, SHORT) { ST_FLOAT, NAME, &TARGET, sizeof(TARGET), SHORT }, +#define CONFIG_PATH(TARGET, NAME, SHORT) { ST_PATH, NAME, &TARGET, sizeof(TARGET), SHORT }, +#define CONFIG_STRING(TARGET, NAME, SHORT) { ST_STRING, NAME, &TARGET, sizeof(TARGET), SHORT }, +#define CONFIG_HEX(TARGET, NAME, SHORT) { ST_HEX, NAME, &TARGET, sizeof(TARGET), SHORT }, + +#define CONFIG_BIND(TARGET, PLAYER, NAME, SHORT) { ST_BIND, NAME, &TARGET, sizeof(TARGET), SHORT, PLAYER }, const rarch_setting_t setting_data[] = { @@ -183,22 +182,31 @@ const rarch_setting_t setting_data[] = END_SUB_GROUP() START_SUB_GROUP("Player 1") - CONFIG_BIND(g_settings.input.binds[0][ 0], "input_player1_b", "B button (down)") - CONFIG_BIND(g_settings.input.binds[0][ 1], "input_player1_y", "Y button (left)") - CONFIG_BIND(g_settings.input.binds[0][ 2], "input_player1_select", "Select button") - CONFIG_BIND(g_settings.input.binds[0][ 3], "input_player1_start", "Start button") - CONFIG_BIND(g_settings.input.binds[0][ 4], "input_player1_up", "Up D-pad") - CONFIG_BIND(g_settings.input.binds[0][ 5], "input_player1_down", "Down D-pad") - CONFIG_BIND(g_settings.input.binds[0][ 6], "input_player1_left", "Left D-pad") - CONFIG_BIND(g_settings.input.binds[0][ 7], "input_player1_right", "Right D-pad") - CONFIG_BIND(g_settings.input.binds[0][ 8], "input_player1_a", "A button (right)") - CONFIG_BIND(g_settings.input.binds[0][ 9], "input_player1_x", "X button (top)") - CONFIG_BIND(g_settings.input.binds[0][10], "input_player1_l", "L button (left shoulder)") - CONFIG_BIND(g_settings.input.binds[0][11], "input_player1_r", "R button (right shoulder)") - CONFIG_BIND(g_settings.input.binds[0][12], "input_player1_l2", "L2 button (left shoulder #2)") - CONFIG_BIND(g_settings.input.binds[0][13], "input_player1_r2", "R2 button (right shoulder #2)") - CONFIG_BIND(g_settings.input.binds[0][14], "input_player1_l3", "L3 button (left analog button)") - CONFIG_BIND(g_settings.input.binds[0][15], "input_player1_r3", "R3 button (right analog button)") + CONFIG_BIND(g_settings.input.binds[0][ 0], 1, "b", "B button (down)") + CONFIG_BIND(g_settings.input.binds[0][ 1], 1, "y", "Y button (left)") + CONFIG_BIND(g_settings.input.binds[0][ 2], 1, "select", "Select button") + CONFIG_BIND(g_settings.input.binds[0][ 3], 1, "start", "Start button") + CONFIG_BIND(g_settings.input.binds[0][ 4], 1, "up", "Up D-pad") + CONFIG_BIND(g_settings.input.binds[0][ 5], 1, "down", "Down D-pad") + CONFIG_BIND(g_settings.input.binds[0][ 6], 1, "left", "Left D-pad") + CONFIG_BIND(g_settings.input.binds[0][ 7], 1, "right", "Right D-pad") + CONFIG_BIND(g_settings.input.binds[0][ 8], 1, "a", "A button (right)") + CONFIG_BIND(g_settings.input.binds[0][ 9], 1, "x", "X button (top)") + CONFIG_BIND(g_settings.input.binds[0][10], 1, "l", "L button (left shoulder)") + CONFIG_BIND(g_settings.input.binds[0][11], 1, "r", "R button (right shoulder)") + CONFIG_BIND(g_settings.input.binds[0][12], 1, "l2", "L2 button (left shoulder #2)") + CONFIG_BIND(g_settings.input.binds[0][13], 1, "r2", "R2 button (right shoulder #2)") + CONFIG_BIND(g_settings.input.binds[0][14], 1, "l3", "L3 button (left analog button)") + CONFIG_BIND(g_settings.input.binds[0][15], 1, "r3", "R3 button (right analog button)") + CONFIG_BIND(g_settings.input.binds[0][16], 1, "turbo", "Turbo enable") + CONFIG_BIND(g_settings.input.binds[0][17], 1, "l_x_plus", "Left analog X+ (right)") + CONFIG_BIND(g_settings.input.binds[0][18], 1, "l_x_minus", "Left analog X- (left)") + CONFIG_BIND(g_settings.input.binds[0][19], 1, "l_y_plus", "Left analog Y+ (down)") + CONFIG_BIND(g_settings.input.binds[0][20], 1, "l_y_minus", "Left analog Y- (up)") + CONFIG_BIND(g_settings.input.binds[0][21], 1, "r_x_plus", "Right analog X+ (right)") + CONFIG_BIND(g_settings.input.binds[0][22], 1, "r_x_minus", "Right analog X- (left)") + CONFIG_BIND(g_settings.input.binds[0][23], 1, "r_y_plus", "Right analog Y+ (down)") + CONFIG_BIND(g_settings.input.binds[0][24], 1, "r_y_minus", "Right analog Y- (up)") END_SUB_GROUP() END_GROUP()