Big rename part 2: 'config' etc. to 'mapping.
[enjoyable.git] / TargetMouseBtn.m
index 172f740..a19b484 100644 (file)
@@ -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);
-       TargetMouseBtntarget = [[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);
 }