ObjFW  Diff

Differences From Artifact [470c008fba]:

To Artifact [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;
		}
	}
}