Skip to content

Commit 339ff76

Browse files
committed
Change button functions to use int not enum
This allows the user to pass a button number or iterate through them without having to explicitly cast to the enum type (XInputControl). The function will still take an enum value without complaint, this just makes it more flexible.
1 parent 296da4c commit 339ff76

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/XInput.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,16 @@ XInputGamepad::XInputGamepad() :
203203
#endif
204204
}
205205

206-
void XInputGamepad::press(XInputControl button) {
206+
void XInputGamepad::press(uint8_t button) {
207207
setButton(button, true);
208208
}
209209

210-
void XInputGamepad::release(XInputControl button) {
210+
void XInputGamepad::release(uint8_t button) {
211211
setButton(button, false);
212212
}
213213

214-
void XInputGamepad::setButton(XInputControl button, boolean state) {
215-
const XInputMap_Button * buttonData = getButtonFromEnum(button);
214+
void XInputGamepad::setButton(uint8_t button, boolean state) {
215+
const XInputMap_Button * buttonData = getButtonFromEnum((XInputControl) button);
216216
if (buttonData != nullptr) {
217217
if (getButton(button) == state) return; // Button hasn't changed
218218

@@ -222,9 +222,9 @@ void XInputGamepad::setButton(XInputControl button, boolean state) {
222222
autosend();
223223
}
224224
else {
225-
Range * triggerRange = getRangeFromEnum(button);
225+
Range * triggerRange = getRangeFromEnum((XInputControl) button);
226226
if (triggerRange == nullptr) return; // Not a trigger (or joystick, but the trigger function will ignore that)
227-
setTrigger(button, state ? triggerRange->max : triggerRange->min); // Treat trigger like a button
227+
setTrigger((XInputControl) button, state ? triggerRange->max : triggerRange->min); // Treat trigger like a button
228228
}
229229
}
230230

@@ -291,8 +291,8 @@ void XInputGamepad::setAutoSend(boolean a) {
291291
autoSendOption = a;
292292
}
293293

294-
boolean XInputGamepad::getButton(XInputControl button) const {
295-
const XInputMap_Button * buttonData = getButtonFromEnum(button);
294+
boolean XInputGamepad::getButton(uint8_t button) const {
295+
const XInputMap_Button * buttonData = getButtonFromEnum((XInputControl) button);
296296
if (buttonData == nullptr) return 0; // Not a button
297297
return tx[buttonData->index] & buttonData->mask;
298298
}

src/XInput.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class XInputGamepad {
7979
XInputGamepad();
8080

8181
// Set Control Surfaces
82-
void press(XInputControl button);
83-
void release(XInputControl button);
84-
void setButton(XInputControl button, boolean state);
82+
void press(uint8_t button);
83+
void release(uint8_t button);
84+
void setButton(uint8_t button, boolean state);
8585

8686
void setDpad(XInputControl pad, boolean state);
8787
void setDpad(boolean up, boolean down, boolean left, boolean right);
@@ -96,7 +96,7 @@ class XInputGamepad {
9696
void setAutoSend(boolean a);
9797

9898
// Read Control Surfaces
99-
boolean getButton(XInputControl button) const;
99+
boolean getButton(uint8_t button) const;
100100
boolean getDpad(XInputControl dpad) const;
101101
uint8_t getTrigger(XInputControl trigger) const;
102102
int16_t getJoystickX(XInputControl joy) const;

0 commit comments

Comments
 (0)