mirror of https://github.com/mgba-emu/mgba.git
Qt: Further input cleanup
This commit is contained in:
parent
0c77227e06
commit
430ffc18e2
|
@ -208,7 +208,18 @@ QString InputController::profileForType(uint32_t type) {
|
|||
return driver->currentProfile();
|
||||
}
|
||||
|
||||
void InputController::setGamepadDriver(uint32_t type) {
|
||||
auto driver = m_inputDrivers.value(type);
|
||||
if (!driver || !driver->supportsGamepads()) {
|
||||
return;
|
||||
}
|
||||
m_gamepadDriver = type;
|
||||
}
|
||||
|
||||
QStringList InputController::connectedGamepads(uint32_t type) const {
|
||||
if (!type) {
|
||||
type = m_gamepadDriver;
|
||||
}
|
||||
auto driver = m_inputDrivers.value(type);
|
||||
if (!driver) {
|
||||
return {};
|
||||
|
@ -222,6 +233,9 @@ QStringList InputController::connectedGamepads(uint32_t type) const {
|
|||
}
|
||||
|
||||
int InputController::gamepadIndex(uint32_t type) const {
|
||||
if (!type) {
|
||||
type = m_gamepadDriver;
|
||||
}
|
||||
auto driver = m_inputDrivers.value(type);
|
||||
if (!driver) {
|
||||
return -1;
|
||||
|
@ -230,6 +244,9 @@ int InputController::gamepadIndex(uint32_t type) const {
|
|||
}
|
||||
|
||||
void InputController::setGamepad(uint32_t type, int index) {
|
||||
if (!type) {
|
||||
type = m_gamepadDriver;
|
||||
}
|
||||
auto driver = m_inputDrivers.value(type);
|
||||
if (!driver) {
|
||||
return;
|
||||
|
@ -237,10 +254,17 @@ void InputController::setGamepad(uint32_t type, int index) {
|
|||
driver->setActiveGamepad(index);
|
||||
}
|
||||
|
||||
void InputController::setGamepad(int index) {
|
||||
setGamepad(0, index);
|
||||
}
|
||||
|
||||
void InputController::setPreferredGamepad(uint32_t type, int index) {
|
||||
if (!m_config) {
|
||||
return;
|
||||
}
|
||||
if (!type) {
|
||||
type = m_gamepadDriver;
|
||||
}
|
||||
auto driver = m_inputDrivers.value(type);
|
||||
if (!driver) {
|
||||
return;
|
||||
|
@ -258,14 +282,31 @@ void InputController::setPreferredGamepad(uint32_t type, int index) {
|
|||
mInputSetPreferredDevice(m_config->input(), "gba", type, m_playerId, name.toUtf8().constData());
|
||||
}
|
||||
|
||||
void InputController::setPreferredGamepad(int index) {
|
||||
setPreferredGamepad(0, index);
|
||||
}
|
||||
|
||||
InputMapper InputController::mapper(uint32_t type) {
|
||||
return InputMapper(&m_inputMap, type);
|
||||
}
|
||||
|
||||
InputMapper InputController::mapper(InputDriver* driver) {
|
||||
return InputMapper(&m_inputMap, driver->type());
|
||||
}
|
||||
|
||||
InputMapper InputController::mapper(InputSource* source) {
|
||||
return InputMapper(&m_inputMap, source->type());
|
||||
}
|
||||
|
||||
void InputController::setSensorDriver(uint32_t type) {
|
||||
auto driver = m_inputDrivers.value(type);
|
||||
if (!driver || !driver->supportsSensors()) {
|
||||
return;
|
||||
}
|
||||
m_sensorDriver = type;
|
||||
}
|
||||
|
||||
|
||||
mRumble* InputController::rumble() {
|
||||
auto driver = m_inputDrivers.value(m_sensorDriver);
|
||||
if (driver) {
|
||||
|
|
|
@ -73,14 +73,22 @@ public:
|
|||
|
||||
static const int32_t AXIS_THRESHOLD = 0x3000;
|
||||
|
||||
QStringList connectedGamepads(uint32_t type) const;
|
||||
int gamepadIndex(uint32_t type) const;
|
||||
void setGamepadDriver(uint32_t type);
|
||||
const InputDriver* gamepadDriver() const { return m_inputDrivers.value(m_sensorDriver).get(); }
|
||||
InputDriver* gamepadDriver() { return m_inputDrivers.value(m_sensorDriver).get(); }
|
||||
|
||||
QStringList connectedGamepads(uint32_t type = 0) const;
|
||||
int gamepadIndex(uint32_t type = 0) const;
|
||||
void setGamepad(uint32_t type, int index);
|
||||
void setGamepad(int index);
|
||||
void setPreferredGamepad(uint32_t type, int index);
|
||||
void setPreferredGamepad(int index);
|
||||
|
||||
InputMapper mapper(uint32_t type);
|
||||
InputMapper mapper(InputDriver*);
|
||||
InputMapper mapper(InputSource*);
|
||||
|
||||
void setSensorDriver(uint32_t type);
|
||||
const InputDriver* sensorDriver() const { return m_inputDrivers.value(m_sensorDriver).get(); }
|
||||
InputDriver* sensorDriver() { return m_inputDrivers.value(m_sensorDriver).get(); }
|
||||
|
||||
|
@ -162,6 +170,7 @@ private:
|
|||
QWidget* m_focusParent;
|
||||
|
||||
QHash<uint32_t, std::shared_ptr<InputDriver>> m_inputDrivers;
|
||||
uint32_t m_gamepadDriver;
|
||||
uint32_t m_sensorDriver;
|
||||
|
||||
QSet<int> m_activeButtons;
|
||||
|
|
|
@ -10,10 +10,6 @@
|
|||
|
||||
#include <QRegExp>
|
||||
|
||||
#ifdef BUILD_SDL
|
||||
#include "platform/sdl/sdl-events.h"
|
||||
#endif
|
||||
|
||||
using namespace QGBA;
|
||||
|
||||
const InputProfile InputProfile::s_defaultMaps[] = {
|
||||
|
@ -215,13 +211,14 @@ const InputProfile* InputProfile::findProfile(const QString& name) {
|
|||
}
|
||||
|
||||
void InputProfile::apply(InputController* controller) const {
|
||||
#ifdef BUILD_SDL
|
||||
InputMapper mapper = controller->mapper(SDL_BINDING_BUTTON);
|
||||
for (size_t i = 0; i < GBA_KEY_MAX; ++i) {
|
||||
mapper.bindKey(m_keys[i], static_cast<GBAKey>(i));
|
||||
mapper.bindAxis(m_axes[i].axis, m_axes[i].direction, static_cast<GBAKey>(i));
|
||||
auto gamepadDriver = controller->gamepadDriver();
|
||||
if (gamepadDriver) {
|
||||
InputMapper mapper = controller->mapper(gamepadDriver);
|
||||
for (size_t i = 0; i < GBA_KEY_MAX; ++i) {
|
||||
mapper.bindKey(m_keys[i], i);
|
||||
mapper.bindAxis(m_axes[i].axis, m_axes[i].direction, i);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
InputDriver* sensorDriver = controller->sensorDriver();
|
||||
if (sensorDriver) {
|
||||
|
|
|
@ -18,10 +18,6 @@
|
|||
#include <mgba-util/png-io.h>
|
||||
#include <mgba-util/vfs.h>
|
||||
|
||||
#ifdef BUILD_SDL
|
||||
#include "platform/sdl/sdl-events.h"
|
||||
#endif
|
||||
|
||||
#include "CoreController.h"
|
||||
#include "GBAApp.h"
|
||||
#include "Window.h"
|
||||
|
@ -318,10 +314,8 @@ void ReportView::generateReport() {
|
|||
} else {
|
||||
windowReport << QString("ROM open: No");
|
||||
}
|
||||
#ifdef BUILD_SDL
|
||||
InputController* input = window->inputController();
|
||||
windowReport << QString("Active gamepad: %1").arg(input->gamepadIndex(SDL_BINDING_BUTTON));
|
||||
#endif
|
||||
windowReport << QString("Active gamepad: %1").arg(input->gamepadIndex());
|
||||
windowReport << QString("Configuration: %1").arg(configs.indexOf(config) + 1);
|
||||
addReport(QString("Window %1").arg(winId), windowReport.join('\n'));
|
||||
}
|
||||
|
@ -481,9 +475,8 @@ void ReportView::addGLInfo(QStringList& report) {
|
|||
}
|
||||
|
||||
void ReportView::addGamepadInfo(QStringList& report) {
|
||||
#ifdef BUILD_SDL
|
||||
InputController* input = GBAApp::app()->windows()[0]->inputController();
|
||||
QStringList gamepads = input->connectedGamepads(SDL_BINDING_BUTTON);
|
||||
QStringList gamepads = input->connectedGamepads();
|
||||
report << QString("Connected gamepads: %1").arg(gamepads.size());
|
||||
int i = 0;
|
||||
for (const auto& gamepad : gamepads) {
|
||||
|
@ -494,10 +487,9 @@ void ReportView::addGamepadInfo(QStringList& report) {
|
|||
i = 0;
|
||||
for (Window* window : GBAApp::app()->windows()) {
|
||||
++i;
|
||||
report << QString("Window %1 gamepad: %2").arg(i).arg(window->inputController()->gamepadIndex(SDL_BINDING_BUTTON));
|
||||
report << QString("Window %1 gamepad: %2").arg(i).arg(window->inputController()->gamepadIndex());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ReportView::addROMInfo(QStringList& report, CoreController* controller) {
|
||||
|
|
Loading…
Reference in New Issue