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 void buttonPressed(int button);
63 void buttonReleased(int button);
64
65public slots:
66 void testGamepad();
67
68private:
69 GBAInputMap m_inputMap;
70 ConfigController* m_config;
71
72#ifdef BUILD_SDL
73 GBASDLEvents m_sdlEvents;
74#endif
75
76 QSet<int> m_activeButtons;
77 QSet<QPair<int, int32_t>> m_activeAxes;
78 QTimer* m_gamepadTimer;
79};
80
81}
82
83#endif