SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
JoyKit/JOYHat.m
1 #import "JOYHat.h"
2 #import "JOYElement.h"
3 #import <AppKit/AppKit.h>
4
5 @implementation JOYHat
6 {
7 JOYElement *_element;
8 double _state;
9 }
10
11 - (uint64_t)uniqueID
12 {
13 return _element.uniqueID | (uint64_t)self.combinedIndex << 32;
14 }
15
16 - (NSString *)description
17 {
18 if (self.isPressed) {
19 return [NSString stringWithFormat:@"<%@: %p (%llx); State: %f degrees>", self.className, self, self.uniqueID, self.angle];
20 }
21 return [NSString stringWithFormat:@"<%@: %p (%llx); State: released>", self.className, self, self.uniqueID];
22
23 }
24
25 - (instancetype)initWithElement:(JOYElement *)element
26 {
27 self = [super init];
28 if (!self) return self;
29
30 _element = element;
31 _state = -1;
32
33 return self;
34 }
35
36 - (bool)isPressed
37 {
38 return _state >= 0 && _state < 360;
39 }
40
41 - (double)angle
42 {
43 if (self.isPressed) return fmod((_state + 270), 360);
44 return -1;
45 }
46
47 - (unsigned)resolution
48 {
49 return _element.max - _element.min + 1;
50 }
51
52 - (bool)updateState
53 {
54 signed state = ([_element value] - _element.min) * 360.0 / self.resolution;
55 if (_state != state) {
56 _state = state;
57 return true;
58 }
59 return false;
60 }
61
62 - (NSString *)usageString
63 {
64 return @"Hat switch";
65 }
66
67 @end
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.