From: Joe Wreschnig Date: Sat, 2 Mar 2013 12:33:11 +0000 (+0100) Subject: Formal protocol for the interface shared between Joysticks and JSActions, use new... X-Git-Tag: version-1.0~56 X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=commitdiff_plain;h=0238d141f06420e1a73eccd14ca73a7e29ad2a69 Formal protocol for the interface shared between Joysticks and JSActions, use new safer types elsewhere. --- diff --git a/ApplicationController.h b/ApplicationController.h index d9a875a..a5dcb6a 100644 --- a/ApplicationController.h +++ b/ApplicationController.h @@ -10,7 +10,7 @@ @class TargetController; @class ConfigsController; -@interface ApplicationController : NSObject { +@interface ApplicationController : NSObject { IBOutlet NSDrawer *drawer; IBOutlet NSWindow *mainWindow; IBOutlet NSToolbarItem *activeButton; diff --git a/Enjoyable.xcodeproj/project.pbxproj b/Enjoyable.xcodeproj/project.pbxproj index 35f48d8..c46eb77 100644 --- a/Enjoyable.xcodeproj/project.pbxproj +++ b/Enjoyable.xcodeproj/project.pbxproj @@ -89,6 +89,7 @@ EE1D7C9116E01E7000B000EB /* NSView+FirstResponder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSView+FirstResponder.m"; sourceTree = ""; }; EE1D7C9416E0ECCF00B000EB /* NSError+Description.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+Description.h"; sourceTree = ""; }; EE1D7C9516E0ECCF00B000EB /* NSError+Description.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+Description.m"; sourceTree = ""; }; + EEF86B7316E2241000674B87 /* NJActionPathElement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NJActionPathElement.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -143,6 +144,7 @@ 8BEFAD9B15C46BFF00823AEC /* TargetMouseScroll.m */, 8BEFAD9E15C476DC00823AEC /* TargetToggleMouseScope.h */, 8BEFAD9F15C476DC00823AEC /* TargetToggleMouseScope.m */, + EEF86B7316E2241000674B87 /* NJActionPathElement.h */, ); name = Classes; sourceTree = ""; diff --git a/JSAction.h b/JSAction.h index 0e25847..dc00a8d 100644 --- a/JSAction.h +++ b/JSAction.h @@ -6,7 +6,9 @@ // Copyright 2009 University of Otago. All rights reserved. // -@interface JSAction : NSObject +#import "NJActionPathElement.h" + +@interface JSAction : NSObject @property (nonatomic, assign) IOHIDElementCookie cookie; @property (nonatomic, copy) NSArray *children; @@ -16,7 +18,7 @@ @property (nonatomic, readonly) float magnitude; @property (readonly) NSString *uid; -- (id)initWithName:(NSString *)newName base:(JSAction *)newBase; +- (id)initWithName:(NSString *)newName base:(id )newBase; - (void)notifyEvent:(IOHIDValueRef)value; - (id)findSubActionForValue:(IOHIDValueRef)value; diff --git a/JSAction.m b/JSAction.m index 6903c56..1cdbeb2 100644 --- a/JSAction.m +++ b/JSAction.m @@ -9,7 +9,7 @@ @implementation JSAction -- (id)initWithName:(NSString *)newName base:(JSAction *)newBase { +- (id)initWithName:(NSString *)newName base:(id )newBase { if ((self = [super init])) { self.name = newName; self.base = newBase; diff --git a/Joystick.h b/Joystick.h index 4b60ba8..e5566f1 100644 --- a/Joystick.h +++ b/Joystick.h @@ -6,9 +6,11 @@ // Copyright 2009 University of Otago. All rights reserved. // +#import "NJActionPathElement.h" + @class JSAction; -@interface Joystick : NSObject +@interface Joystick : NSObject @property (nonatomic, assign) int index; @property (nonatomic, copy) NSString *productName; @@ -18,7 +20,7 @@ @property (readonly) NSString *uid; - (id)initWithDevice:(IOHIDDeviceRef)device; -- (id)handlerForEvent:(IOHIDValueRef)value; +- (JSAction *)handlerForEvent:(IOHIDValueRef)value; - (JSAction *)actionForEvent:(IOHIDValueRef)value; @end diff --git a/Joystick.m b/Joystick.m index 3b43e4e..4753caf 100644 --- a/Joystick.m +++ b/Joystick.m @@ -95,7 +95,7 @@ static NSArray *ActionsForElement(IOHIDDeviceRef device, id base) { return nil; } -- (id)handlerForEvent:(IOHIDValueRef) value { +- (JSAction *)handlerForEvent:(IOHIDValueRef)value { JSAction *mainAction = [self actionForEvent:value]; return [mainAction findSubActionForValue:value]; } diff --git a/JoystickController.m b/JoystickController.m index 967a935..ab59c82 100644 --- a/JoystickController.m +++ b/JoystickController.m @@ -35,10 +35,11 @@ CFRelease(hidManager); } -- (void)expandRecursive:(id)handler { - if ([handler base]) - [self expandRecursive:[handler base]]; - [outlineView expandItem:handler]; +- (void)expandRecursive:(id )pathElement { + if (pathElement) { + [self expandRecursive:pathElement.base]; + [outlineView expandItem:pathElement]; + } } - (void)addRunningTarget:(Target *)target { @@ -188,26 +189,30 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD } - (JSAction *)selectedAction { - id item = [outlineView itemAtRow:outlineView.selectedRow]; - return [item children] ? nil : item; + id item = [outlineView itemAtRow:outlineView.selectedRow]; + return (!item.children && item.base) ? item : nil; } -- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item { - return item ? [[item children] count] : _joysticks.count; +- (NSInteger)outlineView:(NSOutlineView *)outlineView + numberOfChildrenOfItem:(id )item { + return item ? item.children.count : _joysticks.count; } -- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item { +- (BOOL)outlineView:(NSOutlineView *)outlineView + isItemExpandable:(id )item { return item ? [[item children] count] > 0: YES; } -- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item { - return item ? [item children][index] : _joysticks[index]; +- (id)outlineView:(NSOutlineView *)outlineView + child:(NSInteger)index + ofItem:(id )item { + return item ? item.children[index] : _joysticks[index]; } -- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item { - if(item == nil) - return @"root"; - return [item name]; +- (id)outlineView:(NSOutlineView *)outlineView +objectValueForTableColumn:(NSTableColumn *)tableColumn + byItem:(id )item { + return item ? item.name : @"root"; } - (void)outlineViewSelectionDidChange:(NSNotification *)notification { diff --git a/NJActionPathElement.h b/NJActionPathElement.h new file mode 100644 index 0000000..f5eb0ca --- /dev/null +++ b/NJActionPathElement.h @@ -0,0 +1,9 @@ +#import + +@protocol NJActionPathElement + +- (NSArray *)children; +- (id ) base; +- (NSString *)name; + +@end diff --git a/TargetController.m b/TargetController.m index 75f58ab..1f285ec 100644 --- a/TargetController.m +++ b/TargetController.m @@ -164,7 +164,7 @@ } else { self.enabled = YES; NSString *actFullName = action.name; - for (JSAction *cur = action.base; cur; cur = cur.base) { + for (id cur = action.base; cur; cur = cur.base) { actFullName = [[NSString alloc] initWithFormat:@"%@ > %@", cur.name, actFullName]; } title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", configsController.currentConfig.name, actFullName];