all repos — mgba @ fa884d071ecaa3e05ff20b45a67bf9500dd3d6b6

mGBA Game Boy Advance Emulator

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