summaryrefslogtreecommitdiff
path: root/src/core/frontend/key_map.h
diff options
context:
space:
mode:
authorGravatar MerryMage2016-12-23 13:37:40 +0000
committerGravatar MerryMage2016-12-23 13:42:39 +0000
commit64f98f4d0f33b5c626d86a05ab9dd8060e160cc5 (patch)
tree8874f16f9f840add798f58981d5c2fcdf4da3c84 /src/core/frontend/key_map.h
parentMerge pull request #2364 from mailwl/nwm-services (diff)
downloadyuzu-64f98f4d0f33b5c626d86a05ab9dd8060e160cc5.tar.gz
yuzu-64f98f4d0f33b5c626d86a05ab9dd8060e160cc5.tar.xz
yuzu-64f98f4d0f33b5c626d86a05ab9dd8060e160cc5.zip
core: Move emu_window and key_map into core
* Removes circular dependences (common should not depend on core)
Diffstat (limited to 'src/core/frontend/key_map.h')
-rw-r--r--src/core/frontend/key_map.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/core/frontend/key_map.h b/src/core/frontend/key_map.h
new file mode 100644
index 000000000..040794578
--- /dev/null
+++ b/src/core/frontend/key_map.h
@@ -0,0 +1,93 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8#include <tuple>
9#include "core/hle/service/hid/hid.h"
10
11class EmuWindow;
12
13namespace KeyMap {
14
15/**
16 * Represents key mapping targets that are not real 3DS buttons.
17 * They will be handled by KeyMap and translated to 3DS input.
18 */
19enum class IndirectTarget {
20 CirclePadUp,
21 CirclePadDown,
22 CirclePadLeft,
23 CirclePadRight,
24 CirclePadModifier,
25};
26
27/**
28 * Represents a key mapping target. It can be a PadState that represents real 3DS buttons,
29 * or an IndirectTarget.
30 */
31struct KeyTarget {
32 bool direct;
33 union {
34 u32 direct_target_hex;
35 IndirectTarget indirect_target;
36 } target;
37
38 KeyTarget() : direct(true) {
39 target.direct_target_hex = 0;
40 }
41
42 KeyTarget(Service::HID::PadState pad) : direct(true) {
43 target.direct_target_hex = pad.hex;
44 }
45
46 KeyTarget(IndirectTarget i) : direct(false) {
47 target.indirect_target = i;
48 }
49};
50
51/**
52 * Represents a key for a specific host device.
53 */
54struct HostDeviceKey {
55 int key_code;
56 int device_id; ///< Uniquely identifies a host device
57
58 bool operator<(const HostDeviceKey& other) const {
59 return std::tie(key_code, device_id) < std::tie(other.key_code, other.device_id);
60 }
61
62 bool operator==(const HostDeviceKey& other) const {
63 return std::tie(key_code, device_id) == std::tie(other.key_code, other.device_id);
64 }
65};
66
67extern const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets;
68
69/**
70 * Generates a new device id, which uniquely identifies a host device within KeyMap.
71 */
72int NewDeviceId();
73
74/**
75 * Maps a device-specific key to a target (a PadState or an IndirectTarget).
76 */
77void SetKeyMapping(HostDeviceKey key, KeyTarget target);
78
79/**
80 * Clears all key mappings belonging to one device.
81 */
82void ClearKeyMapping(int device_id);
83
84/**
85 * Maps a key press action and call the corresponding function in EmuWindow
86 */
87void PressKey(EmuWindow& emu_window, HostDeviceKey key);
88
89/**
90 * Maps a key release action and call the corresponding function in EmuWindow
91 */
92void ReleaseKey(EmuWindow& emu_window, HostDeviceKey key);
93}