all repos — mgba @ 7149dd3102a6bbb7f73cae7da0c01dc784b0f601

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(QObject* parent = nullptr);
35	~InputController();
36
37	void setConfiguration(ConfigController* config);
38	void loadConfiguration(uint32_t type);
39	void saveConfiguration(uint32_t type = KEYBOARD);
40
41	GBAKey mapKeyboard(int key) const;
42
43	void bindKey(uint32_t type, int key, GBAKey);
44
45	const GBAInputMap* map() const { return &m_inputMap; }
46
47#ifdef BUILD_SDL
48	static const int32_t AXIS_THRESHOLD = 0x3000;
49
50	int testSDLEvents();
51	QSet<int> activeGamepadButtons();
52	QSet<QPair<int, GamepadAxisEvent::Direction>> activeGamepadAxes();
53
54	void bindAxis(uint32_t type, int axis, GamepadAxisEvent::Direction, GBAKey);
55#endif
56
57public slots:
58	void testGamepad();
59
60private:
61	void postPendingEvent(GBAKey);
62	void clearPendingEvent(GBAKey);
63	bool hasPendingEvent(GBAKey) const;
64
65	GBAInputMap m_inputMap;
66	ConfigController* m_config;
67
68#ifdef BUILD_SDL
69	GBASDLEvents m_sdlEvents;
70#endif
71
72	QSet<int> m_activeButtons;
73	QSet<QPair<int, GamepadAxisEvent::Direction>> m_activeAxes;
74	QTimer* m_gamepadTimer;
75
76	QSet<GBAKey> m_pendingEvents;
77};
78
79}
80
81#endif