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 template <typename T> struct Shortcuts {
39 T loadState;
40 T saveState;
41 T holdFastForward;
42 T holdRewind;
43 };
44
45 struct Axis {
46 GamepadAxisEvent::Direction direction;
47 int axis;
48 };
49
50 template <typename T> struct KeyList {
51 T keyA;
52 T keyB;
53 T keySelect;
54 T keyStart;
55 T keyRight;
56 T keyLeft;
57 T keyUp;
58 T keyDown;
59 T keyR;
60 T keyL;
61 };
62
63 constexpr InputProfile(const char* name,
64 const KeyList<int> keys,
65 const Shortcuts<int> shortcutButtons = { -1, -1, -1, -1},
66 const Shortcuts<Axis> shortcutAxes = {
67 {GamepadAxisEvent::Direction::NEUTRAL, -1},
68 {GamepadAxisEvent::Direction::NEUTRAL, -1},
69 {GamepadAxisEvent::Direction::NEUTRAL, -1},
70 {GamepadAxisEvent::Direction::NEUTRAL, -1}},
71 const KeyList<AxisValue> axes = {
72 { GamepadAxisEvent::Direction::NEUTRAL, -1 },
73 { GamepadAxisEvent::Direction::NEUTRAL, -1 },
74 { GamepadAxisEvent::Direction::NEUTRAL, -1 },
75 { GamepadAxisEvent::Direction::NEUTRAL, -1 },
76 { GamepadAxisEvent::Direction::POSITIVE, 0 },
77 { GamepadAxisEvent::Direction::NEGATIVE, 0 },
78 { GamepadAxisEvent::Direction::NEGATIVE, 1 },
79 { GamepadAxisEvent::Direction::POSITIVE, 1 },
80 { GamepadAxisEvent::Direction::NEUTRAL, -1 },
81 { GamepadAxisEvent::Direction::NEUTRAL, -1 }},
82 const struct Coord& tiltAxis = { 2, 3 },
83 const struct Coord& gyroAxis = { 0, 1 },
84 float gyroSensitivity = 2e+09f);
85
86 static const InputProfile s_defaultMaps[];
87
88 const char* m_profileName;
89 const int m_keys[GBA_KEY_MAX];
90 const AxisValue m_axes[GBA_KEY_MAX];
91 const Shortcuts<int> m_shortcutButtons;
92 const Shortcuts<Axis> m_shortcutAxes;
93 Coord m_tiltAxis;
94 Coord m_gyroAxis;
95 float m_gyroSensitivity;
96};
97
98}
99
100#endif