5 // Created by Sam McCall on 5/05/09.
8 @implementation TargetController
11 [radioButtons setState: 1 atRow: 1 column: 0 ];
14 -(IBAction)radioChanged:(id)sender {
15 [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
18 -(IBAction)mdirChanged:(id)sender {
19 [radioButtons setState: 1 atRow: 3 column: 0];
20 [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
23 -(IBAction)mbtnChanged:(id)sender {
24 [radioButtons setState: 1 atRow: 4 column: 0];
25 [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
28 -(IBAction)sdirChanged:(id)sender {
29 [radioButtons setState: 1 atRow: 5 column: 0];
30 [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: sender];
36 switch([radioButtons selectedRow]) {
41 TargetKeyboard* k = [[TargetKeyboard alloc] init];
42 [k setVk: [keyInput vk]];
43 [k setDescr: [keyInput descr]];
49 TargetConfig* c = [[TargetConfig alloc] init];
50 [c setConfig: [configsController configs][[configPopup indexOfSelectedItem]]];
55 TargetMouseMove *mm = [[TargetMouseMove alloc] init];
56 [mm setDir: [mouseDirSelect selectedSegment]];
61 TargetMouseBtn *mb = [[TargetMouseBtn alloc] init];
62 if ([mouseBtnSelect selectedSegment] == 0) {
63 [mb setWhich: kCGMouseButtonLeft];
66 [mb setWhich: kCGMouseButtonRight];
72 TargetMouseScroll *ms = [[TargetMouseScroll alloc] init];
73 if ([scrollDirSelect selectedSegment] == 0) {
83 TargetToggleMouseScope *tms = [[TargetToggleMouseScope alloc] init];
90 -(void)configChosen:(id)sender {
91 [radioButtons setState: 1 atRow: 2 column: 0];
96 JSAction *action = [joystickController selectedAction];
98 configsController.currentConfig[action] = self.state;
104 [radioButtons setState: 1 atRow: 0 column: 0];
105 [mouseDirSelect setSelectedSegment: 0];
106 [mouseBtnSelect setSelectedSegment: 0];
107 [scrollDirSelect setSelectedSegment: 0];
108 [self refreshConfigsPreservingSelection: NO];
111 -(void) setEnabled: (BOOL) enabled {
112 [radioButtons setEnabled: enabled];
113 [keyInput setEnabled: enabled];
114 [configPopup setEnabled: enabled];
115 [mouseDirSelect setEnabled: enabled];
116 [mouseBtnSelect setEnabled: enabled];
117 [scrollDirSelect setEnabled: enabled];
120 return [radioButtons isEnabled];
124 id jsaction = [joystickController selectedAction];
125 currentJsaction = jsaction;
127 [self setEnabled: NO];
128 [title setStringValue: @""];
131 [self setEnabled: YES];
133 Target* target = configsController.currentConfig[jsaction];
136 NSString* actFullName = [act name];
139 actFullName = [[NSString alloc] initWithFormat: @"%@ > %@", [act name], actFullName];
141 [title setStringValue: [[NSString alloc] initWithFormat: @"%@ > %@", [[configsController currentConfig] name], actFullName]];
145 } else if([target isKindOfClass: [TargetKeyboard class]]) {
146 [radioButtons setState:1 atRow: 1 column: 0];
147 [keyInput setVk: [(TargetKeyboard*)target vk]];
148 } else if([target isKindOfClass: [TargetConfig class]]) {
149 [radioButtons setState:1 atRow: 2 column: 0];
150 [configPopup selectItemAtIndex: [[configsController configs] indexOfObject: [(TargetConfig*)target config]]];
152 else if ([target isKindOfClass: [TargetMouseMove class]]) {
153 [radioButtons setState:1 atRow: 3 column: 0];
154 [mouseDirSelect setSelectedSegment: [(TargetMouseMove *)target dir]];
156 else if ([target isKindOfClass: [TargetMouseBtn class]]) {
157 [radioButtons setState: 1 atRow: 4 column: 0];
158 if ([(TargetMouseBtn *)target which] == kCGMouseButtonLeft)
159 [mouseBtnSelect setSelectedSegment: 0];
161 [mouseBtnSelect setSelectedSegment: 1];
163 else if ([target isKindOfClass: [TargetMouseScroll class]]) {
164 [radioButtons setState: 1 atRow: 5 column: 0];
165 if ([(TargetMouseScroll *)target howMuch] < 0)
166 [scrollDirSelect setSelectedSegment: 0];
168 [scrollDirSelect setSelectedSegment: 1];
170 else if ([target isKindOfClass: [TargetToggleMouseScope class]]) {
171 [radioButtons setState: 1 atRow: 6 column: 0];
173 [NSException raise:@"Unknown target subclass" format:@"Unknown target subclass"];
178 [[[NSApplication sharedApplication] mainWindow] makeFirstResponder: keyInput];
181 -(void) refreshConfigsPreservingSelection: (BOOL) preserve {
182 int initialIndex = [configPopup indexOfSelectedItem];
184 NSArray* configs = [configsController configs];
185 [configPopup removeAllItems];
186 for(int i=0; i<[configs count]; i++) {
187 [configPopup addItemWithTitle: [configs[i]name]];
190 [configPopup selectItemAtIndex:initialIndex];