mirror of https://github.com/mgba-emu/mgba.git
Qt: Rudimentary gamepad mapper
This commit is contained in:
parent
091e717133
commit
e6ea94d229
|
@ -3,6 +3,7 @@
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QTimer>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include "InputController.h"
|
#include "InputController.h"
|
||||||
|
@ -39,6 +40,22 @@ GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, QWidget* paren
|
||||||
m_keyB = new KeyEditor(this);
|
m_keyB = new KeyEditor(this);
|
||||||
m_keyL = new KeyEditor(this);
|
m_keyL = new KeyEditor(this);
|
||||||
m_keyR = new KeyEditor(this);
|
m_keyR = new KeyEditor(this);
|
||||||
|
|
||||||
|
#ifdef BUILD_SDL
|
||||||
|
if (type == SDL_BINDING_BUTTON) {
|
||||||
|
m_keyDU->setNumeric(true);
|
||||||
|
m_keyDD->setNumeric(true);
|
||||||
|
m_keyDL->setNumeric(true);
|
||||||
|
m_keyDR->setNumeric(true);
|
||||||
|
m_keySelect->setNumeric(true);
|
||||||
|
m_keyStart->setNumeric(true);
|
||||||
|
m_keyA->setNumeric(true);
|
||||||
|
m_keyB->setNumeric(true);
|
||||||
|
m_keyL->setNumeric(true);
|
||||||
|
m_keyR->setNumeric(true);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
m_keyDU->setValue(GBAInputQueryBinding(map, type, GBA_KEY_UP));
|
m_keyDU->setValue(GBAInputQueryBinding(map, type, GBA_KEY_UP));
|
||||||
m_keyDD->setValue(GBAInputQueryBinding(map, type, GBA_KEY_DOWN));
|
m_keyDD->setValue(GBAInputQueryBinding(map, type, GBA_KEY_DOWN));
|
||||||
m_keyDL->setValue(GBAInputQueryBinding(map, type, GBA_KEY_LEFT));
|
m_keyDL->setValue(GBAInputQueryBinding(map, type, GBA_KEY_LEFT));
|
||||||
|
@ -92,6 +109,15 @@ GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, QWidget* paren
|
||||||
m_background.load(":/res/keymap.qpic");
|
m_background.load(":/res/keymap.qpic");
|
||||||
|
|
||||||
setAll->setFocus();
|
setAll->setFocus();
|
||||||
|
|
||||||
|
#ifdef BUILD_SDL
|
||||||
|
if (type == SDL_BINDING_BUTTON) {
|
||||||
|
m_gamepadTimer = new QTimer(this);
|
||||||
|
connect(m_gamepadTimer, SIGNAL(timeout()), this, SLOT(testGamepad()));
|
||||||
|
m_gamepadTimer->setInterval(100);
|
||||||
|
m_gamepadTimer->start();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAKeyEditor::setAll() {
|
void GBAKeyEditor::setAll() {
|
||||||
|
@ -150,6 +176,21 @@ void GBAKeyEditor::save() {
|
||||||
m_controller->saveConfiguration(m_type);
|
m_controller->saveConfiguration(m_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef BUILD_SDL
|
||||||
|
void GBAKeyEditor::testGamepad() {
|
||||||
|
QSet<int> activeKeys = m_controller->activeGamepadButtons();
|
||||||
|
if (activeKeys.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (KeyEditor* key : m_keyOrder) {
|
||||||
|
if (!key->hasFocus()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
key->setValue(*activeKeys.begin());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void GBAKeyEditor::setLocation(QWidget* widget, qreal x, qreal y) {
|
void GBAKeyEditor::setLocation(QWidget* widget, qreal x, qreal y) {
|
||||||
QSize s = size();
|
QSize s = size();
|
||||||
QSize hint = widget->sizeHint();
|
QSize hint = widget->sizeHint();
|
||||||
|
|
|
@ -26,6 +26,9 @@ protected:
|
||||||
private slots:
|
private slots:
|
||||||
void setNext();
|
void setNext();
|
||||||
void save();
|
void save();
|
||||||
|
#ifdef BUILD_SDL
|
||||||
|
void testGamepad();
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const qreal DPAD_CENTER_X;
|
static const qreal DPAD_CENTER_X;
|
||||||
|
@ -35,6 +38,11 @@ private:
|
||||||
|
|
||||||
void setLocation(QWidget* widget, qreal x, qreal y);
|
void setLocation(QWidget* widget, qreal x, qreal y);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef BUILD_SDL
|
||||||
|
QTimer* m_gamepadTimer;
|
||||||
|
#endif
|
||||||
|
|
||||||
QWidget* m_buttons;
|
QWidget* m_buttons;
|
||||||
KeyEditor* m_keyDU;
|
KeyEditor* m_keyDU;
|
||||||
KeyEditor* m_keyDD;
|
KeyEditor* m_keyDD;
|
||||||
|
|
|
@ -97,4 +97,18 @@ int InputController::testSDLEvents() {
|
||||||
}
|
}
|
||||||
return activeButtons;
|
return activeButtons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSet<int> InputController::activeGamepadButtons() {
|
||||||
|
SDL_Joystick* joystick = m_sdlEvents.joystick;
|
||||||
|
SDL_JoystickUpdate();
|
||||||
|
int numButtons = SDL_JoystickNumButtons(joystick);
|
||||||
|
QSet<int> activeButtons;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < numButtons; ++i) {
|
||||||
|
if (SDL_JoystickGetButton(joystick, i)) {
|
||||||
|
activeButtons.insert(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return activeButtons;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,6 +9,8 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <QSet>
|
||||||
|
|
||||||
namespace QGBA {
|
namespace QGBA {
|
||||||
|
|
||||||
class ConfigController;
|
class ConfigController;
|
||||||
|
@ -32,6 +34,7 @@ public:
|
||||||
|
|
||||||
#ifdef BUILD_SDL
|
#ifdef BUILD_SDL
|
||||||
int testSDLEvents();
|
int testSDLEvents();
|
||||||
|
QSet<int> activeGamepadButtons();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -6,12 +6,17 @@ using namespace QGBA;
|
||||||
|
|
||||||
KeyEditor::KeyEditor(QWidget* parent)
|
KeyEditor::KeyEditor(QWidget* parent)
|
||||||
: QLineEdit(parent)
|
: QLineEdit(parent)
|
||||||
|
, m_numeric(false)
|
||||||
{
|
{
|
||||||
setAlignment(Qt::AlignCenter);
|
setAlignment(Qt::AlignCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyEditor::setValue(int key) {
|
void KeyEditor::setValue(int key) {
|
||||||
setText(QKeySequence(key).toString(QKeySequence::NativeText));
|
if (m_numeric) {
|
||||||
|
setText(QString::number(key));
|
||||||
|
} else {
|
||||||
|
setText(QKeySequence(key).toString(QKeySequence::NativeText));
|
||||||
|
}
|
||||||
m_key = key;
|
m_key = key;
|
||||||
emit valueChanged(key);
|
emit valueChanged(key);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +28,8 @@ QSize KeyEditor::sizeHint() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyEditor::keyPressEvent(QKeyEvent* event) {
|
void KeyEditor::keyPressEvent(QKeyEvent* event) {
|
||||||
setValue(event->key());
|
if (!m_numeric) {
|
||||||
|
setValue(event->key());
|
||||||
|
}
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ public:
|
||||||
void setValue(int key);
|
void setValue(int key);
|
||||||
int value() const { return m_key; }
|
int value() const { return m_key; }
|
||||||
|
|
||||||
|
void setNumeric(bool numeric) { m_numeric = numeric; }
|
||||||
|
|
||||||
virtual QSize sizeHint() const override;
|
virtual QSize sizeHint() const override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -24,6 +26,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_key;
|
int m_key;
|
||||||
|
bool m_numeric;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,6 +173,15 @@ void Window::openKeymapWindow() {
|
||||||
keyEditor->show();
|
keyEditor->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef BUILD_SDL
|
||||||
|
void Window::openGamepadWindow() {
|
||||||
|
GBAKeyEditor* keyEditor = new GBAKeyEditor(&m_inputController, SDL_BINDING_BUTTON);
|
||||||
|
connect(this, SIGNAL(shutdown()), keyEditor, SLOT(close()));
|
||||||
|
keyEditor->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
keyEditor->show();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_FFMPEG
|
#ifdef USE_FFMPEG
|
||||||
void Window::openVideoWindow() {
|
void Window::openVideoWindow() {
|
||||||
if (!m_videoView) {
|
if (!m_videoView) {
|
||||||
|
@ -454,6 +463,12 @@ void Window::setupMenu(QMenuBar* menubar) {
|
||||||
connect(keymap, SIGNAL(triggered()), this, SLOT(openKeymapWindow()));
|
connect(keymap, SIGNAL(triggered()), this, SLOT(openKeymapWindow()));
|
||||||
emulationMenu->addAction(keymap);
|
emulationMenu->addAction(keymap);
|
||||||
|
|
||||||
|
#ifdef BUILD_SDL
|
||||||
|
QAction* gamepad = new QAction(tr("Remap gamepad..."), emulationMenu);
|
||||||
|
connect(gamepad, SIGNAL(triggered()), this, SLOT(openGamepadWindow()));
|
||||||
|
emulationMenu->addAction(gamepad);
|
||||||
|
#endif
|
||||||
|
|
||||||
QMenu* avMenu = menubar->addMenu(tr("Audio/&Video"));
|
QMenu* avMenu = menubar->addMenu(tr("Audio/&Video"));
|
||||||
QMenu* frameMenu = avMenu->addMenu(tr("Frame size"));
|
QMenu* frameMenu = avMenu->addMenu(tr("Frame size"));
|
||||||
QAction* setSize = new QAction(tr("1x"), avMenu);
|
QAction* setSize = new QAction(tr("1x"), avMenu);
|
||||||
|
|
|
@ -56,6 +56,10 @@ public slots:
|
||||||
|
|
||||||
void openKeymapWindow();
|
void openKeymapWindow();
|
||||||
|
|
||||||
|
#ifdef BUILD_SDL
|
||||||
|
void openGamepadWindow();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_FFMPEG
|
#ifdef USE_FFMPEG
|
||||||
void openVideoWindow();
|
void openVideoWindow();
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue