21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
-
+
-
-
+
-
+
-
+
-
+
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
-
+
+
+
+
|
#import "OHGameControllerDirectionalPad.h"
#import "OHGameControllerEmulatedAxis.h"
#import "OHGameControllerEmulatedButton.h"
@implementation OHGameControllerDirectionalPad
@synthesize xAxis = _xAxis, yAxis = _yAxis;
@synthesize upButton = _upButton, downButton = _downButton;
@synthesize up = _up, down = _down, left = _left, right = _right;
@synthesize leftButton = _leftButton, rightButton = _rightButton;
- (instancetype)initWithName: (OFString *)name
{
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithName: (OFString *)name
xAxis: (OHGameControllerAxis *)xAxis
yAxis: (OHGameControllerAxis *)yAxis
{
self = [super initWithName: name];
@try {
_xAxis = [xAxis retain];
_yAxis = [yAxis retain];
_upButton = [[OHGameControllerEmulatedButton alloc]
_up = [[OHGameControllerEmulatedButton alloc]
initWithAxis: _yAxis
positive: false];
_downButton = [[OHGameControllerEmulatedButton alloc]
_down = [[OHGameControllerEmulatedButton alloc]
initWithAxis: _yAxis
positive: true];
_leftButton = [[OHGameControllerEmulatedButton alloc]
_left = [[OHGameControllerEmulatedButton alloc]
initWithAxis: _xAxis
positive: false];
_rightButton = [[OHGameControllerEmulatedButton alloc]
_right = [[OHGameControllerEmulatedButton alloc]
initWithAxis: _xAxis
positive: true];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithName: (OFString *)name
upButton: (OHGameControllerButton *)upButton
downButton: (OHGameControllerButton *)downButton
leftButton: (OHGameControllerButton *)leftButton
rightButton: (OHGameControllerButton *)rightButton
up: (OHGameControllerButton *)up
down: (OHGameControllerButton *)down
left: (OHGameControllerButton *)left
right: (OHGameControllerButton *)right
{
self = [super initWithName: name];
@try {
_upButton = [upButton retain];
_downButton = [downButton retain];
_leftButton = [leftButton retain];
_rightButton = [rightButton retain];
_up = [up retain];
_down = [down retain];
_left = [left retain];
_right = [right retain];
_xAxis = [[OHGameControllerEmulatedAxis alloc]
initWithNegativeButton: _leftButton
positiveButton: _rightButton];
initWithNegativeButton: _left
positiveButton: _right];
_yAxis = [[OHGameControllerEmulatedAxis alloc]
initWithNegativeButton: _upButton
positiveButton: _downButton];
initWithNegativeButton: _up
positiveButton: _down];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_xAxis release];
[_yAxis release];
[_upButton release];
[_downButton release];
[_leftButton release];
[_rightButton release];
[_up release];
[_down release];
[_left release];
[_right release];
[super dealloc];
}
- (OFString *)description
{
return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name];
}
@end
|