X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=TargetMouseBtn.m;h=a19b484475ccf42fcde78a435834279e4247676b;hp=172f7406f1a1d0d3c1a56d53b2a37d2fed5b9f6c;hb=e2a4d830dd9817f6a515a3b1b6aa152d3bb98c2b;hpb=51ca12b552a9c17c4d4029b0340e193b273044a8 diff --git a/TargetMouseBtn.m b/TargetMouseBtn.m index 172f740..a19b484 100644 --- a/TargetMouseBtn.m +++ b/TargetMouseBtn.m @@ -3,48 +3,47 @@ // Enjoy // // Created by Yifeng Huang on 7/27/12. -// Copyright (c) 2012 __MyCompanyName__. All rights reserved. // #import "TargetMouseBtn.h" @implementation TargetMouseBtn -@synthesize which; ++ (NSString *)serializationCode { + return @"mbtn"; +} --(NSString*) stringify { - return [[NSString alloc] initWithFormat: @"mbtn~%u", which]; +- (NSDictionary *)serialize { + return @{ @"type": @"mbtn", @"button": @(_button) }; } -+(TargetMouseBtn*) unstringifyImpl: (NSArray*) comps { - NSParameterAssert([comps count] == 2); - TargetMouseBtn* target = [[TargetMouseBtn alloc] init]; - [target setWhich: [comps[1] integerValue]]; ++ (Target *)targetDeserialize:(NSDictionary *)serialization + withMappings:(NSArray *)mappings { + TargetMouseBtn *target = [[TargetMouseBtn alloc] init]; + target.button = [serialization[@"button"] intValue]; return target; } --(void) trigger: (JoystickController *)jc { - NSRect screenRect = [[NSScreen mainScreen] frame]; - NSInteger height = screenRect.size.height; - NSPoint mouseLoc = [NSEvent mouseLocation]; - CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown; +-(void) trigger { + CGFloat height = NSScreen.mainScreen.frame.size.height; + NSPoint mouseLoc = NSEvent.mouseLocation; + 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 { - NSRect screenRect = [[NSScreen mainScreen] frame]; - NSInteger height = screenRect.size.height; - NSPoint mouseLoc = [NSEvent mouseLocation]; - CGEventType eventType = (which == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; +-(void) untrigger { + CGFloat height = NSScreen.mainScreen.frame.size.height; + NSPoint mouseLoc = NSEvent.mouseLocation; + CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp; CGEventRef click = CGEventCreateMouseEvent(NULL, eventType, CGPointMake(mouseLoc.x, height - mouseLoc.y), - which); + _button); CGEventPost(kCGHIDEventTap, click); CFRelease(click); }