all repos — mgba @ 3eb4c01515cc42f6f4cb35f0c8432b644fccf806

mGBA Game Boy Advance Emulator

src/platform/qt/InputController.h (view raw)

  1/* Copyright (c) 2013-2015 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#ifndef QGBA_INPUT_CONTROLLER_H
  7#define QGBA_INPUT_CONTROLLER_H
  8
  9#include "GamepadAxisEvent.h"
 10
 11#include <QObject>
 12#include <QSet>
 13#include <QVector>
 14
 15class QTimer;
 16
 17extern "C" {
 18#include "gba/input.h"
 19
 20#ifdef BUILD_SDL
 21#include "platform/sdl/sdl-events.h"
 22#endif
 23}
 24
 25namespace QGBA {
 26
 27class ConfigController;
 28
 29class InputController : public QObject {
 30Q_OBJECT
 31
 32public:
 33	static const uint32_t KEYBOARD = 0x51545F4B;
 34
 35	InputController(int playerId = 0, QObject* parent = nullptr);
 36	~InputController();
 37
 38	void setConfiguration(ConfigController* config);
 39	void loadConfiguration(uint32_t type);
 40	void loadProfile(uint32_t type, const QString& profile);
 41	void saveConfiguration(uint32_t type = KEYBOARD);
 42	void saveProfile(uint32_t type, const QString& profile);
 43	const char* profileForType(uint32_t type);
 44
 45	bool allowOpposing() const { return m_allowOpposing; }
 46	void setAllowOpposing(bool allowOpposing) { m_allowOpposing = allowOpposing; }
 47
 48	GBAKey mapKeyboard(int key) const;
 49
 50	void bindKey(uint32_t type, int key, GBAKey);
 51
 52	const GBAInputMap* map() const { return &m_inputMap; }
 53
 54#ifdef BUILD_SDL
 55	static const int32_t AXIS_THRESHOLD = 0x3000;
 56
 57	int testSDLEvents();
 58	QSet<int> activeGamepadButtons();
 59	QSet<QPair<int, GamepadAxisEvent::Direction>> activeGamepadAxes();
 60	void recalibrateAxes();
 61
 62	void bindAxis(uint32_t type, int axis, GamepadAxisEvent::Direction, GBAKey);
 63
 64	QStringList connectedGamepads(uint32_t type) const;
 65	int gamepad(uint32_t type) const { return m_sdlPlayer.joystickIndex; }
 66	void setGamepad(uint32_t type, int index) { GBASDLPlayerChangeJoystick(&s_sdlEvents, &m_sdlPlayer, index); }
 67	void setPreferredGamepad(uint32_t type, const QString& device);
 68#endif
 69
 70	GBARumble* rumble();
 71	GBARotationSource* rotationSource();
 72
 73public slots:
 74	void testGamepad();
 75
 76private:
 77	void postPendingEvent(GBAKey);
 78	void clearPendingEvent(GBAKey);
 79	bool hasPendingEvent(GBAKey) const;
 80
 81	GBAInputMap m_inputMap;
 82	ConfigController* m_config;
 83	int m_playerId;
 84	bool m_allowOpposing;
 85
 86#ifdef BUILD_SDL
 87	static int s_sdlInited;
 88	static GBASDLEvents s_sdlEvents;
 89	GBASDLPlayer m_sdlPlayer;
 90	bool m_playerAttached;
 91	QVector<int> m_deadzones;
 92#endif
 93
 94	QSet<int> m_activeButtons;
 95	QSet<QPair<int, GamepadAxisEvent::Direction>> m_activeAxes;
 96	QTimer* m_gamepadTimer;
 97
 98	QSet<GBAKey> m_pendingEvents;
 99};
100
101}
102
103#endif