diff options
| author | 2016-05-12 13:09:36 +0300 | |
|---|---|---|
| committer | 2016-05-15 13:24:22 +0300 | |
| commit | 03631f9b8fe75cf1c3a70a3094aeddcebffa4cf9 (patch) | |
| tree | 95edc62b3b8520a533e534bf4991159875fef3e5 /src/common/key_map.h | |
| parent | AudioCore: Implement time stretcher (#1737) (diff) | |
| download | yuzu-03631f9b8fe75cf1c3a70a3094aeddcebffa4cf9.tar.gz yuzu-03631f9b8fe75cf1c3a70a3094aeddcebffa4cf9.tar.xz yuzu-03631f9b8fe75cf1c3a70a3094aeddcebffa4cf9.zip | |
Refactor input subsystem
Diffstat (limited to 'src/common/key_map.h')
| -rw-r--r-- | src/common/key_map.h | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/src/common/key_map.h b/src/common/key_map.h index 68f7e2f99..0438a14e0 100644 --- a/src/common/key_map.h +++ b/src/common/key_map.h | |||
| @@ -4,11 +4,42 @@ | |||
| 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 | ||
| 15 | enum class IndirectTarget { | ||
| 16 | CIRCLE_PAD_UP, CIRCLE_PAD_DOWN, CIRCLE_PAD_LEFT, CIRCLE_PAD_RIGHT, | ||
| 17 | }; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * Represents a key mapping target. It can be a PadState that represents 3DS real buttons, | ||
| 21 | * or an IndirectTarget. | ||
| 22 | */ | ||
| 23 | struct KeyTarget { | ||
| 24 | bool direct; | ||
| 25 | union { | ||
| 26 | u32 direct_target_hex; | ||
| 27 | IndirectTarget indirect_target; | ||
| 28 | } target; | ||
| 29 | |||
| 30 | KeyTarget() : direct(true) { | ||
| 31 | target.direct_target_hex = 0; | ||
| 32 | } | ||
| 33 | |||
| 34 | KeyTarget(Service::HID::PadState pad) : direct(true) { | ||
| 35 | target.direct_target_hex = pad.hex; | ||
| 36 | } | ||
| 37 | |||
| 38 | KeyTarget(IndirectTarget i) : direct(false) { | ||
| 39 | target.indirect_target = i; | ||
| 40 | } | ||
| 41 | }; | ||
| 42 | |||
| 12 | /** | 43 | /** |
| 13 | * Represents a key for a specific host device. | 44 | * Represents a key for a specific host device. |
| 14 | */ | 45 | */ |
| @@ -27,19 +58,31 @@ struct HostDeviceKey { | |||
| 27 | } | 58 | } |
| 28 | }; | 59 | }; |
| 29 | 60 | ||
| 61 | extern const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets; | ||
| 62 | |||
| 30 | /** | 63 | /** |
| 31 | * Generates a new device id, which uniquely identifies a host device within KeyMap. | 64 | * Generates a new device id, which uniquely identifies a host device within KeyMap. |
| 32 | */ | 65 | */ |
| 33 | int NewDeviceId(); | 66 | int NewDeviceId(); |
| 34 | 67 | ||
| 35 | /** | 68 | /** |
| 36 | * Maps a device-specific key to a PadState. | 69 | * Maps a device-specific key to a target (a PadState or an IndirectTarget). |
| 70 | */ | ||
| 71 | void SetKeyMapping(HostDeviceKey key, KeyTarget target); | ||
| 72 | |||
| 73 | /** | ||
| 74 | * Clears all key mappings belonging to one device. | ||
| 75 | */ | ||
| 76 | void ClearKeyMapping(int device_id); | ||
| 77 | |||
| 78 | /** | ||
| 79 | * Maps a key press actions and call the corresponding function in EmuWindow | ||
| 37 | */ | 80 | */ |
| 38 | void SetKeyMapping(HostDeviceKey key, Service::HID::PadState padState); | 81 | void PressKey(EmuWindow& emu_window, HostDeviceKey key); |
| 39 | 82 | ||
| 40 | /** | 83 | /** |
| 41 | * Gets the PadState that's mapped to the provided device-specific key. | 84 | * Maps a key release actions and call the corresponding function in EmuWindow |
| 42 | */ | 85 | */ |
| 43 | Service::HID::PadState GetPadKey(HostDeviceKey key); | 86 | void ReleaseKey(EmuWindow& emu_window, HostDeviceKey key); |
| 44 | 87 | ||
| 45 | } | 88 | } |