ObjFW  Check-in [f02049612e]

Overview
Comment:OFGameController: Add constants for buttons
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | gamecontroller
Files: files | file ages | folders
SHA3-256: f02049612ed36af18faf6c0c0855f811e36231f0ff221b76c0400eb111b6ed8d
User & Date: js on 2024-05-09 19:05:14
Other Links: branch diff | manifest | tags
Context
2024-05-09
19:46
OFGameController: Support for pressure sensitivity check-in: 336ecd9bdc user: js tags: gamecontroller
19:05
OFGameController: Add constants for buttons check-in: f02049612e user: js tags: gamecontroller
18:13
OFGameController: Quirks for Xbox 360 controller check-in: 978e3bfb1e user: js tags: gamecontroller
Changes

Modified src/OFGameController.h from [90ee305e31] to [174eaaf8eb].

24
25
26
27
28
29
30






























































































































































31
32
33
34
35
36
37

/** @file */

@class OFArray OF_GENERIC(ObjectType);
@class OFMutableSet OF_GENERIC(ObjectType);
@class OFSet OF_GENERIC(ObjectType);































































































































































/**
 * @brief A class for reading state from a game controller.
 */
OF_SUBCLASSING_RESTRICTED
@interface OFGameController: OFObject
{
#ifdef OF_LINUX







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195

/** @file */

@class OFArray OF_GENERIC(ObjectType);
@class OFMutableSet OF_GENERIC(ObjectType);
@class OFSet OF_GENERIC(ObjectType);

/**
 * @brief A button on a controller.
 *
 * Possible values are:
 *
 *   * @ref OFGameControllerButtonA
 *   * @ref OFGameControllerButtonB
 *   * @ref OFGameControllerButtonC
 *   * @ref OFGameControllerButtonX
 *   * @ref OFGameControllerButtonY
 *   * @ref OFGameControllerButtonZ
 *   * @ref OFGameControllerButtonL
 *   * @ref OFGameControllerButtonR
 *   * @ref OFGameControllerButtonZL
 *   * @ref OFGameControllerButtonZR
 *   * @ref OFGameControllerButtonSelect
 *   * @ref OFGameControllerButtonStart
 *   * @ref OFGameControllerButtonHome
 *   * @ref OFGameControllerButtonLeftStick
 *   * @ref OFGameControllerButtonRightStick
 *   * @ref OFGameControllerButtonDPadUp
 *   * @ref OFGameControllerButtonDPadDown
 *   * @ref OFGameControllerButtonDPadLeft
 *   * @ref OFGameControllerButtonDPadRight
 *   * @ref OFGameControllerButtonCPadUp
 *   * @ref OFGameControllerButtonCPadDown
 *   * @ref OFGameControllerButtonCPadLeft
 *   * @ref OFGameControllerButtonCPadRight
 */
typedef OFConstantString *OFGameControllerButton;

#ifdef __cplusplus
extern "C" {
#endif
/**
 * @brief The A button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonA;

/**
 * @brief The B button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonB;

/**
 * @brief The C button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonC;

/**
 * @brief The X button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonX;

/**
 * @brief The Y button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonY;

/**
 * @brief The Z button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonZ;

/**
 * @brief The L button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonL;

/**
 * @brief The R button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonR;

/**
 * @brief The ZL button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonZL;

/**
 * @brief The ZR button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonZR;

/**
 * @brief The Select button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonSelect;

/**
 * @brief The Start button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonStart;

/**
 * @brief The Home button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonHome;

/**
 * @brief The Capture button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonCapture;

/**
 * @brief The left stick button (pressing the left stick) on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonLeftStick;

/**
 * @brief The right stick button (pressing the right stick) on a game
 *	  controller.
 */
extern const OFGameControllerButton OFGameControllerButtonRightStick;

/**
 * @brief The D-Pad Up button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonDPadUp;

/**
 * @brief The D-Pad Down button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonDPadDown;

/**
 * @brief The D-Pad Left button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonDPadLeft;

/**
 * @brief The D-Pad Right button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonDPadRight;

/**
 * @brief The C-Pad Up button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonCPadUp;

/**
 * @brief The C-Pad Down button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonCPadDown;

/**
 * @brief The C-Pad Left button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonCPadLeft;

/**
 * @brief The C-Pad Right button on a game controller.
 */
extern const OFGameControllerButton OFGameControllerButtonCPadRight;
#ifdef __cplusplus
}
#endif

/**
 * @brief A class for reading state from a game controller.
 */
OF_SUBCLASSING_RESTRICTED
@interface OFGameController: OFObject
{
#ifdef OF_LINUX

Modified src/OFGameController.m from [07bd6ec7f8] to [b3fdaf3904].

20
21
22
23
24
25
26

























27
28
29
30
31
32
33
#include "config.h"

#import "OFGameController.h"
#import "OFArray.h"

#import "OFOutOfRangeException.h"


























#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
# include "platform/Linux/OFGameController.m"
#elif defined(OF_NINTENDO_DS)
# include "platform/NintendoDS/OFGameController.m"
#elif defined(OF_NINTENDO_3DS)
# include "platform/Nintendo3DS/OFGameController.m"
#else







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







20
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
#include "config.h"

#import "OFGameController.h"
#import "OFArray.h"

#import "OFOutOfRangeException.h"

const OFGameControllerButton OFGameControllerButtonA = @"A";
const OFGameControllerButton OFGameControllerButtonB = @"B";
const OFGameControllerButton OFGameControllerButtonC = @"C";
const OFGameControllerButton OFGameControllerButtonX = @"X";
const OFGameControllerButton OFGameControllerButtonY = @"Y";
const OFGameControllerButton OFGameControllerButtonZ = @"Z";
const OFGameControllerButton OFGameControllerButtonL = @"L";
const OFGameControllerButton OFGameControllerButtonR = @"R";
const OFGameControllerButton OFGameControllerButtonZL = @"ZL";
const OFGameControllerButton OFGameControllerButtonZR = @"ZR";
const OFGameControllerButton OFGameControllerButtonSelect = @"Select";
const OFGameControllerButton OFGameControllerButtonStart = @"Start";
const OFGameControllerButton OFGameControllerButtonHome = @"Home";
const OFGameControllerButton OFGameControllerButtonCapture = @"Capture";
const OFGameControllerButton OFGameControllerButtonLeftStick = @"Left Stick";
const OFGameControllerButton OFGameControllerButtonRightStick = @"Right Stick";
const OFGameControllerButton OFGameControllerButtonDPadUp = @"D-Pad Up";
const OFGameControllerButton OFGameControllerButtonDPadDown = @"D-Pad Down";
const OFGameControllerButton OFGameControllerButtonDPadLeft = @"D-Pad Left";
const OFGameControllerButton OFGameControllerButtonDPadRight = @"D-Pad Right";
const OFGameControllerButton OFGameControllerButtonCPadUp = @"C-Pad Up";
const OFGameControllerButton OFGameControllerButtonCPadDown = @"C-Pad Down";
const OFGameControllerButton OFGameControllerButtonCPadLeft = @"C-Pad Left";
const OFGameControllerButton OFGameControllerButtonCPadRight = @"C-Pad Right";

#if defined(OF_LINUX) && defined(OF_HAVE_FILES)
# include "platform/Linux/OFGameController.m"
#elif defined(OF_NINTENDO_DS)
# include "platform/NintendoDS/OFGameController.m"
#elif defined(OF_NINTENDO_3DS)
# include "platform/Nintendo3DS/OFGameController.m"
#else

Modified src/platform/Linux/OFGameController.m from [470c008fba] to [25579e0c0b].

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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
		case BTN_Z:
			return nil;
		}
	} else if (vendorID == vendorIDNintendo &&
	    productID == productIDN64Controller) {
		switch (button) {
		case BTN_TL2:
			return @"Z";
		case BTN_Y:
			return @"C-Stick Left";
		case BTN_C:
			return @"C-Stick Right";
		case BTN_SELECT:
			return @"C-Stick Up";
		case BTN_X:
			return @"C-Stick Down";
		case BTN_MODE:
			return @"Home";
		case BTN_Z:
			return @"Capture";
		case BTN_THUMBL:
		case BTN_THUMBR:
			return nil;
		}
	}

	switch (button) {
	case BTN_A:
		return @"A";
	case BTN_B:
		return @"B";
	case BTN_C:
		return @"C";
	case BTN_X:
		return @"X";
	case BTN_Y:
		return @"Y";
	case BTN_Z:
		return @"Z";
	case BTN_TL:
		return @"L";
	case BTN_TR:
		return @"R";
	case BTN_TL2:
		return @"ZL";
	case BTN_TR2:
		return @"ZR";
	case BTN_SELECT:
		return @"Select";
	case BTN_START:
		return @"Start";
	case BTN_MODE:
		return @"Home";
	case BTN_THUMBL:
		return @"Left Stick";
	case BTN_THUMBR:
		return @"Right Stick";
	case BTN_DPAD_UP:
		return @"D-Pad Up";
	case BTN_DPAD_DOWN:
		return @"D-Pad Down";
	case BTN_DPAD_LEFT:
		return @"D-Pad Left";
	case BTN_DPAD_RIGHT:
		return @"D-Pad Right";
	}

	return nil;
}

static float
scale(float value, float min, float max)







|

|

|

|

|

|

|








|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|







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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
		case BTN_Z:
			return nil;
		}
	} else if (vendorID == vendorIDNintendo &&
	    productID == productIDN64Controller) {
		switch (button) {
		case BTN_TL2:
			return OFGameControllerButtonZ;
		case BTN_Y:
			return OFGameControllerButtonCPadLeft;
		case BTN_C:
			return OFGameControllerButtonCPadRight;
		case BTN_SELECT:
			return OFGameControllerButtonCPadUp;
		case BTN_X:
			return OFGameControllerButtonCPadDown;
		case BTN_MODE:
			return OFGameControllerButtonHome;
		case BTN_Z:
			return OFGameControllerButtonCapture;
		case BTN_THUMBL:
		case BTN_THUMBR:
			return nil;
		}
	}

	switch (button) {
	case BTN_A:
		return OFGameControllerButtonA;
	case BTN_B:
		return OFGameControllerButtonB;
	case BTN_C:
		return OFGameControllerButtonC;
	case BTN_X:
		return OFGameControllerButtonX;
	case BTN_Y:
		return OFGameControllerButtonY;
	case BTN_Z:
		return OFGameControllerButtonZ;
	case BTN_TL:
		return OFGameControllerButtonL;
	case BTN_TR:
		return OFGameControllerButtonR;
	case BTN_TL2:
		return OFGameControllerButtonZL;
	case BTN_TR2:
		return OFGameControllerButtonZR;
	case BTN_SELECT:
		return OFGameControllerButtonSelect;
	case BTN_START:
		return OFGameControllerButtonStart;
	case BTN_MODE:
		return OFGameControllerButtonHome;
	case BTN_THUMBL:
		return OFGameControllerButtonLeftStick;
	case BTN_THUMBR:
		return OFGameControllerButtonRightStick;
	case BTN_DPAD_UP:
		return OFGameControllerButtonDPadUp;
	case BTN_DPAD_DOWN:
		return OFGameControllerButtonDPadDown;
	case BTN_DPAD_LEFT:
		return OFGameControllerButtonDPadLeft;
	case BTN_DPAD_RIGHT:
		return OFGameControllerButtonDPadRight;
	}

	return nil;
}

static float
scale(float value, float min, float max)
297
298
299
300
301
302
303
304

305

306

307

308
309
310
311
312
313
314
315
316
317
318
319
320
				_rightAnalogStickMaxX = infoX.maximum;
				_rightAnalogStickMinY = infoY.minimum;
				_rightAnalogStickMaxY = infoY.maximum;
			}

			if (OFBitSetIsSet(absBits, ABS_HAT0X) &&
			    OFBitSetIsSet(absBits, ABS_HAT0Y)) {
				[_buttons addObject: @"D-Pad Left"];

				[_buttons addObject: @"D-Pad Right"];

				[_buttons addObject: @"D-Pad Up"];

				[_buttons addObject: @"D-Pad Down"];

			}

			if (OFBitSetIsSet(absBits, ABS_Z))
				[_buttons addObject: @"ZL"];
			if (OFBitSetIsSet(absBits, ABS_RZ))
				[_buttons addObject: @"ZR"];
		}

		[_buttons makeImmutable];
	} @catch (id e) {
		[self release];
		@throw e;
	}







|
>
|
>
|
>
|
>



|

|







297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
				_rightAnalogStickMaxX = infoX.maximum;
				_rightAnalogStickMinY = infoY.minimum;
				_rightAnalogStickMaxY = infoY.maximum;
			}

			if (OFBitSetIsSet(absBits, ABS_HAT0X) &&
			    OFBitSetIsSet(absBits, ABS_HAT0Y)) {
				[_buttons addObject:
				    OFGameControllerButtonDPadLeft];
				[_buttons addObject:
				    OFGameControllerButtonDPadRight];
				[_buttons addObject:
				    OFGameControllerButtonDPadUp];
				[_buttons addObject:
				    OFGameControllerButtonDPadDown];
			}

			if (OFBitSetIsSet(absBits, ABS_Z))
				[_buttons addObject: OFGameControllerButtonZL];
			if (OFBitSetIsSet(absBits, ABS_RZ))
				[_buttons addObject: OFGameControllerButtonZR];
		}

		[_buttons makeImmutable];
	} @catch (id e) {
		[self release];
		@throw e;
	}
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426

427
428

429
430
431
432

433
434

435
436
437
438
439
440
441
				_rightAnalogStickPosition.y = scale(event.value,
				    _rightAnalogStickMinY,
				    _rightAnalogStickMaxY);
				break;
			case ABS_HAT0X:
				if (event.value < 0) {
					[_pressedButtons addObject:
					    @"D-Pad Left"];
					[_pressedButtons removeObject:
					    @"D-Pad Right"];
				} else if (event.value > 0) {
					[_pressedButtons addObject:
					    @"D-Pad Right"];
					[_pressedButtons removeObject:
					    @"D-Pad Left"];
				} else {
					[_pressedButtons removeObject:
					    @"D-Pad Left"];
					[_pressedButtons removeObject:
					    @"D-Pad Right"];
				}
				break;
			case ABS_HAT0Y:
				if (event.value < 0) {
					[_pressedButtons addObject:
					    @"D-Pad Up"];
					[_pressedButtons removeObject:
					    @"D-Pad Down"];
				} else if (event.value > 0) {
					[_pressedButtons addObject:
					    @"D-Pad Down"];
					[_pressedButtons removeObject:
					    @"D-Pad Up"];
				} else {
					[_pressedButtons removeObject:
					    @"D-Pad Up"];
					[_pressedButtons removeObject:
					    @"D-Pad Down"];
				}
				break;
			case ABS_Z:
				if (event.value > 0)
					[_pressedButtons addObject: @"ZL"];

				else
					[_pressedButtons removeObject: @"ZL"];

				break;
			case ABS_RZ:
				if (event.value > 0)
					[_pressedButtons addObject: @"ZR"];

				else
					[_pressedButtons removeObject: @"ZR"];

				break;
			}

			break;
		}
	}
}







|

|


|

|


|

|





|

|


|

|


|

|




|
>

|
>



|
>

|
>







388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
				_rightAnalogStickPosition.y = scale(event.value,
				    _rightAnalogStickMinY,
				    _rightAnalogStickMaxY);
				break;
			case ABS_HAT0X:
				if (event.value < 0) {
					[_pressedButtons addObject:
					    OFGameControllerButtonDPadLeft];
					[_pressedButtons removeObject:
					    OFGameControllerButtonDPadRight];
				} else if (event.value > 0) {
					[_pressedButtons addObject:
					    OFGameControllerButtonDPadRight];
					[_pressedButtons removeObject:
					    OFGameControllerButtonDPadLeft];
				} else {
					[_pressedButtons removeObject:
					    OFGameControllerButtonDPadLeft];
					[_pressedButtons removeObject:
					    OFGameControllerButtonDPadRight];
				}
				break;
			case ABS_HAT0Y:
				if (event.value < 0) {
					[_pressedButtons addObject:
					    OFGameControllerButtonDPadUp];
					[_pressedButtons removeObject:
					    OFGameControllerButtonDPadDown];
				} else if (event.value > 0) {
					[_pressedButtons addObject:
					    OFGameControllerButtonDPadDown];
					[_pressedButtons removeObject:
					    OFGameControllerButtonDPadUp];
				} else {
					[_pressedButtons removeObject:
					    OFGameControllerButtonDPadUp];
					[_pressedButtons removeObject:
					    OFGameControllerButtonDPadDown];
				}
				break;
			case ABS_Z:
				if (event.value > 0)
					[_pressedButtons addObject:
					    OFGameControllerButtonZL];
				else
					[_pressedButtons removeObject:
					    OFGameControllerButtonZL];
				break;
			case ABS_RZ:
				if (event.value > 0)
					[_pressedButtons addObject:
					    OFGameControllerButtonZR];
				else
					[_pressedButtons removeObject:
					    OFGameControllerButtonZR];
				break;
			}

			break;
		}
	}
}

Modified src/platform/Nintendo3DS/OFGameController.m from [f6f05e83f5] to [cde2b51e73].

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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
- (OFString *)name
{
	return @"Nintendo 3DS";
}

- (OFSet *)buttons
{
	return [OFSet setWithObjects: @"A", @"B", @"Select", @"Start",
	    @"D-Pad Right", @"D-Pad Left", @"D-Pad Up", @"D-Pad Down", @"R",
	    @"L", @"X", @"Y", @"ZL", @"ZR", @"C-Stick Right", @"C-Stick Left",






	    @"C-Stick Up", @"C-Stick Down", nil];
}

- (OFSet *)pressedButtons
{
	OFMutableSet *pressedButtons = [OFMutableSet setWithCapacity: 18];
	u32 keys;

	hidScanInput();
	keys = hidKeysHeld();

	if (keys & KEY_A)
		[pressedButtons addObject: @"A"];
	if (keys & KEY_B)
		[pressedButtons addObject: @"A"];
	if (keys & KEY_SELECT)
		[pressedButtons addObject: @"Select"];
	if (keys & KEY_START)
		[pressedButtons addObject: @"Start"];
	if (keys & KEY_DRIGHT)
		[pressedButtons addObject: @"D-Pad Right"];
	if (keys & KEY_DLEFT)
		[pressedButtons addObject: @"D-Pad Left"];
	if (keys & KEY_DUP)
		[pressedButtons addObject: @"D-Pad Up"];
	if (keys & KEY_DDOWN)
		[pressedButtons addObject: @"D-Pad Down"];
	if (keys & KEY_R)
		[pressedButtons addObject: @"R"];
	if (keys & KEY_L)
		[pressedButtons addObject: @"L"];
	if (keys & KEY_X)
		[pressedButtons addObject: @"X"];
	if (keys & KEY_Y)
		[pressedButtons addObject: @"Y"];
	if (keys & KEY_ZL)
		[pressedButtons addObject: @"ZL"];
	if (keys & KEY_ZR)
		[pressedButtons addObject: @"ZR"];
	if (keys & KEY_CSTICK_RIGHT)
		[pressedButtons addObject: @"C-Stick Right"];
	if (keys & KEY_CSTICK_LEFT)
		[pressedButtons addObject: @"C-Stick Left"];
	if (keys & KEY_CSTICK_UP)
		[pressedButtons addObject: @"C-Stick Up"];
	if (keys & KEY_CSTICK_DOWN)
		[pressedButtons addObject: @"C-Stick Down"];

	[pressedButtons makeImmutable];

	return pressedButtons;
}

- (bool)hasLeftAnalogStick







|
|
|
>
>
>
>
>
>
|











|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|







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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
- (OFString *)name
{
	return @"Nintendo 3DS";
}

- (OFSet *)buttons
{
	return [OFSet setWithObjects: OFGameControllerButtonA,
	    OFGameControllerButtonB, OFGameControllerButtonSelect,
	    OFGameControllerButtonStart, OFGameControllerButtonDPadRight,
	    OFGameControllerButtonDPadLeft, OFGameControllerButtonDPadUp,
	    OFGameControllerButtonDPadDown, OFGameControllerButtonR,
	    OFGameControllerButtonL, OFGameControllerButtonX,
	    OFGameControllerButtonY, OFGameControllerButtonZL,
	    OFGameControllerButtonZR, OFGameControllerButtonCPadRight,
	    OFGameControllerButtonCPadLeft, OFGameControllerButtonCPadUp,
	    OFGameControllerButtonCPadDown, nil];
}

- (OFSet *)pressedButtons
{
	OFMutableSet *pressedButtons = [OFMutableSet setWithCapacity: 18];
	u32 keys;

	hidScanInput();
	keys = hidKeysHeld();

	if (keys & KEY_A)
		[pressedButtons addObject: OFGameControllerButtonA];
	if (keys & KEY_B)
		[pressedButtons addObject: OFGameControllerButtonB];
	if (keys & KEY_SELECT)
		[pressedButtons addObject: OFGameControllerButtonSelect];
	if (keys & KEY_START)
		[pressedButtons addObject: OFGameControllerButtonStart];
	if (keys & KEY_DRIGHT)
		[pressedButtons addObject: OFGameControllerButtonDPadRight];
	if (keys & KEY_DLEFT)
		[pressedButtons addObject: OFGameControllerButtonDPadLeft];
	if (keys & KEY_DUP)
		[pressedButtons addObject: OFGameControllerButtonDPadUp];
	if (keys & KEY_DDOWN)
		[pressedButtons addObject: OFGameControllerButtonDPadDown];
	if (keys & KEY_R)
		[pressedButtons addObject: OFGameControllerButtonR];
	if (keys & KEY_L)
		[pressedButtons addObject: OFGameControllerButtonL];
	if (keys & KEY_X)
		[pressedButtons addObject: OFGameControllerButtonX];
	if (keys & KEY_Y)
		[pressedButtons addObject: OFGameControllerButtonY];
	if (keys & KEY_ZL)
		[pressedButtons addObject: OFGameControllerButtonZL];
	if (keys & KEY_ZR)
		[pressedButtons addObject: OFGameControllerButtonZR];
	if (keys & KEY_CSTICK_RIGHT)
		[pressedButtons addObject: OFGameControllerButtonCPadRight];
	if (keys & KEY_CSTICK_LEFT)
		[pressedButtons addObject: OFGameControllerButtonCPadLeft];
	if (keys & KEY_CSTICK_UP)
		[pressedButtons addObject: OFGameControllerButtonCPadUp];
	if (keys & KEY_CSTICK_DOWN)
		[pressedButtons addObject: OFGameControllerButtonCPadDown];

	[pressedButtons makeImmutable];

	return pressedButtons;
}

- (bool)hasLeftAnalogStick

Modified src/platform/NintendoDS/OFGameController.m from [178427af22] to [3f4b233e3e].

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
111
112
113
114
115
116
117
118
119
120
121
- (OFString *)name
{
	return @"Nintendo DS";
}

- (OFSet *)buttons
{
	return [OFSet setWithObjects: @"A", @"B", @"Select", @"Start",
	    @"D-Pad Right", @"D-Pad Left", @"D-Pad Up", @"D-Pad Down", @"R",




	    @"L", @"X", @"Y", nil];
}

- (OFSet *)pressedButtons
{
	OFMutableSet *pressedButtons = [OFMutableSet setWithCapacity: 12];
	uint32 keys;

	scanKeys();
	keys = keysCurrent();

	if (keys & KEY_A)
		[pressedButtons addObject: @"A"];
	if (keys & KEY_B)
		[pressedButtons addObject: @"A"];
	if (keys & KEY_SELECT)
		[pressedButtons addObject: @"Select"];
	if (keys & KEY_START)
		[pressedButtons addObject: @"Start"];
	if (keys & KEY_RIGHT)
		[pressedButtons addObject: @"D-Pad Right"];
	if (keys & KEY_LEFT)
		[pressedButtons addObject: @"D-Pad Left"];
	if (keys & KEY_UP)
		[pressedButtons addObject: @"D-Pad Up"];
	if (keys & KEY_DOWN)
		[pressedButtons addObject: @"D-Pad Down"];
	if (keys & KEY_R)
		[pressedButtons addObject: @"R"];
	if (keys & KEY_L)
		[pressedButtons addObject: @"L"];
	if (keys & KEY_X)
		[pressedButtons addObject: @"X"];
	if (keys & KEY_Y)
		[pressedButtons addObject: @"Y"];

	[pressedButtons makeImmutable];

	return pressedButtons;
}

- (bool)hasLeftAnalogStick







|
|
>
>
>
>
|











|

|

|

|

|

|

|

|

|

|

|

|







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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
- (OFString *)name
{
	return @"Nintendo DS";
}

- (OFSet *)buttons
{
	return [OFSet setWithObjects: OFGameControllerButtonA,
	    OFGameControllerButtonB, OFGameControllerButtonSelect,
	    OFGameControllerButtonStart, OFGameControllerButtonDPadRight,
	    OFGameControllerButtonDPadLeft, OFGameControllerButtonDPadUp,
	    OFGameControllerButtonDPadDown, OFGameControllerButtonR,
	    OFGameControllerButtonL, OFGameControllerButtonX,
	    OFGameControllerButtonY, nil];
}

- (OFSet *)pressedButtons
{
	OFMutableSet *pressedButtons = [OFMutableSet setWithCapacity: 12];
	uint32 keys;

	scanKeys();
	keys = keysCurrent();

	if (keys & KEY_A)
		[pressedButtons addObject: OFGameControllerButtonA];
	if (keys & KEY_B)
		[pressedButtons addObject: OFGameControllerButtonB];
	if (keys & KEY_SELECT)
		[pressedButtons addObject: OFGameControllerButtonSelect];
	if (keys & KEY_START)
		[pressedButtons addObject: OFGameControllerButtonStart];
	if (keys & KEY_RIGHT)
		[pressedButtons addObject: OFGameControllerButtonDPadRight];
	if (keys & KEY_LEFT)
		[pressedButtons addObject: OFGameControllerButtonDPadLeft];
	if (keys & KEY_UP)
		[pressedButtons addObject: OFGameControllerButtonDPadUp];
	if (keys & KEY_DOWN)
		[pressedButtons addObject: OFGameControllerButtonDPadDown];
	if (keys & KEY_R)
		[pressedButtons addObject: OFGameControllerButtonR];
	if (keys & KEY_L)
		[pressedButtons addObject: OFGameControllerButtonL];
	if (keys & KEY_X)
		[pressedButtons addObject: OFGameControllerButtonX];
	if (keys & KEY_Y)
		[pressedButtons addObject: OFGameControllerButtonY];

	[pressedButtons makeImmutable];

	return pressedButtons;
}

- (bool)hasLeftAnalogStick