src/platform/qt/InputProfile.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_PROFILE
7#define QGBA_INPUT_PROFILE
8
9#include "GamepadAxisEvent.h"
10
11extern "C" {
12#include "gba/interface.h"
13}
14
15namespace QGBA {
16
17class InputController;
18
19class InputProfile {
20public:
21 static const InputProfile* findProfile(const QString& name);
22
23 void apply(InputController*) const;
24 bool lookupShortcutButton(const QString& shortcut, int* button) const;
25 bool lookupShortcutAxis(const QString& shortcut, int* axis, GamepadAxisEvent::Direction* direction) const;
26
27private:
28 struct Coord {
29 int x;
30 int y;
31 };
32
33 struct AxisValue {
34 GamepadAxisEvent::Direction direction;
35 int axis;
36 };
37
38 struct ShortcutButton {
39 const char* shortcut;
40 int button;
41 };
42
43 struct ShortcutAxis {
44 const char* shortcut;
45 GamepadAxisEvent::Direction direction;
46 int axis;
47 };
48
49 constexpr InputProfile(const char* name,
50 int keys[GBA_KEY_MAX],
51 const ShortcutButton* shortcutButtons = (ShortcutButton[]) {{}},
52 const ShortcutAxis* shortcutAxes = (ShortcutAxis[]) {{}},
53 AxisValue axes[GBA_KEY_MAX] = (AxisValue[GBA_KEY_MAX]) {
54 {}, {}, {}, {},
55 { GamepadAxisEvent::Direction::POSITIVE, 0 },
56 { GamepadAxisEvent::Direction::NEGATIVE, 0 },
57 { GamepadAxisEvent::Direction::NEGATIVE, 1 },
58 { GamepadAxisEvent::Direction::POSITIVE, 1 },
59 {}, {}},
60 const struct Coord& tiltAxis = { 2, 3 },
61 const struct Coord& gyroAxis = { 0, 1 },
62 float gyroSensitivity = 2e+09f);
63
64 static const InputProfile s_defaultMaps[];
65
66 const char* m_profileName;
67 const int m_keys[GBA_KEY_MAX];
68 const AxisValue m_axes[GBA_KEY_MAX];
69 const ShortcutButton* m_shortcutButtons;
70 const ShortcutAxis* m_shortcutAxes;
71 Coord m_tiltAxis;
72 Coord m_gyroAxis;
73 float m_gyroSensitivity;
74};
75
76}
77
78#endif