diff options
| author | 2016-06-10 22:28:58 -0400 | |
|---|---|---|
| committer | 2016-06-10 22:28:58 -0400 | |
| commit | f99961581ee129c44625dbd8890fab349253271a (patch) | |
| tree | 9a2610d391d795b533054a91c22763e869bdd62b /src/common/key_map.h | |
| parent | Merge pull request #1896 from citra-emu/revert-1893-interpreter-split (diff) | |
| parent | fixup! fixup! Refactor input system (diff) | |
| download | yuzu-f99961581ee129c44625dbd8890fab349253271a.tar.gz yuzu-f99961581ee129c44625dbd8890fab349253271a.tar.xz yuzu-f99961581ee129c44625dbd8890fab349253271a.zip | |
Merge pull request #1789 from wwylele/input-refactor
Refactor input mapping & implement circle pad modifier
Diffstat (limited to 'src/common/key_map.h')
| -rw-r--r-- | src/common/key_map.h | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/src/common/key_map.h b/src/common/key_map.h index 68f7e2f99..b62f017c6 100644 --- a/src/common/key_map.h +++ b/src/common/key_map.h | |||
| @@ -4,12 +4,51 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | ||
| 7 | #include <tuple> | 8 | #include <tuple> |
| 8 | #include "core/hle/service/hid/hid.h" | 9 | #include "core/hle/service/hid/hid.h" |
| 9 | 10 | ||
| 11 | class EmuWindow; | ||
| 12 | |||
| 10 | namespace KeyMap { | 13 | namespace KeyMap { |
| 11 | 14 | ||
| 12 | /** | 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 | */ | ||
| 19 | enum 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 | */ | ||
| 31 | struct 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 | /** | ||
| 13 | * Represents a key for a specific host device. | 52 | * Represents a key for a specific host device. |
| 14 | */ | 53 | */ |
| 15 | struct HostDeviceKey { | 54 | struct HostDeviceKey { |
| @@ -27,19 +66,31 @@ struct HostDeviceKey { | |||
| 27 | } | 66 | } |
| 28 | }; | 67 | }; |
| 29 | 68 | ||
| 69 | extern const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets; | ||
| 70 | |||
| 30 | /** | 71 | /** |
| 31 | * Generates a new device id, which uniquely identifies a host device within KeyMap. | 72 | * Generates a new device id, which uniquely identifies a host device within KeyMap. |
| 32 | */ | 73 | */ |
| 33 | int NewDeviceId(); | 74 | int NewDeviceId(); |
| 34 | 75 | ||
| 35 | /** | 76 | /** |
| 36 | * Maps a device-specific key to a PadState. | 77 | * Maps a device-specific key to a target (a PadState or an IndirectTarget). |
| 78 | */ | ||
| 79 | void SetKeyMapping(HostDeviceKey key, KeyTarget target); | ||
| 80 | |||
| 81 | /** | ||
| 82 | * Clears all key mappings belonging to one device. | ||
| 83 | */ | ||
| 84 | void ClearKeyMapping(int device_id); | ||
| 85 | |||
| 86 | /** | ||
| 87 | * Maps a key press action and call the corresponding function in EmuWindow | ||
| 37 | */ | 88 | */ |
| 38 | void SetKeyMapping(HostDeviceKey key, Service::HID::PadState padState); | 89 | void PressKey(EmuWindow& emu_window, HostDeviceKey key); |
| 39 | 90 | ||
| 40 | /** | 91 | /** |
| 41 | * Gets the PadState that's mapped to the provided device-specific key. | 92 | * Maps a key release action and call the corresponding function in EmuWindow |
| 42 | */ | 93 | */ |
| 43 | Service::HID::PadState GetPadKey(HostDeviceKey key); | 94 | void ReleaseKey(EmuWindow& emu_window, HostDeviceKey key); |
| 44 | 95 | ||
| 45 | } | 96 | } |