X-Git-Url: https://git.yukkurigames.com/?a=blobdiff_plain;f=Classes%2FNJInputButton.m;fp=Classes%2FNJInputButton.m;h=0c3b0ce32de0105413d0d1c4e68c86be853e62b7;hb=0064c1fbff36795885a9724081af2a17d83c20a3;hp=0000000000000000000000000000000000000000;hpb=56d825ba259066d847a9fc3f9c8c0c0a362a1507;p=enjoyable.git diff --git a/Classes/NJInputButton.m b/Classes/NJInputButton.m new file mode 100644 index 0000000..0c3b0ce --- /dev/null +++ b/Classes/NJInputButton.m @@ -0,0 +1,34 @@ +// +// NJInputButton.m +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// + +#import "NJInputButton.h" + +@implementation NJInputButton { + long _max; +} + +- (id)initWithName:(NSString *)name idx:(int)idx max:(long)max { + if ((self = [super init])) { + _max = max; + if (name.length) + self.name = [NSString stringWithFormat:@"Button %d - %@", idx, name]; + else + self.name = [NSString stringWithFormat:@"Button %d", idx]; + } + return self; +} + +- (id)findSubInputForValue:(IOHIDValueRef)val { + return (IOHIDValueGetIntegerValue(val) == _max) ? self : nil; +} + +- (void)notifyEvent:(IOHIDValueRef)value { + self.active = IOHIDValueGetIntegerValue(value) == _max; + self.magnitude = IOHIDValueGetIntegerValue(value) / (float)_max; +} + +@end