ObjFW  Check-in [59b45e87d1]

Overview
Comment:OFGameController: {north,south,west,east}Button
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | gamecontroller
Files: files | file ages | folders
SHA3-256: 59b45e87d19487a3d38853af4da3ab2f4ee006b3e40ab74ae70f46a414ea1c81
User & Date: js on 2024-05-11 21:56:42
Other Links: branch diff | manifest | tags
Context
2024-05-12
13:07
OFGameController: {vendor,product}ID on Windows check-in: 8815b72dad user: js tags: gamecontroller
2024-05-11
21:56
OFGameController: {north,south,west,east}Button check-in: 59b45e87d1 user: js tags: gamecontroller
10:19
OFGameController: Add quirks for Joycons check-in: 1da303e600 user: js tags: gamecontroller
Changes

Modified src/OFGameController.h from [dd47275cc1] to [5a5c795ad8].

302
303
304
305
306
307
308
























309
310
311
312
313
314
315
/**
 * @brief The position of the right analog stick.
 *
 * The range is from (-1, -1) to (1, 1).
 */
@property (readonly, nonatomic) OFPoint rightAnalogStickPosition;

























/**
 * @brief Returns the available controllers.
 *
 * @return The available controllers
 */
+ (OFArray OF_GENERIC(OFGameController *) *)controllers;








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







302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/**
 * @brief The position of the right analog stick.
 *
 * The range is from (-1, -1) to (1, 1).
 */
@property (readonly, nonatomic) OFPoint rightAnalogStickPosition;

/**
 * @brief The north button on the right diamond pad or `nil` if there is none.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    OFGameControllerButton northButton;

/**
 * @brief The south button on the right diamond pad or `nil` if there is none.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    OFGameControllerButton southButton;

/**
 * @brief The west button on the right diamond pad or `nil` if there is none.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    OFGameControllerButton westButton;

/**
 * @brief The east button on the right diamond pad or `nil` if there is none.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    OFGameControllerButton eastButton;

/**
 * @brief Returns the available controllers.
 *
 * @return The available controllers
 */
+ (OFArray OF_GENERIC(OFGameController *) *)controllers;

Modified src/OFGameController.m from [31e4b70394] to [c4bdc74964].

60
61
62
63
64
65
66

67
68
69
70
71
72
73
# include "platform/NintendoDS/OFGameController.m"
#elif defined(OF_NINTENDO_3DS)
# include "platform/Nintendo3DS/OFGameController.m"
#else
@implementation OFGameController
@dynamic name, buttons, pressedButtons, hasLeftAnalogStick;
@dynamic leftAnalogStickPosition, hasRightAnalogStick, rightAnalogStickPosition;


+ (OFArray OF_GENERIC(OFGameController *) *)controllers
{
	return [OFArray array];
}

- (instancetype)init







>







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# include "platform/NintendoDS/OFGameController.m"
#elif defined(OF_NINTENDO_3DS)
# include "platform/Nintendo3DS/OFGameController.m"
#else
@implementation OFGameController
@dynamic name, buttons, pressedButtons, hasLeftAnalogStick;
@dynamic leftAnalogStickPosition, hasRightAnalogStick, rightAnalogStickPosition;
@dynamic northButton, southButton, westButton, eastButton;

+ (OFArray OF_GENERIC(OFGameController *) *)controllers
{
	return [OFArray array];
}

- (instancetype)init

Modified src/platform/Linux/OFGameController.m from [a552f91d7e] to [cec84b63cd].

532
533
534
535
536
537
538




















































539
540
541
542
543
544
	if (button == OFGameControllerButtonZL && _hasZLPressure)
		return _ZLPressure;
	if (button == OFGameControllerButtonZR && _hasZRPressure)
		return _ZRPressure;

	return ([self.pressedButtons containsObject: button] ? 1 : 0);
}





















































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







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






532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
	if (button == OFGameControllerButtonZL && _hasZLPressure)
		return _ZLPressure;
	if (button == OFGameControllerButtonZR && _hasZRPressure)
		return _ZRPressure;

	return ([self.pressedButtons containsObject: button] ? 1 : 0);
}

- (OFGameControllerButton)northButton
{
	if (_vendorID == vendorIDNintendo && _productID == productIDLeftJoycon)
		return nil;
	if (_vendorID == vendorIDNintendo && _productID == productIDRightJoycon)
		return OFGameControllerButtonX;
	if (_vendorID == vendorIDNintendo &&
	    _productID == productIDN64Controller)
		return nil;

	return OFGameControllerButtonY;
}

- (OFGameControllerButton)southButton
{
	if (_vendorID == vendorIDNintendo && _productID == productIDLeftJoycon)
		return nil;
	if (_vendorID == vendorIDNintendo && _productID == productIDRightJoycon)
		return OFGameControllerButtonB;
	if (_vendorID == vendorIDNintendo &&
	    _productID == productIDN64Controller)
		return nil;

	return OFGameControllerButtonA;
}

- (OFGameControllerButton)westButton
{
	if (_vendorID == vendorIDNintendo && _productID == productIDLeftJoycon)
		return nil;
	if (_vendorID == vendorIDNintendo && _productID == productIDRightJoycon)
		return OFGameControllerButtonY;
	if (_vendorID == vendorIDNintendo &&
	    _productID == productIDN64Controller)
		return nil;

	return OFGameControllerButtonX;
}

- (OFGameControllerButton)eastButton
{
	if (_vendorID == vendorIDNintendo && _productID == productIDLeftJoycon)
		return nil;
	if (_vendorID == vendorIDNintendo && _productID == productIDRightJoycon)
		return OFGameControllerButtonA;
	if (_vendorID == vendorIDNintendo &&
	    _productID == productIDN64Controller)
		return nil;

	return OFGameControllerButtonB;
}

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

Modified src/platform/Nintendo3DS/OFGameController.m from [e9a5f2027b] to [4e207caf2f].

185
186
187
188
189
190
191




















192
193
194
195
196
197
	return false;
}

- (float)pressureForButton: (OFGameControllerButton)button
{
	return ([self.pressedButtons containsObject: button] ? 1 : 0);
}





















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







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






185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
	return false;
}

- (float)pressureForButton: (OFGameControllerButton)button
{
	return ([self.pressedButtons containsObject: button] ? 1 : 0);
}

- (OFGameControllerButton)northButton
{
	return OFGameControllerButtonX;
}

- (OFGameControllerButton)southButton
{
	return OFGameControllerButtonB;
}

- (OFGameControllerButton)westButton
{
	return OFGameControllerButtonY;
}

- (OFGameControllerButton)eastButton
{
	return OFGameControllerButtonA;
}

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

Modified src/platform/NintendoDS/OFGameController.m from [a3027c8fb5] to [2d083ad50e].

162
163
164
165
166
167
168




















169
170
171
172
173
174
	return false;
}

- (float)pressureForButton: (OFGameControllerButton)button
{
	return ([self.pressedButtons containsObject: button] ? 1 : 0);
}





















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







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






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
	return false;
}

- (float)pressureForButton: (OFGameControllerButton)button
{
	return ([self.pressedButtons containsObject: button] ? 1 : 0);
}

- (OFGameControllerButton)northButton
{
	return OFGameControllerButtonX;
}

- (OFGameControllerButton)southButton
{
	return OFGameControllerButtonB;
}

- (OFGameControllerButton)westButton
{
	return OFGameControllerButtonY;
}

- (OFGameControllerButton)eastButton
{
	return OFGameControllerButtonA;
}

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

Modified src/platform/Windows/OFGameController.m from [0f49be7a6d] to [102a468920].

223
224
225
226
227
228
229




















230
231
232
233
234
235
	if (button == OFGameControllerButtonZL)
		return _ZLPressure;
	if (button == OFGameControllerButtonZR)
		return _ZRPressure;

	return ([self.pressedButtons containsObject: button] ? 1 : 0);
}





















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







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






223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
	if (button == OFGameControllerButtonZL)
		return _ZLPressure;
	if (button == OFGameControllerButtonZR)
		return _ZRPressure;

	return ([self.pressedButtons containsObject: button] ? 1 : 0);
}

- (OFGameControllerButton)northButton
{
	return OFGameControllerButtonY;
}

- (OFGameControllerButton)southButton
{
	return OFGameControllerButtonA;
}

- (OFGameControllerButton)westButton
{
	return OFGameControllerButtonX;
}

- (OFGameControllerButton)eastButton
{
	return OFGameControllerButtonB;
}

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

Modified tests/gamecontroller/GameControllerTests.m from [77c7b12639] to [2e38947e29].

55
56
57
58
59
60
61

62



63
64
65
66
67
68
69
			    controller.productID != nil) {
				[OFStdOut setForegroundColor: [OFColor teal]];
				[OFStdOut writeFormat: @" [%04X:%04X]",
				    controller.vendorID.unsignedShortValue,
				    controller.productID.unsignedShortValue];
			}


			[OFStdOut writeString: @"\n"];




			[controller retrieveState];

			for (OFGameControllerButton button in buttons) {
				float pressure =
				    [controller pressureForButton: button];








>
|
>
>
>







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
			    controller.productID != nil) {
				[OFStdOut setForegroundColor: [OFColor teal]];
				[OFStdOut writeFormat: @" [%04X:%04X]",
				    controller.vendorID.unsignedShortValue,
				    controller.productID.unsignedShortValue];
			}

			[OFStdOut setForegroundColor: [OFColor blue]];
			[OFStdOut writeFormat:
			    @"\nNorth: %@  South: %@  West: %@  East: %@\n",
			    controller.northButton, controller.southButton,
			    controller.westButton, controller.eastButton];

			[controller retrieveState];

			for (OFGameControllerButton button in buttons) {
				float pressure =
				    [controller pressureForButton: button];