1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/*
* Copyright (c) 2010, Wei Mingzhi <whistler_wmz@users.sf.net>.
* All Rights Reserved.
*
* Based on HIDInput by Gil Pedersen.
* Copyright (c) 2004, Gil Pedersen.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses>.
*/
#import "ControllerList.h"
#include "pad.h"
#include "cfg.h"
static int currentController;
@implementation ControllerList
- (id)initWithConfig
{
if (!(self = [super init])) return nil;
return self;
}
#if !__has_feature(objc_arc)
- (void)dealloc
{
[super dealloc];
}
#endif
/* sets current controller data returned by data source */
+ (void)setCurrentController:(int)which
{
currentController = which;
}
+ (int)currentController
{
return currentController;
}
/* NSDataSource */
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
return DKEY_TOTAL + (g.cfg.PadDef[currentController].Type == PSE_PAD_TYPE_ANALOGPAD ? 8 : -3);
}
static const NSString *LabelText[DKEY_TOTAL + 8] = {
@"D-Pad Up",
@"D-Pad Down",
@"D-Pad Left",
@"D-Pad Right",
@"Cross",
@"Circle",
@"Square",
@"Triangle",
@"L1",
@"R1",
@"L2",
@"R2",
@"Select",
@"Start",
@"L3",
@"R3",
@"Analog",
@"L-Stick Right",
@"L-Stick Left",
@"L-Stick Down",
@"L-Stick Up",
@"R-Stick Right",
@"R-Stick Left",
@"R-Stick Down",
@"R-Stick Up"
};
static const int DPad[DKEY_TOTAL] = {
DKEY_UP,
DKEY_DOWN,
DKEY_LEFT,
DKEY_RIGHT,
DKEY_CROSS,
DKEY_CIRCLE,
DKEY_SQUARE,
DKEY_TRIANGLE,
DKEY_L1,
DKEY_R1,
DKEY_L2,
DKEY_R2,
DKEY_SELECT,
DKEY_START,
DKEY_L3,
DKEY_R3,
DKEY_ANALOG
};
+ (int)buttonOfRow:(NSInteger)row
{
return DPad[row];
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex
{
char buf[256];
if ([((NSString *)[aTableColumn identifier]) isEqualToString:@"key"])
return LabelText[rowIndex];
else {
// actual keys
if (rowIndex < DKEY_TOTAL) {
GetKeyDescription(buf, currentController, DPad[rowIndex]);
} else {
rowIndex -= DKEY_TOTAL;
GetAnalogDescription(buf, currentController, rowIndex / 4, rowIndex % 4);
}
return @(buf);
}
}
- (void)deleteRow:(NSInteger)which
{
if (which < DKEY_TOTAL) {
g.cfg.PadDef[currentController].KeyDef[DPad[which]].Key = 0;
g.cfg.PadDef[currentController].KeyDef[DPad[which]].JoyEvType = NONE;
g.cfg.PadDef[currentController].KeyDef[DPad[which]].J.d = 0;
} else {
which -= DKEY_TOTAL;
g.cfg.PadDef[currentController].AnalogDef[which / 4][which % 4].Key = 0;
g.cfg.PadDef[currentController].AnalogDef[which / 4][which % 4].JoyEvType = NONE;
g.cfg.PadDef[currentController].AnalogDef[which / 4][which % 4].J.d = 0;
}
}
@end
|