all repos — mgba @ afae3c8b807577123c93f32f1145422fc55500af

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
14class QTimer;
15
16extern "C" {
17#include "gba/input.h"
18
19#ifdef BUILD_SDL
20#include "platform/sdl/sdl-events.h"
21#endif
22}
23
24namespace QGBA {
25
26class ConfigController;
27
28class InputController : public QObject {
29Q_OBJECT
30
31public:
32	static const uint32_t KEYBOARD = 0x51545F4B;
33
34	InputController(int playerId = 0, QObject* parent = nullptr);
35	~InputController();
36
37	void setConfiguration(ConfigController* config);
38	void loadConfiguration(uint32_t type);
39	void loadProfile(uint32_t type, const QString& profile);
40	void saveConfiguration(uint32_t type = KEYBOARD);
41	void saveProfile(uint32_t type, const QString& profile);
42	const char* profileForType(uint32_t type);
43
44	GBAKey mapKeyboard(int key) const;
45
46	void bindKey(uint32_t type, int key, GBAKey);
47
48	const GBAInputMap* map() const { return &m_inputMap; }
49
50#ifdef BUILD_SDL
51	static const int32_t AXIS_THRESHOLD = 0x3000;
52
53	int testSDLEvents();
54	QSet<int> activeGamepadButtons();
55	QSet<QPair<int, GamepadAxisEvent::Direction>> activeGamepadAxes();
56
57	void bindAxis(uint32_t type, int axis, GamepadAxisEvent::Direction, GBAKey);
58
59	QStringList connectedGamepads(uint32_t type) const;
60	int gamepad(uint32_t type) const { return m_sdlPlayer.joystickIndex; }
61	void setGamepad(uint32_t type, int index) { GBASDLPlayerChangeJoystick(&s_sdlEvents, &m_sdlPlayer, index); }
62	void setPreferredGamepad(uint32_t type, const QString& device);
63#endif
64
65public slots:
66	void testGamepad();
67
68private:
69	void postPendingEvent(GBAKey);
70	void clearPendingEvent(GBAKey);
71	bool hasPendingEvent(GBAKey) const;
72
73	GBAInputMap m_inputMap;
74	ConfigController* m_config;
75	int m_playerId;
76
77#ifdef BUILD_SDL
78	static int s_sdlInited;
79	static GBASDLEvents s_sdlEvents;
80	GBASDLPlayer m_sdlPlayer;
81	bool m_playerAttached;
82#endif
83
84	QSet<int> m_activeButtons;
85	QSet<QPair<int, GamepadAxisEvent::Direction>> m_activeAxes;
86	QTimer* m_gamepadTimer;
87
88	QSet<GBAKey> m_pendingEvents;
89};
90
91}
92
93#endif