all repos — mgba @ 33c4b179415269bb31f45b1875ff307b2b434448

mGBA Game Boy Advance Emulator

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

 1/* Copyright (c) 2013-2014 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 <QObject>
10#include <QSet>
11
12class QTimer;
13
14extern "C" {
15#include "gba-input.h"
16
17#ifdef BUILD_SDL
18#include "platform/sdl/sdl-events.h"
19#endif
20}
21
22namespace QGBA {
23
24class ConfigController;
25
26class InputController : public QObject {
27Q_OBJECT
28
29public:
30	static const uint32_t KEYBOARD = 0x51545F4B;
31
32	InputController(QObject* parent = nullptr);
33	~InputController();
34
35	void setConfiguration(ConfigController* config);
36	void loadConfiguration(uint32_t type);
37	void saveConfiguration(uint32_t type = KEYBOARD);
38
39	GBAKey mapKeyboard(int key) const;
40
41	void bindKey(uint32_t type, int key, GBAKey);
42
43	const GBAInputMap* map() const { return &m_inputMap; }
44
45#ifdef BUILD_SDL
46	static const int32_t AXIS_THRESHOLD = 0x3000;
47	enum Direction {
48		NEUTRAL = 0,
49		POSITIVE = 1,
50		NEGATIVE = -1
51	};
52
53	int testSDLEvents();
54	QSet<int> activeGamepadButtons();
55	QSet<QPair<int, int32_t>> activeGamepadAxes();
56
57	void bindAxis(uint32_t type, int axis, Direction, GBAKey);
58#endif
59
60signals:
61	void axisChanged(int axis, int32_t value);
62
63public slots:
64	void testGamepad();
65
66private:
67	void postPendingEvent(GBAKey);
68	void clearPendingEvent(GBAKey);
69	bool hasPendingEvent(GBAKey) const;
70
71	GBAInputMap m_inputMap;
72	ConfigController* m_config;
73
74#ifdef BUILD_SDL
75	GBASDLEvents m_sdlEvents;
76#endif
77
78	QSet<int> m_activeButtons;
79	QSet<QPair<int, int32_t>> m_activeAxes;
80	QTimer* m_gamepadTimer;
81
82	QSet<GBAKey> m_pendingEvents;
83};
84
85}
86
87#endif