// Created by Sam McCall on 5/05/09.
//
-@implementation JSActionButton
+#import "JSActionButton.h"
-@synthesize max, active;
+@implementation JSActionButton {
+ int _max;
+}
--(id)initWithIndex: (int)newIndex andName: (NSString *)newName {
- if(self= [ super init]) {
- subActions = NULL;
- index = newIndex;
- name = [[NSString alloc] initWithFormat: @"Button %d %@", (index+1), newName];
- }
- return self;
+- (id)initWithName:(NSString *)name idx:(int)idx max:(int)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) findSubActionForValue: (IOHIDValueRef) val {
- if(IOHIDValueGetIntegerValue(val) == max)
- return self;
- return NULL;
+- (id)findSubActionForValue:(IOHIDValueRef)val {
+ return (IOHIDValueGetIntegerValue(val) == _max) ? self : nil;
}
--(void) notifyEvent: (IOHIDValueRef) value {
- active = IOHIDValueGetIntegerValue(value) == max;
+- (void)notifyEvent:(IOHIDValueRef)value {
+ self.active = IOHIDValueGetIntegerValue(value) == _max;
}
@end