Fix several cases where the UI did not properly reflect model changes.
[enjoyable.git] / Classes / NJInputButton.m
1 //
2 // NJInputButton.m
3 // Enjoy
4 //
5 // Created by Sam McCall on 5/05/09.
6 //
7
8 #import "NJInputButton.h"
9
10 @implementation NJInputButton {
11 CFIndex _max;
12 }
13
14 - (id)initWithElement:(IOHIDElementRef)element
15 index:(int)index
16 parent:(NJInputPathElement *)parent
17 {
18 if ((self = [super initWithName:NJINPUT_NAME(NSLocalizedString(@"button %d", @"button name"), index)
19 eid:NJINPUT_EID("Button", index)
20 element:element
21 parent:parent])) {
22 _max = IOHIDElementGetLogicalMax(element);
23 }
24 return self;
25 }
26
27 - (id)findSubInputForValue:(IOHIDValueRef)val {
28 return (IOHIDValueGetIntegerValue(val) == _max) ? self : nil;
29 }
30
31 - (void)notifyEvent:(IOHIDValueRef)value {
32 self.active = IOHIDValueGetIntegerValue(value) == _max;
33 self.magnitude = IOHIDValueGetIntegerValue(value) / (float)_max;
34 }
35
36 @end