ObjFW  Check-in [35e4d04158]

Overview
Comment:OHGameControllerDirectionalPad: Rename methods
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 35e4d04158e744d988374ab8d70a03086556e5039d11839b4b46aa572978b84b
User & Date: js on 2024-06-08 19:32:08
Other Links: manifest | tags
Context
2024-06-08
19:36
ObjFWHID: Ignore Guide button on XInput 9.1.0 check-in: 256c4a696f user: js tags: trunk
19:32
OHGameControllerDirectionalPad: Rename methods check-in: 35e4d04158 user: js tags: trunk
19:26
OHGamepad: Add missing documentation check-in: 21d148d1f9 user: js tags: trunk
Changes

Modified src/hid/OHEvdevGamepad.m from [2d485491e2] to [00711b94af].

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
		   yAxis: yAxis] autorelease];
}

- (OHGameControllerDirectionalPad *)dPad
{
	OHGameControllerAxis *xAxis = [_rawProfile.axes objectForKey: @"HAT0X"];
	OHGameControllerAxis *yAxis = [_rawProfile.axes objectForKey: @"HAT0Y"];
	OHGameControllerButton *upButton, *downButton;
	OHGameControllerButton *leftButton, *rightButton;

	if (xAxis != nil && yAxis != nil)
		return [[[OHGameControllerDirectionalPad alloc]
		    initWithName: @"D-Pad"
			   xAxis: xAxis
			   yAxis: yAxis] autorelease];

	upButton = [_rawProfile.buttons objectForKey: @"D-Pad Up"];
	downButton = [_rawProfile.buttons objectForKey: @"D-Pad Down"];
	leftButton = [_rawProfile.buttons objectForKey: @"D-Pad Left"];
	rightButton = [_rawProfile.buttons objectForKey: @"D-Pad Right"];

	if (upButton != nil && downButton != nil &&
	    leftButton != nil && rightButton != nil)
		return [[[OHGameControllerDirectionalPad alloc]
		    initWithName: @"D-Pad"
			upButton: upButton
		      downButton: downButton
		      leftButton: leftButton
		     rightButton: rightButton] autorelease];

	return nil;
}
@end







|
<







|
|
|
|

<
|


|
|
|
|




203
204
205
206
207
208
209
210

211
212
213
214
215
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230
231
232
233
		   yAxis: yAxis] autorelease];
}

- (OHGameControllerDirectionalPad *)dPad
{
	OHGameControllerAxis *xAxis = [_rawProfile.axes objectForKey: @"HAT0X"];
	OHGameControllerAxis *yAxis = [_rawProfile.axes objectForKey: @"HAT0Y"];
	OHGameControllerButton *up, *down, *left, *right;


	if (xAxis != nil && yAxis != nil)
		return [[[OHGameControllerDirectionalPad alloc]
		    initWithName: @"D-Pad"
			   xAxis: xAxis
			   yAxis: yAxis] autorelease];

	up = [_rawProfile.buttons objectForKey: @"D-Pad Up"];
	down = [_rawProfile.buttons objectForKey: @"D-Pad Down"];
	left = [_rawProfile.buttons objectForKey: @"D-Pad Left"];
	right = [_rawProfile.buttons objectForKey: @"D-Pad Right"];


	if (up != nil && down != nil && left != nil && right != nil)
		return [[[OHGameControllerDirectionalPad alloc]
		    initWithName: @"D-Pad"
			      up: up
			    down: down
			    left: left
			   right: right] autorelease];

	return nil;
}
@end

Modified src/hid/OHGameControllerDirectionalPad.h from [773f283b6a] to [f9c0f28585].

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
 *
 * @brief An directional pad or thumb stick of a game controller.
 */
OF_SUBCLASSING_RESTRICTED
@interface OHGameControllerDirectionalPad: OHGameControllerElement
{
	OHGameControllerAxis *_xAxis, *_yAxis;
	OHGameControllerButton *_upButton, *_downButton;
	OHGameControllerButton *_leftButton, *_rightButton;
}

/**
 * @brief The X axis of the directional pad.
 */
@property (readonly, nonatomic) OHGameControllerAxis *xAxis;

/**
 * @brief The Y axis of the directional pad.
 */
@property (readonly, nonatomic) OHGameControllerAxis *yAxis;

/**
 * @brief The up button of the directional pad.
 */
@property (readonly, nonatomic) OHGameControllerButton *upButton;

/**
 * @brief The down button of the directional pad.
 */
@property (readonly, nonatomic) OHGameControllerButton *downButton;

/**
 * @brief The left button of the directional pad.
 */
@property (readonly, nonatomic) OHGameControllerButton *leftButton;

/**
 * @brief The right button of the directional pad.
 */
@property (readonly, nonatomic) OHGameControllerButton *rightButton;

- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE;

- (instancetype)initWithName: (OFString *)name
		       xAxis: (OHGameControllerAxis *)xAxis
		       yAxis: (OHGameControllerAxis *)yAxis;

- (instancetype)initWithName: (OFString *)name
		    upButton: (OHGameControllerButton *)upButton
		  downButton: (OHGameControllerButton *)downButton
		  leftButton: (OHGameControllerButton *)leftButton
		 rightButton: (OHGameControllerButton *)rightButton;
@end

OF_ASSUME_NONNULL_END







|
<















|




|




|




|








|
|
|
|



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
 *
 * @brief An directional pad or thumb stick of a game controller.
 */
OF_SUBCLASSING_RESTRICTED
@interface OHGameControllerDirectionalPad: OHGameControllerElement
{
	OHGameControllerAxis *_xAxis, *_yAxis;
	OHGameControllerButton *_up, *_down, *_left, *_right;

}

/**
 * @brief The X axis of the directional pad.
 */
@property (readonly, nonatomic) OHGameControllerAxis *xAxis;

/**
 * @brief The Y axis of the directional pad.
 */
@property (readonly, nonatomic) OHGameControllerAxis *yAxis;

/**
 * @brief The up button of the directional pad.
 */
@property (readonly, nonatomic) OHGameControllerButton *up;

/**
 * @brief The down button of the directional pad.
 */
@property (readonly, nonatomic) OHGameControllerButton *down;

/**
 * @brief The left button of the directional pad.
 */
@property (readonly, nonatomic) OHGameControllerButton *left;

/**
 * @brief The right button of the directional pad.
 */
@property (readonly, nonatomic) OHGameControllerButton *right;

- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE;

- (instancetype)initWithName: (OFString *)name
		       xAxis: (OHGameControllerAxis *)xAxis
		       yAxis: (OHGameControllerAxis *)yAxis;

- (instancetype)initWithName: (OFString *)name
			  up: (OHGameControllerButton *)up
			down: (OHGameControllerButton *)down
			left: (OHGameControllerButton *)left
		       right: (OHGameControllerButton *)right;
@end

OF_ASSUME_NONNULL_END

Modified src/hid/OHGameControllerDirectionalPad.m from [f54e2d335a] to [04d6b10457].

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

#import "OHGameControllerDirectionalPad.h"
#import "OHGameControllerEmulatedAxis.h"
#import "OHGameControllerEmulatedButton.h"

@implementation OHGameControllerDirectionalPad
@synthesize xAxis = _xAxis, yAxis = _yAxis;
@synthesize upButton = _upButton, downButton = _downButton;
@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]
		    initWithAxis: _yAxis
			positive: false];
		_downButton = [[OHGameControllerEmulatedButton alloc]
		    initWithAxis: _yAxis
			positive: true];
		_leftButton = [[OHGameControllerEmulatedButton alloc]
		    initWithAxis: _xAxis
			positive: false];
		_rightButton = [[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
{
	self = [super initWithName: name];

	@try {
		_upButton = [upButton retain];
		_downButton = [downButton retain];
		_leftButton = [leftButton retain];
		_rightButton = [rightButton retain];

		_xAxis = [[OHGameControllerEmulatedAxis alloc]
		    initWithNegativeButton: _leftButton
			    positiveButton: _rightButton];
		_yAxis = [[OHGameControllerEmulatedAxis alloc]
		    initWithNegativeButton: _upButton
			    positiveButton: _downButton];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_xAxis release];
	[_yAxis release];
	[_upButton release];
	[_downButton release];
	[_leftButton release];
	[_rightButton release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name];
}
@end







|
<
















|


|


|


|











|
|
|
|




|
|
|
|


|
|

|
|












|
|
|
|









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 up = _up, down = _down, left = _left, right = _right;


- (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];

		_up = [[OHGameControllerEmulatedButton alloc]
		    initWithAxis: _yAxis
			positive: false];
		_down = [[OHGameControllerEmulatedButton alloc]
		    initWithAxis: _yAxis
			positive: true];
		_left = [[OHGameControllerEmulatedButton alloc]
		    initWithAxis: _xAxis
			positive: false];
		_right = [[OHGameControllerEmulatedButton alloc]
		    initWithAxis: _xAxis
			positive: true];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)initWithName: (OFString *)name
			  up: (OHGameControllerButton *)up
			down: (OHGameControllerButton *)down
			left: (OHGameControllerButton *)left
		       right: (OHGameControllerButton *)right
{
	self = [super initWithName: name];

	@try {
		_up = [up retain];
		_down = [down retain];
		_left = [left retain];
		_right = [right retain];

		_xAxis = [[OHGameControllerEmulatedAxis alloc]
		    initWithNegativeButton: _left
			    positiveButton: _right];
		_yAxis = [[OHGameControllerEmulatedAxis alloc]
		    initWithNegativeButton: _up
			    positiveButton: _down];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_xAxis release];
	[_yAxis release];
	[_up release];
	[_down release];
	[_left release];
	[_right release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name];
}
@end

Modified src/hid/OHXInputGameController.m from [6b31e51715] to [4922b1a2cf].

207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
	_gamepad.rightThumbstick.xAxis.value =
	    (float)state.Gamepad.sThumbRX /
	    (state.Gamepad.sThumbRX < 0 ? -INT16_MIN : INT16_MAX);
	_gamepad.rightThumbstick.yAxis.value =
	    -(float)state.Gamepad.sThumbRY /
	    (state.Gamepad.sThumbRY < 0 ? -INT16_MIN : INT16_MAX);

	_gamepad.dPad.upButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP);
	_gamepad.dPad.downButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN);
	_gamepad.dPad.leftButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT);
	_gamepad.dPad.rightButton.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT);
}

- (OFString *)name
{
	switch (XInputVersion) {
	case 14:







|

|

|

|







207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
	_gamepad.rightThumbstick.xAxis.value =
	    (float)state.Gamepad.sThumbRX /
	    (state.Gamepad.sThumbRX < 0 ? -INT16_MIN : INT16_MAX);
	_gamepad.rightThumbstick.yAxis.value =
	    -(float)state.Gamepad.sThumbRY /
	    (state.Gamepad.sThumbRY < 0 ? -INT16_MIN : INT16_MAX);

	_gamepad.dPad.up.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP);
	_gamepad.dPad.down.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN);
	_gamepad.dPad.left.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT);
	_gamepad.dPad.right.value =
	    !!(state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT);
}

- (OFString *)name
{
	switch (XInputVersion) {
	case 14:

Modified src/hid/OHXInputGamepad.m from [4438c4bc5d] to [254b2085d9].

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableDictionary *buttons =
		    [OFMutableDictionary dictionaryWithCapacity: numButtons];
		OFMutableDictionary *directionalPads;
		OHGameControllerAxis *xAxis, *yAxis;
		OHGameControllerDirectionalPad *directionalPad;
		OHGameControllerButton *upButton, *downButton;
		OHGameControllerButton *leftButton, *rightButton;

		for (size_t i = 0; i < numButtons; i++) {
			OHGameControllerButton *button =
			    [[OHGameControllerButton alloc]
			    initWithName: buttonNames[i]];

			@try {







|
<







39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableDictionary *buttons =
		    [OFMutableDictionary dictionaryWithCapacity: numButtons];
		OFMutableDictionary *directionalPads;
		OHGameControllerAxis *xAxis, *yAxis;
		OHGameControllerDirectionalPad *directionalPad;
		OHGameControllerButton *up, *down, *left, *right;


		for (size_t i = 0; i < numButtons; i++) {
			OHGameControllerButton *button =
			    [[OHGameControllerButton alloc]
			    initWithName: buttonNames[i]];

			@try {
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
111
		directionalPad = [[[OHGameControllerDirectionalPad alloc]
		    initWithName: @"Right Thumbstick"
			   xAxis: xAxis
			   yAxis: yAxis] autorelease];
		[directionalPads setObject: directionalPad
				    forKey: @"Right Thumbstick"];

		upButton = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Up"] autorelease];
		downButton = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Down"] autorelease];
		leftButton = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Left"] autorelease];
		rightButton = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Right"] autorelease];
		directionalPad = [[[OHGameControllerDirectionalPad alloc]
		    initWithName: @"D-Pad"
			upButton: upButton
		      downButton: downButton
		      leftButton: leftButton
		     rightButton: rightButton] autorelease];
		[directionalPads setObject: directionalPad forKey: @"D-Pad"];

		[directionalPads makeImmutable];
		_directionalPads = [directionalPads retain];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {







|

|

|

|



|
|
|
|







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
		directionalPad = [[[OHGameControllerDirectionalPad alloc]
		    initWithName: @"Right Thumbstick"
			   xAxis: xAxis
			   yAxis: yAxis] autorelease];
		[directionalPads setObject: directionalPad
				    forKey: @"Right Thumbstick"];

		up = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Up"] autorelease];
		down = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Down"] autorelease];
		left = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Left"] autorelease];
		right = [[[OHGameControllerButton alloc]
		    initWithName: @"D-Pad Right"] autorelease];
		directionalPad = [[[OHGameControllerDirectionalPad alloc]
		    initWithName: @"D-Pad"
			      up: up
			    down: down
			    left: left
			   right: right] autorelease];
		[directionalPads setObject: directionalPad forKey: @"D-Pad"];

		[directionalPads makeImmutable];
		_directionalPads = [directionalPads retain];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {