X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Classes%2FNJOutputMouseScroll.m;h=1ae08cc18ff8a8b8a9049f0cee875ff1cc49d377;hp=812685f527de245846749a33bd9b42d5a37fb4b0;hb=281e575060f936fd9483d1cf6416851b3783fe42;hpb=0064c1fbff36795885a9724081af2a17d83c20a3 diff --git a/Classes/NJOutputMouseScroll.m b/Classes/NJOutputMouseScroll.m index 812685f..1ae08cc 100644 --- a/Classes/NJOutputMouseScroll.m +++ b/Classes/NJOutputMouseScroll.m @@ -16,42 +16,51 @@ - (NSDictionary *)serialize { return @{ @"type": self.class.serializationCode, @"direction": @(_direction), - @"speed": @(_speed) + @"speed": @(_speed), + @"smooth": @(_smooth), }; } -+ (NJOutput *)outputDeserialize:(NSDictionary *)serialization - withMappings:(NSArray *)mappings { ++ (NJOutput *)outputWithSerialization:(NSDictionary *)serialization { NJOutputMouseScroll *output = [[NJOutputMouseScroll alloc] init]; output.direction = [serialization[@"direction"] intValue]; - output.speed = [serialization[@"direction"] floatValue]; + 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); } } -- (BOOL)update:(NJDeviceController *)jc { +- (BOOL)update:(NJInputController *)ic { 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);