diff options
| author | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2014-04-08 02:33:19 +0000 |
|---|---|---|
| committer | SND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2014-04-08 02:33:19 +0000 |
| commit | c875a3566e340e366553beb2dcd6b2bcf4d5ab18 (patch) | |
| tree | 97dcfbe538af5f282135a27cf889ed32b1d9d54d /macosx/plugins/DFInput/macsrc/PadView.m | |
| parent | 0d4ea9238b154a30e8713c7d00d7b6d1b0050d5c (diff) | |
| download | pcsxr-c875a3566e340e366553beb2dcd6b2bcf4d5ab18.tar.gz | |
DFInput: Implement SDL2 GameController support.
This change allows the user to use SDL2’s GameController API instead of the Joystick API.
The Game Controller API maps the buttons similar to an Xbox 360 controller, so some tricky mapping needed to be done.
Note that it currently only supports OS X.
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@89828 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'macosx/plugins/DFInput/macsrc/PadView.m')
| -rwxr-xr-x | macosx/plugins/DFInput/macsrc/PadView.m | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/macosx/plugins/DFInput/macsrc/PadView.m b/macosx/plugins/DFInput/macsrc/PadView.m index f8936888..befb5df3 100755 --- a/macosx/plugins/DFInput/macsrc/PadView.m +++ b/macosx/plugins/DFInput/macsrc/PadView.m @@ -26,7 +26,7 @@ - (id)initWithFrame:(NSRect)frameRect { - if ((self = [super initWithFrame:frameRect]) != nil) { + if (self = [super initWithFrame:frameRect]) { controller = [[ControllerList alloc] initWithConfig]; [self setController:0]; } @@ -35,13 +35,14 @@ - (void)drawRect:(NSRect)rect { + } - (IBAction)setType:(id)sender { g.cfg.PadDef[[ControllerList currentController]].Type = ([sender indexOfSelectedItem] > 0 ? PSE_PAD_TYPE_ANALOGPAD : PSE_PAD_TYPE_STANDARD); - + [tableView reloadData]; } @@ -50,36 +51,49 @@ g.cfg.PadDef[[ControllerList currentController]].DevNum = (int)[sender indexOfSelectedItem] - 1; } +- (IBAction)toggleSDL2:(id)sender +{ + controller.usingSDL2 = !controller.usingSDL2; + + [tableView reloadData]; +} + - (void)setController:(int)which { int i; - + [ControllerList setCurrentController:which]; [tableView setDataSource:controller]; - + [deviceMenu removeAllItems]; [deviceMenu addItemWithTitle:[[NSBundle bundleForClass:[self class]] localizedStringForKey:@"(Keyboard only)" value:@"" table:nil]]; - + for (i = 0; i < SDL_NumJoysticks(); i++) { - NSMenuItem *joystickItem = nil; + NSMenuItem *joystickItem; #if SDL_VERSION_ATLEAST(2, 0, 0) - SDL_Joystick *tmpJoy = SDL_JoystickOpen(i); - joystickItem = [[NSMenuItem alloc] initWithTitle:@(SDL_JoystickName(tmpJoy)) action:NULL keyEquivalent:@""]; - SDL_JoystickClose(tmpJoy); + NSString *tmpString; + if (SDL_IsGameController(i)) { + tmpString = @(SDL_GameControllerNameForIndex(i)); + } else { + tmpString = @(SDL_JoystickNameForIndex(i)); + } + joystickItem = [[NSMenuItem alloc] initWithTitle:tmpString action:NULL keyEquivalent:@""]; #else joystickItem = [[NSMenuItem alloc] initWithTitle:@(SDL_JoystickName(i)) action:NULL keyEquivalent:@""]; #endif [joystickItem setTag:i + 1]; [[deviceMenu menu] addItem:joystickItem]; } - + if (g.cfg.PadDef[which].DevNum >= SDL_NumJoysticks()) { g.cfg.PadDef[which].DevNum = -1; } - + [deviceMenu selectItemAtIndex:g.cfg.PadDef[which].DevNum + 1]; [typeMenu selectItemAtIndex:(g.cfg.PadDef[which].Type == PSE_PAD_TYPE_ANALOGPAD ? 1 : 0)]; - + + [self.useSDL2Check setState:g.cfg.PadDef[which].UseSDL2 ? NSOnState : NSOffState]; + [tableView reloadData]; } @@ -92,7 +106,7 @@ - (void)keyDown:(NSEvent *)theEvent { unsigned short key = [theEvent keyCode]; - + if ([[theEvent window] firstResponder] == tableView) { if (key == 51 || key == 117) { // delete keys - remove the mappings for the selected item @@ -105,7 +119,7 @@ return; } } - + [super keyDown:theEvent]; } |
