@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 objectAtIndex:1] integerValue]];
++ (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);
}