X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJOutputMouseScroll.m;h=b97a3e733547320afc7cf3ad3d043058d50a1106;hp=99cec4a2f7724972e3a056b9a3ed97bc0790068f;hb=9d7f100f57dded88fa998a86715a919ca471c3db;hpb=73e32e5c30b83a9690d705ac5351d51327283b21 diff --git a/Classes/NJOutputMouseScroll.m b/Classes/NJOutputMouseScroll.m index 99cec4a..b97a3e7 100644 --- a/Classes/NJOutputMouseScroll.m +++ b/Classes/NJOutputMouseScroll.m @@ -16,7 +16,8 @@ - (NSDictionary *)serialize { return @{ @"type": self.class.serializationCode, @"direction": @(_direction), - @"speed": @(_speed) + @"speed": @(_speed), + @"smooth": @(_smooth), }; } @@ -25,19 +26,28 @@ NJOutputMouseScroll *output = [[NJOutputMouseScroll alloc] init]; output.direction = [serialization[@"direction"] intValue]; output.speed = [serialization[@"speed"] floatValue]; + output.smooth = [serialization[@"smooth"] boolValue]; return output; } - (BOOL)isContinuous { - return !!self.speed; + return _smooth; +} + +- (int)wheel:(int)n { + int amount = abs(_direction) == n ? _direction / n : 0; + if (self.smooth) + amount *= _speed * self.magnitude; + return amount; } - (void)trigger { - if (!self.speed) { + if (!_smooth) { CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, - 1, - _direction); + 2, + [self wheel:1], + [self wheel:2]); CGEventPost(kCGHIDEventTap, scroll); CFRelease(scroll); } @@ -47,11 +57,11 @@ if (self.magnitude < 0.05f) return NO; // dead zone - int amount = (int)(_speed * self.magnitude * _direction); CGEventRef scroll = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, - 1, - amount); + 2, + [self wheel:1], + [self wheel:2]); CGEventPost(kCGHIDEventTap, scroll); CFRelease(scroll);