From 20ccd38576bb48caf8e4129a8c86fe04819d83bc Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Wed, 27 Feb 2013 16:31:32 +0100 Subject: [PATCH] Rename 'subActions' to 'children' to match Joystick property name. Simplify logic that deals with Joysticks-or-JSActions. --- JSAction.h | 2 +- JSAction.m | 2 +- JSActionAnalog.m | 12 ++++++------ JSActionHat.m | 38 +++++++++++++++++++------------------- JoystickController.m | 43 +++++++++---------------------------------- 5 files changed, 36 insertions(+), 61 deletions(-) diff --git a/JSAction.h b/JSAction.h index 9de4696..30e99b9 100644 --- a/JSAction.h +++ b/JSAction.h @@ -16,7 +16,7 @@ @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; diff --git a/JSAction.m b/JSAction.m index 6bc1529..84d1ea8 100644 --- a/JSAction.m +++ b/JSAction.m @@ -11,7 +11,7 @@ @synthesize cookie; @synthesize index; -@synthesize subActions; +@synthesize children; @synthesize base; @synthesize name; diff --git a/JSActionAnalog.m b/JSActionAnalog.m index e7d6eba..5aded63 100644 --- a/JSActionAnalog.m +++ b/JSActionAnalog.m @@ -16,8 +16,8 @@ - (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_; @@ -31,9 +31,9 @@ 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; } @@ -41,8 +41,8 @@ - (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 { diff --git a/JSActionHat.m b/JSActionHat.m index 4e11b49..d948cc7 100644 --- a/JSActionHat.m +++ b/JSActionHat.m @@ -29,7 +29,7 @@ static BOOL active_fourway[20] = { - (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]]; @@ -44,34 +44,34 @@ static BOOL active_fourway[20] = { 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: @@ -87,9 +87,9 @@ static BOOL active_fourway[20] = { 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 diff --git a/JoystickController.m b/JoystickController.m index 54734a8..6d73a2a 100644 --- a/JoystickController.m +++ b/JoystickController.m @@ -62,10 +62,10 @@ static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDVa 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; @@ -176,46 +176,21 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD - (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"; -- 2.30.2