X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetMouseBtn.m;h=2f56f7e1849b5bcdb551ba17360f1076fe5f4260;hp=172f7406f1a1d0d3c1a56d53b2a37d2fed5b9f6c;hb=c262a3d0972ba16257fd24a948ab04f528f80d33;hpb=51ca12b552a9c17c4d4029b0340e193b273044a8 diff --git a/TargetMouseBtn.m b/TargetMouseBtn.m index 172f740..2f56f7e 100644 --- a/TargetMouseBtn.m +++ b/TargetMouseBtn.m @@ -10,41 +10,45 @@ @implementation TargetMouseBtn -@synthesize which; +@synthesize button; --(NSString*) stringify { - return [[NSString alloc] initWithFormat: @"mbtn~%u", which]; ++ (NSString *)serializationCode { + return @"mbtn"; } -+(TargetMouseBtn*) unstringifyImpl: (NSArray*) comps { - NSParameterAssert([comps count] == 2); - TargetMouseBtn* target = [[TargetMouseBtn alloc] init]; - [target setWhich: [comps[1] integerValue]]; +- (NSDictionary *)serialize { + return @{ @"type": @"mbtn", @"button": @(self.button) }; +} + ++ (Target *)targetDeserialize:(NSDictionary *)serialization + withConfigs:(NSArray *)configs { + TargetMouseBtn *target = [[TargetMouseBtn alloc] init]; + target.button = [serialization[@"button"] intValue]; return target; } --(void) trigger: (JoystickController *)jc { +-(void) trigger { NSRect screenRect = [[NSScreen mainScreen] frame]; NSInteger height = screenRect.size.height; NSPoint mouseLoc = [NSEvent mouseLocation]; - CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown; + CGEventType eventType = (button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, CGPointMake(mouseLoc.x, height - mouseLoc.y), - which); + button); CGEventPost(kCGHIDEventTap, click); CFRelease(click); } --(void) untrigger: (JoystickController *)jc { +-(void) untrigger { NSRect screenRect = [[NSScreen mainScreen] frame]; NSInteger height = screenRect.size.height; NSPoint mouseLoc = [NSEvent mouseLocation]; - CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; + CGEventType eventType = (button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, CGPointMake(mouseLoc.x, height - mouseLoc.y), - which); + button); CGEventPost(kCGHIDEventTap, click); CFRelease(click); }