pcsxr-1.9.92
[pcsx_rearmed.git] / macosx / plugins / DFInput / macsrc / PadView.m
CommitLineData
ef79bbde
P
1/*
2 * Copyright (c) 2010, Wei Mingzhi <whistler@openoffice.org>.
3 * All Rights Reserved.
4 *
5 * Based on: HIDInput by Gil Pedersen.
6 * Copyright (c) 2004, Gil Pedersen.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses>.
20 */
21
22#import "PadView.h"
23#include "pad.h"
24
25@implementation PadView
26
27- (id)initWithFrame:(NSRect)frameRect
28{
29 if ((self = [super initWithFrame:frameRect]) != nil) {
30 controller = [[ControllerList alloc] initWithConfig];
31 [self setController:0];
32 }
33 return self;
34}
35
36- (void)dealloc
37{
38 [controller release];
39 [super dealloc];
40}
41
42- (void)drawRect:(NSRect)rect
43{
44}
45
46- (IBAction)setType:(id)sender
47{
48 g.cfg.PadDef[[ControllerList currentController]].Type =
49 ([sender indexOfSelectedItem] > 0 ? PSE_PAD_TYPE_ANALOGPAD : PSE_PAD_TYPE_STANDARD);
50
51 [tableView reloadData];
52}
53
54- (IBAction)setDevice:(id)sender
55{
56 g.cfg.PadDef[[ControllerList currentController]].DevNum = (int)[sender indexOfSelectedItem] - 1;
57}
58
59- (void)setController:(int)which
60{
61 int i;
62
63 [ControllerList setCurrentController:which];
64 [tableView setDataSource:controller];
65
66 [deviceMenu removeAllItems];
67 [deviceMenu addItemWithTitle:@"(Keyboard only)"];
68
69 for (i = 0; i < SDL_NumJoysticks(); i++) {
70 [deviceMenu addItemWithTitle:[NSString stringWithUTF8String:SDL_JoystickName(i)]];
71 }
72
73 if (g.cfg.PadDef[which].DevNum >= SDL_NumJoysticks()) {
74 g.cfg.PadDef[which].DevNum = -1;
75 }
76
77 [deviceMenu selectItemAtIndex:g.cfg.PadDef[which].DevNum + 1];
78 [typeMenu selectItemAtIndex:(g.cfg.PadDef[which].Type == PSE_PAD_TYPE_ANALOGPAD ? 1 : 0)];
79
80 [tableView reloadData];
81}
82
83
84- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor
85{
86 return false;
87}
88
89/* handles key events on the pad list */
90- (void)keyDown:(NSEvent *)theEvent
91{
92 int key = [theEvent keyCode];
93
94 if ([[theEvent window] firstResponder] == tableView) {
95 if (key == 51 || key == 117) {
96 // delete keys - remove the mappings for the selected item
97 [controller deleteRow:[tableView selectedRow]];
98 [tableView reloadData];
99 return;
100 } else if (key == 36) {
101 // return key - configure the selected item
102 [tableView editColumn:[tableView columnWithIdentifier:@"button"] row:[tableView selectedRow] withEvent:nil select:YES];
103 return;
104 }
105 }
106
107 [super keyDown:theEvent];
108}
109
110@end