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#pragma once
7
8#include "GamepadAxisEvent.h"
9
10#include <mgba/gba/interface.h>
11
12namespace QGBA {
13
14class InputController;
15
16class InputProfile {
17public:
18 static const InputProfile* findProfile(const QString& name);
19
20 void apply(InputController*) const;
21 bool lookupShortcutButton(const QString& shortcut, int* button) const;
22 bool lookupShortcutAxis(const QString& shortcut, int* axis, GamepadAxisEvent::Direction* direction) const;
23
24private:
25 struct Coord {
26 int x;
27 int y;
28 };
29
30 struct AxisValue {
31 GamepadAxisEvent::Direction direction;
32 int axis;
33 };
34
35 template <typename T> struct Shortcuts {
36 T loadState;
37 T saveState;
38 T holdFastForward;
39 T holdRewind;
40 };
41
42 struct Axis {
43 GamepadAxisEvent::Direction direction;
44 int axis;
45 };
46
47 template <typename T> struct KeyList {
48 T keyA;
49 T keyB;
50 T keySelect;
51 T keyStart;
52 T keyRight;
53 T keyLeft;
54 T keyUp;
55 T keyDown;
56 T keyR;
57 T keyL;
58 };
59
60 constexpr InputProfile(const char* name,
61 const KeyList<int> keys,
62 const Shortcuts<int> shortcutButtons = { -1, -1, -1, -1},
63 const Shortcuts<Axis> shortcutAxes = {
64 {GamepadAxisEvent::Direction::NEUTRAL, -1},
65 {GamepadAxisEvent::Direction::NEUTRAL, -1},
66 {GamepadAxisEvent::Direction::NEUTRAL, -1},
67 {GamepadAxisEvent::Direction::NEUTRAL, -1}},
68 const KeyList<AxisValue> axes = {
69 { GamepadAxisEvent::Direction::NEUTRAL, -1 },
70 { GamepadAxisEvent::Direction::NEUTRAL, -1 },
71 { GamepadAxisEvent::Direction::NEUTRAL, -1 },
72 { GamepadAxisEvent::Direction::NEUTRAL, -1 },
73 { GamepadAxisEvent::Direction::POSITIVE, 0 },
74 { GamepadAxisEvent::Direction::NEGATIVE, 0 },
75 { GamepadAxisEvent::Direction::NEGATIVE, 1 },
76 { GamepadAxisEvent::Direction::POSITIVE, 1 },
77 { GamepadAxisEvent::Direction::NEUTRAL, -1 },
78 { GamepadAxisEvent::Direction::NEUTRAL, -1 }},
79 const struct Coord& tiltAxis = { 2, 3 },
80 const struct Coord& gyroAxis = { 0, 1 },
81 float gyroSensitivity = 2e+09f);
82
83 static const InputProfile s_defaultMaps[];
84
85 const char* m_profileName;
86 const int m_keys[GBA_KEY_MAX];
87 const AxisValue m_axes[GBA_KEY_MAX];
88 const Shortcuts<int> m_shortcutButtons;
89 const Shortcuts<Axis> m_shortcutAxes;
90 Coord m_tiltAxis;
91 Coord m_gyroAxis;
92 float m_gyroSensitivity;
93};
94
95}