X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetMouseScroll.m;h=ac3b852511d37a92f7ae744518e7b62bfadee5e9;hp=d840ba1069bfe2539a50cbd44d79e8d7bda40dd2;hb=f864d363128de19fc6591b77ae9226b34166d715;hpb=681ca0346ecb3f3da2c45a1a470601f15aad22cf diff --git a/TargetMouseScroll.m b/TargetMouseScroll.m index d840ba1..ac3b852 100644 --- a/TargetMouseScroll.m +++ b/TargetMouseScroll.m @@ -7,7 +7,9 @@ #import "TargetMouseScroll.h" -@implementation TargetMouseScroll +@implementation TargetMouseScroll { + int sign; +} + (NSString *)serializationCode { return @"mscroll"; @@ -23,13 +25,45 @@ target.amount = [serialization[@"amount"] intValue]; return target; } --(void) trigger { + +- (void)trigger { + if (!self.magnitude) { + CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL, + kCGScrollEventUnitLine, + 1, + _amount); + CGEventPost(kCGHIDEventTap, scroll); + CFRelease(scroll); + } +} + +- (BOOL)update:(NJInputController *)jc { + if (fabsf(self.magnitude) < 0.01f) { + sign = 0; + return NO; // dead zone + } + + // If the input crossed over High/Low, this target is done. + if (!sign) + sign = self.magnitude < 0 ? -1 : 1; + else if (sign / self.magnitude < 0) { + sign = 0; + return NO; + } + + int amount = (int)(16.f * fabsf(self.magnitude) * _amount); CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL, - kCGScrollEventUnitLine, + kCGScrollEventUnitPixel, 1, - _amount); + amount); CGEventPost(kCGHIDEventTap, scroll); CFRelease(scroll); + + return YES; +} + +- (BOOL)isContinuous { + return YES; } @end