5 // Created by Yifeng Huang on 7/28/12.
8 #import "TargetMouseScroll.h"
10 @implementation TargetMouseScroll {
14 + (NSString *)serializationCode {
18 - (NSDictionary *)serialize {
19 return @{ @"type": @"mscroll", @"amount": @(_amount) };
22 + (Target *)targetDeserialize:(NSDictionary *)serialization
23 withConfigs:(NSArray *)configs {
24 TargetMouseScroll *target = [[TargetMouseScroll alloc] init];
25 target.amount = [serialization[@"amount"] intValue];
30 if (!self.magnitude) {
31 CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
32 kCGScrollEventUnitLine,
35 CGEventPost(kCGHIDEventTap, scroll);
40 - (BOOL)update:(JoystickController *)jc {
41 if (fabsf(self.magnitude) < 0.01f) {
43 return NO; // dead zone
46 // If the action crossed over High/Low, this target is done.
48 sign = self.magnitude < 0 ? -1 : 1;
49 else if (sign / self.magnitude < 0) {
54 int amount = (int)(16.f * fabsf(self.magnitude) * _amount);
55 CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL,
56 kCGScrollEventUnitPixel,
59 CGEventPost(kCGHIDEventTap, scroll);
65 - (BOOL)isContinuous {