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 loadProfile(uint32_t type, const char* profile);
40 void saveConfiguration(uint32_t type = KEYBOARD);
41 void saveProfile(uint32_t type, const char* 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#endif
59
60public slots:
61 void testGamepad();
62
63private:
64 void postPendingEvent(GBAKey);
65 void clearPendingEvent(GBAKey);
66 bool hasPendingEvent(GBAKey) const;
67
68 GBAInputMap m_inputMap;
69 ConfigController* m_config;
70
71#ifdef BUILD_SDL
72 GBASDLEvents m_sdlEvents;
73#endif
74
75 QSet<int> m_activeButtons;
76 QSet<QPair<int, GamepadAxisEvent::Direction>> m_activeAxes;
77 QTimer* m_gamepadTimer;
78
79 QSet<GBAKey> m_pendingEvents;
80};
81
82}
83
84#endif