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
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";
			return OFGameControllerButtonZ;
		case BTN_Y:
			return @"C-Stick Left";
			return OFGameControllerButtonCPadLeft;
		case BTN_C:
			return @"C-Stick Right";
			return OFGameControllerButtonCPadRight;
		case BTN_SELECT:
			return @"C-Stick Up";
			return OFGameControllerButtonCPadUp;
		case BTN_X:
			return @"C-Stick Down";
			return OFGameControllerButtonCPadDown;
		case BTN_MODE:
			return @"Home";
			return OFGameControllerButtonHome;
		case BTN_Z:
			return @"Capture";
			return OFGameControllerButtonCapture;
		case BTN_THUMBL:
		case BTN_THUMBR:
			return nil;
		}
	}

	switch (button) {
	case BTN_A:
		return @"A";
		return OFGameControllerButtonA;
	case BTN_B:
		return @"B";
		return OFGameControllerButtonB;
	case BTN_C:
		return @"C";
		return OFGameControllerButtonC;
	case BTN_X:
		return @"X";
		return OFGameControllerButtonX;
	case BTN_Y:
		return @"Y";
		return OFGameControllerButtonY;
	case BTN_Z:
		return @"Z";
		return OFGameControllerButtonZ;
	case BTN_TL:
		return @"L";
		return OFGameControllerButtonL;
	case BTN_TR:
		return @"R";
		return OFGameControllerButtonR;
	case BTN_TL2:
		return @"ZL";
		return OFGameControllerButtonZL;
	case BTN_TR2:
		return @"ZR";
		return OFGameControllerButtonZR;
	case BTN_SELECT:
		return @"Select";
		return OFGameControllerButtonSelect;
	case BTN_START:
		return @"Start";
		return OFGameControllerButtonStart;
	case BTN_MODE:
		return @"Home";
		return OFGameControllerButtonHome;
	case BTN_THUMBL:
		return @"Left Stick";
		return OFGameControllerButtonLeftStick;
	case BTN_THUMBR:
		return @"Right Stick";
		return OFGameControllerButtonRightStick;
	case BTN_DPAD_UP:
		return @"D-Pad Up";
		return OFGameControllerButtonDPadUp;
	case BTN_DPAD_DOWN:
		return @"D-Pad Down";
		return OFGameControllerButtonDPadDown;
	case BTN_DPAD_LEFT:
		return @"D-Pad Left";
		return OFGameControllerButtonDPadLeft;
	case BTN_DPAD_RIGHT:
		return @"D-Pad 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
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: @"D-Pad Left"];
				[_buttons addObject: @"D-Pad Right"];
				[_buttons addObject: @"D-Pad Up"];
				[_buttons addObject: @"D-Pad Down"];
				[_buttons addObject:
				    OFGameControllerButtonDPadLeft];
				[_buttons addObject:
				    OFGameControllerButtonDPadRight];
				[_buttons addObject:
				    OFGameControllerButtonDPadUp];
				[_buttons addObject:
				    OFGameControllerButtonDPadDown];
			}

			if (OFBitSetIsSet(absBits, ABS_Z))
				[_buttons addObject: @"ZL"];
				[_buttons addObject: OFGameControllerButtonZL];
			if (OFBitSetIsSet(absBits, ABS_RZ))
				[_buttons addObject: @"ZR"];
				[_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
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:
					    @"D-Pad Left"];
					    OFGameControllerButtonDPadLeft];
					[_pressedButtons removeObject:
					    @"D-Pad Right"];
					    OFGameControllerButtonDPadRight];
				} else if (event.value > 0) {
					[_pressedButtons addObject:
					    @"D-Pad Right"];
					    OFGameControllerButtonDPadRight];
					[_pressedButtons removeObject:
					    @"D-Pad Left"];
					    OFGameControllerButtonDPadLeft];
				} else {
					[_pressedButtons removeObject:
					    @"D-Pad Left"];
					    OFGameControllerButtonDPadLeft];
					[_pressedButtons removeObject:
					    @"D-Pad Right"];
					    OFGameControllerButtonDPadRight];
				}
				break;
			case ABS_HAT0Y:
				if (event.value < 0) {
					[_pressedButtons addObject:
					    @"D-Pad Up"];
					    OFGameControllerButtonDPadUp];
					[_pressedButtons removeObject:
					    @"D-Pad Down"];
					    OFGameControllerButtonDPadDown];
				} else if (event.value > 0) {
					[_pressedButtons addObject:
					    @"D-Pad Down"];
					    OFGameControllerButtonDPadDown];
					[_pressedButtons removeObject:
					    @"D-Pad Up"];
					    OFGameControllerButtonDPadUp];
				} else {
					[_pressedButtons removeObject:
					    @"D-Pad Up"];
					    OFGameControllerButtonDPadUp];
					[_pressedButtons removeObject:
					    @"D-Pad Down"];
					    OFGameControllerButtonDPadDown];
				}
				break;
			case ABS_Z:
				if (event.value > 0)
					[_pressedButtons addObject: @"ZL"];
					[_pressedButtons addObject:
					    OFGameControllerButtonZL];
				else
					[_pressedButtons removeObject: @"ZL"];
					[_pressedButtons removeObject:
					    OFGameControllerButtonZL];
				break;
			case ABS_RZ:
				if (event.value > 0)
					[_pressedButtons addObject: @"ZR"];
					[_pressedButtons addObject:
					    OFGameControllerButtonZR];
				else
					[_pressedButtons removeObject: @"ZR"];
					[_pressedButtons removeObject:
					    OFGameControllerButtonZR];
				break;
			}

			break;
		}
	}
}