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