diff options
| author | 2017-03-17 14:59:39 -0400 | |
|---|---|---|
| committer | 2017-03-17 14:59:39 -0400 | |
| commit | 423ab5e2bcf5a522e5f412447c05f648df57a14c (patch) | |
| tree | 1e60eaeffa59229254a47f885d2fe2cbbdc1a5c0 /src/input_common/main.cpp | |
| parent | Merge pull request #2618 from wwylele/log-less-filename (diff) | |
| parent | qt/config_input: don't connect for null button (diff) | |
| download | yuzu-423ab5e2bcf5a522e5f412447c05f648df57a14c.tar.gz yuzu-423ab5e2bcf5a522e5f412447c05f648df57a14c.tar.xz yuzu-423ab5e2bcf5a522e5f412447c05f648df57a14c.zip | |
Merge pull request #2497 from wwylele/input-2
Refactor input emulation & add SDL gamepad support
Diffstat (limited to 'src/input_common/main.cpp')
| -rw-r--r-- | src/input_common/main.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp new file mode 100644 index 000000000..699f41e6b --- /dev/null +++ b/src/input_common/main.cpp | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <memory> | ||
| 6 | #include "common/param_package.h" | ||
| 7 | #include "input_common/analog_from_button.h" | ||
| 8 | #include "input_common/keyboard.h" | ||
| 9 | #include "input_common/main.h" | ||
| 10 | #ifdef HAVE_SDL2 | ||
| 11 | #include "input_common/sdl/sdl.h" | ||
| 12 | #endif | ||
| 13 | |||
| 14 | namespace InputCommon { | ||
| 15 | |||
| 16 | static std::shared_ptr<Keyboard> keyboard; | ||
| 17 | |||
| 18 | void Init() { | ||
| 19 | keyboard = std::make_shared<InputCommon::Keyboard>(); | ||
| 20 | Input::RegisterFactory<Input::ButtonDevice>("keyboard", keyboard); | ||
| 21 | Input::RegisterFactory<Input::AnalogDevice>("analog_from_button", | ||
| 22 | std::make_shared<InputCommon::AnalogFromButton>()); | ||
| 23 | #ifdef HAVE_SDL2 | ||
| 24 | SDL::Init(); | ||
| 25 | #endif | ||
| 26 | } | ||
| 27 | |||
| 28 | void Shutdown() { | ||
| 29 | Input::UnregisterFactory<Input::ButtonDevice>("keyboard"); | ||
| 30 | keyboard.reset(); | ||
| 31 | Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button"); | ||
| 32 | |||
| 33 | #ifdef HAVE_SDL2 | ||
| 34 | SDL::Shutdown(); | ||
| 35 | #endif | ||
| 36 | } | ||
| 37 | |||
| 38 | Keyboard* GetKeyboard() { | ||
| 39 | return keyboard.get(); | ||
| 40 | } | ||
| 41 | |||
| 42 | std::string GenerateKeyboardParam(int key_code) { | ||
| 43 | Common::ParamPackage param{ | ||
| 44 | {"engine", "keyboard"}, {"code", std::to_string(key_code)}, | ||
| 45 | }; | ||
| 46 | return param.Serialize(); | ||
| 47 | } | ||
| 48 | |||
| 49 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, | ||
| 50 | int key_modifier, float modifier_scale) { | ||
| 51 | Common::ParamPackage circle_pad_param{ | ||
| 52 | {"engine", "analog_from_button"}, | ||
| 53 | {"up", GenerateKeyboardParam(key_up)}, | ||
| 54 | {"down", GenerateKeyboardParam(key_down)}, | ||
| 55 | {"left", GenerateKeyboardParam(key_left)}, | ||
| 56 | {"right", GenerateKeyboardParam(key_right)}, | ||
| 57 | {"modifier", GenerateKeyboardParam(key_modifier)}, | ||
| 58 | {"modifier_scale", std::to_string(modifier_scale)}, | ||
| 59 | }; | ||
| 60 | return circle_pad_param.Serialize(); | ||
| 61 | } | ||
| 62 | |||
| 63 | } // namespace InputCommon | ||