projects
/
enjoyable.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Big rename part 2: 'config' etc. to 'mapping.
[enjoyable.git]
/
TargetMouseMove.m
diff --git
a/TargetMouseMove.m
b/TargetMouseMove.m
index
8eeae88
..
b1d52a0
100644
(file)
--- a/
TargetMouseMove.m
+++ b/
TargetMouseMove.m
@@
-3,50
+3,57
@@
// Enjoy
//
// Created by Yifeng Huang on 7/26/12.
// Enjoy
//
// Created by Yifeng Huang on 7/26/12.
-// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "TargetMouseMove.h"
//
#import "TargetMouseMove.h"
-#import "
Joystick
Controller.h"
+#import "
NJInput
Controller.h"
-@implementation TargetMouseMove
+@implementation TargetMouseMove {
+ int sign;
+}
-(BOOL) isContinuous {
-(BOOL) isContinuous {
- return
true
;
+ return
YES
;
}
}
-@synthesize dir;
-
+ (NSString *)serializationCode {
return @"mmove";
}
- (NSDictionary *)serialize {
+ (NSString *)serializationCode {
return @"mmove";
}
- (NSDictionary *)serialize {
- return @{ @"type": @"mmove", @"
dir": @(self.dir
) };
+ return @{ @"type": @"mmove", @"
axis": @(_axis
) };
}
+ (Target *)targetDeserialize:(NSDictionary *)serialization
}
+ (Target *)targetDeserialize:(NSDictionary *)serialization
- with
Configs:(NSArray *)confi
gs {
+ with
Mappings:(NSArray *)mappin
gs {
TargetMouseMove *target = [[TargetMouseMove alloc] init];
TargetMouseMove *target = [[TargetMouseMove alloc] init];
- target.
dir = [serialization[@"dir
"] intValue];
+ target.
axis = [serialization[@"axis
"] intValue];
return target;
}
return target;
}
-- (BOOL)update:(
Joystick
Controller *)jc {
- //printf("Dir %d inputValue %f\n", [self dir], [self inputValue]);
- if (fabs(self.magnitude) < 0.01)
+- (BOOL)update:(
NJInput
Controller *)jc {
+ if (fabsf(self.magnitude) < 0.01) {
+ sign = 0;
return NO; // dead zone
return NO; // dead zone
+ }
+
+ // If the input crossed over High/Low, this target is done.
+ if (!sign)
+ sign = self.magnitude < 0 ? -1 : 1;
+ else if (sign / self.magnitude < 0) {
+ sign = 0;
+ return NO;
+ }
- NSRect screenRect = [[NSScreen mainScreen] frame];
- NSInteger height = screenRect.size.height;
+ CGFloat height = NSScreen.mainScreen.frame.size.height;
// TODO
// TODO
- float speed = 4.
0
;
- if (
[jc frontWindowOnly]
)
- speed = 12.
0
;
- float dx = 0.
0, dy = 0.0
;
- if (
[self dir]
== 0)
+ float speed = 4.
f
;
+ if (
jc.frontWindowOnly
)
+ speed = 12.
f
;
+ float dx = 0.
f, dy = 0.f
;
+ if (
_axis
== 0)
dx = self.magnitude * speed;
else
dy = self.magnitude * speed;
dx = self.magnitude * speed;
else
dy = self.magnitude * speed;
@@
-59,10
+66,10
@@
CGPointMake(mouseLoc.x, height - mouseLoc.y),
0);
CGEventSetType(move, kCGEventMouseMoved);
CGPointMake(mouseLoc.x, height - mouseLoc.y),
0);
CGEventSetType(move, kCGEventMouseMoved);
- CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, dx);
- CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, dy);
+ CGEventSetIntegerValueField(move, kCGMouseEventDeltaX,
(int)
dx);
+ CGEventSetIntegerValueField(move, kCGMouseEventDeltaY,
(int)
dy);
- if (
[jc frontWindowOnly]
) {
+ if (
jc.frontWindowOnly
) {
ProcessSerialNumber psn;
GetFrontProcess(&psn);
CGEventPostToPSN(&psn, move);
ProcessSerialNumber psn;
GetFrontProcess(&psn);
CGEventPostToPSN(&psn, move);
@@
-72,7
+79,7
@@
}
CFRelease(move);
}
CFRelease(move);
- return
dx || dy
;
+ return
YES
;
}
@end
}
@end