@property (assign) void* cookie;
@property (assign) int index;
-@property (copy) NSArray *subActions;
+@property (copy) NSArray *children;
@property (strong) id base;
@property (copy) NSString *name;
@property (readonly) BOOL active;
@synthesize cookie;
@synthesize index;
-@synthesize subActions;
+@synthesize children;
@synthesize base;
@synthesize name;
- (id)initWithIndex:(int)newIndex offset:(float)offset_ scale:(float)scale_ {
if ((self = [super init])) {
- self.subActions = @[[[SubAction alloc] initWithIndex:0 name:@"Low" base:self],
- [[SubAction alloc] initWithIndex:1 name:@"High" base:self]];
+ self.children = @[[[SubAction alloc] initWithIndex:0 name:@"Low" base:self],
+ [[SubAction alloc] initWithIndex:1 name:@"High" base:self]];
self.index = newIndex;
self.offset = offset_;
self.scale = scale_;
float parsed = [self getRealValue:raw];
if (parsed < -DEAD_ZONE)
- return self.subActions[0];
+ return self.children[0];
else if (parsed > DEAD_ZONE)
- return self.subActions[1];
+ return self.children[1];
else
return nil;
}
- (void)notifyEvent:(IOHIDValueRef)value {
int raw = IOHIDValueGetIntegerValue(value);
float parsed = [self getRealValue:raw];
- [self.subActions[0] setActive:parsed < -DEAD_ZONE];
- [self.subActions[1] setActive:parsed > DEAD_ZONE];
+ [self.children[0] setActive:parsed < -DEAD_ZONE];
+ [self.children[1] setActive:parsed > DEAD_ZONE];
}
- (float)getRealValue:(int)value {
- (id)init {
if ((self = [super init])) {
- self.subActions = @[[[SubAction alloc] initWithIndex: 0 name: @"Up" base: self],
+ self.children = @[[[SubAction alloc] initWithIndex: 0 name: @"Up" base: self],
[[SubAction alloc] initWithIndex: 1 name: @"Down" base: self],
[[SubAction alloc] initWithIndex: 2 name: @"Left" base: self],
[[SubAction alloc] initWithIndex: 3 name: @"Right" base: self]];
switch (IOHIDElementGetLogicalMax(IOHIDValueGetElement(value))) {
case 7: // 8-way switch, 0-7.
switch (parsed) {
- case 0: return self.subActions[0];
- case 4: return self.subActions[1];
- case 6: return self.subActions[2];
- case 2: return self.subActions[3];
+ case 0: return self.children[0];
+ case 4: return self.children[1];
+ case 6: return self.children[2];
+ case 2: return self.children[3];
default: return nil;
}
case 8: // 8-way switch, 1-8 (neutral 0).
switch (parsed) {
- case 1: return self.subActions[0];
- case 5: return self.subActions[1];
- case 7: return self.subActions[2];
- case 3: return self.subActions[3];
+ case 1: return self.children[0];
+ case 5: return self.children[1];
+ case 7: return self.children[2];
+ case 3: return self.children[3];
default: return nil;
}
case 3: // 4-way switch, 0-3.
switch (parsed) {
- case 0: return self.subActions[0];
- case 2: return self.subActions[1];
- case 3: return self.subActions[2];
- case 1: return self.subActions[3];
+ case 0: return self.children[0];
+ case 2: return self.children[1];
+ case 3: return self.children[2];
+ case 1: return self.children[3];
default: return nil;
}
case 4: // 4-way switch, 1-4 (neutral 0).
switch (parsed) {
- case 1: return self.subActions[0];
- case 3: return self.subActions[1];
- case 4: return self.subActions[2];
- case 2: return self.subActions[3];
+ case 1: return self.children[0];
+ case 3: return self.children[1];
+ case 4: return self.children[2];
+ case 2: return self.children[3];
default: return nil;
}
default:
parsed++;
size++;
}
- BOOL *activeSubactions = (size == 8) ? active_eightway : active_fourway;
+ BOOL *activechildren = (size == 8) ? active_eightway : active_fourway;
for (int i = 0; i < 4; i++)
- [self.subActions[i] setActive:activeSubactions[parsed * 4 + i]];
+ [self.children[i] setActive:activechildren[parsed * 4 + i]];
}
@end
return;
[mainAction notifyEvent: value];
- NSArray* subactions = [mainAction subActions];
- if(!subactions)
- subactions = @[mainAction];
- for(id subaction in subactions) {
+ NSArray* children = [mainAction children];
+ if(!children)
+ children = @[mainAction];
+ for(id subaction in children) {
Target* target = [[controller->configsController currentConfig] getTargetForAction:subaction];
if(!target)
continue;
- (JSAction *)selectedAction {
id item = [outlineView itemAtRow:outlineView.selectedRow];
- if ([item isKindOfClass: [JSAction class]] && ![item subActions])
- return item;
- else
- return nil;
+ return [item children] ? nil : item;
}
-/* outline view */
-
- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
- if(item == nil)
- return [joysticks count];
- if([item isKindOfClass: [Joystick class]])
- return [[item children] count];
- if([item isKindOfClass: [JSAction class]] && [item subActions] != NULL)
- return [[item subActions] count];
- return 0;
+ return item ? [[item children] count] : [joysticks count];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
- if(item == nil)
- return YES;
- if([item isKindOfClass: [Joystick class]])
- return YES;
- if([item isKindOfClass: [JSAction class]])
- return [item subActions]==NULL ? NO : YES;
- return NO;
+ return item ? [[item children] count] > 0: YES;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item {
- if(item == nil)
- return joysticks[index];
-
- if([item isKindOfClass: [Joystick class]])
- return [item children][index];
-
- if([item isKindOfClass: [JSAction class]])
- return [item subActions][index];
-
- return NULL;
+ return item ? [item children][index] : joysticks[index];
}
+
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
if(item == nil)
return @"root";