Qt: More API cleanup

This commit is contained in:
Vicki Pfau 2023-01-22 20:01:45 -08:00
parent 2df70ee45e
commit 74e7a44da3
6 changed files with 41 additions and 25 deletions

View File

@ -240,7 +240,7 @@ int InputController::gamepadIndex(uint32_t type) const {
if (!driver) {
return -1;
}
return driver->activeGamepad();
return driver->activeGamepadIndex();
}
void InputController::setGamepad(uint32_t type, int index) {
@ -362,12 +362,8 @@ Gamepad* InputController::gamepad(uint32_t type) {
if (!driver->supportsGamepads()) {
return nullptr;
}
QList<Gamepad*> driverPads(driver->connectedGamepads());
int activeGamepad = driver->activeGamepad();
if (activeGamepad < 0 || activeGamepad >= driverPads.count()) {
return nullptr;
}
return driverPads[activeGamepad];
return driver->activeGamepad();
}
QList<Gamepad*> InputController::gamepads() {
@ -376,16 +372,15 @@ QList<Gamepad*> InputController::gamepads() {
if (!driver->supportsGamepads()) {
continue;
}
QList<Gamepad*> driverPads(driver->connectedGamepads());
int activeGamepad = driver->activeGamepad();
if (activeGamepad >= 0 && activeGamepad < driverPads.count()) {
pads.append(driverPads[activeGamepad]);
Gamepad* pad = driver->activeGamepad();
if (pad) {
pads.append(pad);
}
}
return pads;
}
QSet<int> InputController::activeGamepadButtons(int type) {
QSet<int> InputController::activeGamepadButtons(uint32_t type) {
QSet<int> activeButtons;
Gamepad* pad = gamepad(type);
if (!pad) {
@ -400,7 +395,7 @@ QSet<int> InputController::activeGamepadButtons(int type) {
return activeButtons;
}
QSet<QPair<int, GamepadAxisEvent::Direction>> InputController::activeGamepadAxes(int type) {
QSet<QPair<int, GamepadAxisEvent::Direction>> InputController::activeGamepadAxes(uint32_t type) {
QSet<QPair<int, GamepadAxisEvent::Direction>> activeAxes;
Gamepad* pad = gamepad(type);
if (!pad) {
@ -421,7 +416,7 @@ QSet<QPair<int, GamepadAxisEvent::Direction>> InputController::activeGamepadAxes
return activeAxes;
}
QSet<QPair<int, GamepadHatEvent::Direction>> InputController::activeGamepadHats(int type) {
QSet<QPair<int, GamepadHatEvent::Direction>> InputController::activeGamepadHats(uint32_t type) {
QSet<QPair<int, GamepadHatEvent::Direction>> activeHats;
Gamepad* pad = gamepad(type);
if (!pad) {
@ -436,7 +431,7 @@ QSet<QPair<int, GamepadHatEvent::Direction>> InputController::activeGamepadHats(
return activeHats;
}
void InputController::testGamepad(int type) {
void InputController::testGamepad(uint32_t type) {
QWriteLocker l(&m_eventsLock);
auto activeAxes = activeGamepadAxes(type);
auto oldAxes = m_activeAxes;

View File

@ -107,7 +107,7 @@ signals:
void luminanceValueChanged(int value);
public slots:
void testGamepad(int type);
void testGamepad(uint32_t type);
void update();
void increaseLuminanceLevel();
@ -136,9 +136,9 @@ private:
Gamepad* gamepad(uint32_t type);
QList<Gamepad*> gamepads();
QSet<int> activeGamepadButtons(int type);
QSet<QPair<int, GamepadAxisEvent::Direction>> activeGamepadAxes(int type);
QSet<QPair<int, GamepadHatEvent::Direction>> activeGamepadHats(int type);
QSet<int> activeGamepadButtons(uint32_t type);
QSet<QPair<int, GamepadAxisEvent::Direction>> activeGamepadAxes(uint32_t type);
QSet<QPair<int, GamepadHatEvent::Direction>> activeGamepadHats(uint32_t type);
struct InputControllerLux : GBALuminanceSource {
InputController* p;

View File

@ -40,14 +40,32 @@ QList<Gamepad*> InputDriver::connectedGamepads() const {
return {};
}
int InputDriver::activeKeySource() const {
int InputDriver::activeKeySourceIndex() const {
return -1;
}
int InputDriver::activeGamepad() const {
int InputDriver::activeGamepadIndex() const {
return -1;
}
KeySource* InputDriver::activeKeySource() {
QList<KeySource*> ks(connectedKeySources());
int activeKeySource = activeKeySourceIndex();
if (activeKeySource < 0 || activeKeySource >= ks.count()) {
return nullptr;
}
return ks[activeKeySource];
}
Gamepad* InputDriver::activeGamepad() {
QList<Gamepad*> pads(connectedGamepads());
int activeGamepad = activeGamepadIndex();
if (activeGamepad < 0 || activeGamepad >= pads.count()) {
return nullptr;
}
return pads[activeGamepad];
}
void InputDriver::setActiveKeySource(int) {
}

View File

@ -44,8 +44,11 @@ public:
virtual QList<KeySource*> connectedKeySources() const;
virtual QList<Gamepad*> connectedGamepads() const;
virtual int activeKeySource() const;
virtual int activeGamepad() const;
virtual int activeKeySourceIndex() const;
virtual int activeGamepadIndex() const;
KeySource* activeKeySource();
Gamepad* activeGamepad();
virtual void setActiveKeySource(int);
virtual void setActiveGamepad(int);

View File

@ -173,7 +173,7 @@ void SDLInputDriver::updateGamepads() {
}
#endif
int SDLInputDriver::activeGamepad() const {
int SDLInputDriver::activeGamepadIndex() const {
return m_sdlPlayer.joystick ? m_sdlPlayer.joystick->index : 0;
}

View File

@ -46,7 +46,7 @@ public:
QList<Gamepad*> connectedGamepads() const override;
int activeGamepad() const override;
int activeGamepadIndex() const override;
void setActiveGamepad(int) override;
void registerTiltAxisX(int axis) override;