all repos — mgba @ cddae84a437fd5753f8bf3c7c549641ba162f657

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, QWidget* topLevel = nullptr, QObject* parent = nullptr);
 36	~InputController();
 37
 38	void setConfiguration(ConfigController* config);
 39	void saveConfiguration();
 40	void loadConfiguration(uint32_t type);
 41	void loadProfile(uint32_t type, const QString& profile);
 42	void saveConfiguration(uint32_t type);
 43	void saveProfile(uint32_t type, const QString& profile);
 44	const char* profileForType(uint32_t type);
 45
 46	bool allowOpposing() const { return m_allowOpposing; }
 47	void setAllowOpposing(bool allowOpposing) { m_allowOpposing = allowOpposing; }
 48
 49	GBAKey mapKeyboard(int key) const;
 50
 51	void bindKey(uint32_t type, int key, GBAKey);
 52
 53	const GBAInputMap* map() const { return &m_inputMap; }
 54
 55	int pollEvents();
 56
 57	static const int32_t AXIS_THRESHOLD = 0x3000;
 58	QSet<int> activeGamepadButtons(int type);
 59	QSet<QPair<int, GamepadAxisEvent::Direction>> activeGamepadAxes(int type);
 60	void recalibrateAxes();
 61
 62	void bindAxis(uint32_t type, int axis, GamepadAxisEvent::Direction, GBAKey);
 63	void unbindAllAxes(uint32_t type);
 64
 65	QStringList connectedGamepads(uint32_t type) const;
 66	int gamepad(uint32_t type) const;
 67	void setGamepad(uint32_t type, int index);
 68	void setPreferredGamepad(uint32_t type, const QString& device);
 69
 70	void registerTiltAxisX(int axis);
 71	void registerTiltAxisY(int axis);
 72	void registerGyroAxisX(int axis);
 73	void registerGyroAxisY(int axis);
 74
 75	float gyroSensitivity() const;
 76	void setGyroSensitivity(float sensitivity);
 77
 78	void stealFocus(QWidget* focus);
 79	void releaseFocus(QWidget* focus);
 80
 81	GBARumble* rumble();
 82	GBARotationSource* rotationSource();
 83
 84signals:
 85	void profileLoaded(const QString& profile);
 86
 87public slots:
 88	void testGamepad(int type);
 89
 90#if defined(BUILD_SDL) && SDL_VERSION_ATLEAST(2, 0, 0)
 91	// TODO: Move these to somewhere that makes sense
 92	void suspendScreensaver();
 93	void resumeScreensaver();
 94	void setScreensaverSuspendable(bool);
 95#endif
 96
 97private:
 98	void postPendingEvent(GBAKey);
 99	void clearPendingEvent(GBAKey);
100	bool hasPendingEvent(GBAKey) const;
101	void sendGamepadEvent(QEvent*);
102
103	GBAInputMap m_inputMap;
104	ConfigController* m_config;
105	int m_playerId;
106	bool m_allowOpposing;
107	QWidget* m_topLevel;
108	QWidget* m_focusParent;
109
110#ifdef BUILD_SDL
111	static int s_sdlInited;
112	static GBASDLEvents s_sdlEvents;
113	GBASDLPlayer m_sdlPlayer;
114	bool m_playerAttached;
115#endif
116
117	QVector<int> m_deadzones;
118
119	QSet<int> m_activeButtons;
120	QSet<QPair<int, GamepadAxisEvent::Direction>> m_activeAxes;
121	QTimer* m_gamepadTimer;
122
123	QSet<GBAKey> m_pendingEvents;
124};
125
126}
127
128#endif