diff options
author | bunnei <bunneidev@gmail.com> | 2022-12-18 02:16:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-18 02:16:13 +0100 |
commit | 48108a8c9b28e08f86aab5c2ad41414e455f4706 (patch) | |
tree | 2dc3ff390a17ebdee32958eac619632cef424fe4 /src/input_common/drivers/virtual_gamepad.h | |
parent | Merge pull request #7450 from FernandoS27/ndc-vulkan (diff) | |
parent | input_common: Add virtual gamepad (diff) | |
download | yuzu-48108a8c9b28e08f86aab5c2ad41414e455f4706.tar yuzu-48108a8c9b28e08f86aab5c2ad41414e455f4706.tar.gz yuzu-48108a8c9b28e08f86aab5c2ad41414e455f4706.tar.bz2 yuzu-48108a8c9b28e08f86aab5c2ad41414e455f4706.tar.lz yuzu-48108a8c9b28e08f86aab5c2ad41414e455f4706.tar.xz yuzu-48108a8c9b28e08f86aab5c2ad41414e455f4706.tar.zst yuzu-48108a8c9b28e08f86aab5c2ad41414e455f4706.zip |
Diffstat (limited to 'src/input_common/drivers/virtual_gamepad.h')
-rw-r--r-- | src/input_common/drivers/virtual_gamepad.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/input_common/drivers/virtual_gamepad.h b/src/input_common/drivers/virtual_gamepad.h new file mode 100644 index 000000000..3df91cc6f --- /dev/null +++ b/src/input_common/drivers/virtual_gamepad.h @@ -0,0 +1,73 @@ +// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "input_common/input_engine.h" + +namespace InputCommon { + +/** + * A virtual controller that is always assigned to the game input + */ +class VirtualGamepad final : public InputEngine { +public: + enum class VirtualButton { + ButtonA, + ButtonB, + ButtonX, + ButtonY, + StickL, + StickR, + TriggerL, + TriggerR, + TriggerZL, + TriggerZR, + ButtonPlus, + ButtonMinus, + ButtonLeft, + ButtonUp, + ButtonRight, + ButtonDown, + ButtonSL, + ButtonSR, + ButtonHome, + ButtonCapture, + }; + + enum class VirtualStick { + Left = 0, + Right = 1, + }; + + explicit VirtualGamepad(std::string input_engine_); + + /** + * Sets the status of all buttons bound with the key to pressed + * @param player_index the player number that will take this action + * @param button_id the id of the button + * @param value indicates if the button is pressed or not + */ + void SetButtonState(std::size_t player_index, int button_id, bool value); + void SetButtonState(std::size_t player_index, VirtualButton button_id, bool value); + + /** + * Sets the status of all buttons bound with the key to released + * @param player_index the player number that will take this action + * @param axis_id the id of the axis to move + * @param x_value the position of the stick in the x axis + * @param y_value the position of the stick in the y axis + */ + void SetStickPosition(std::size_t player_index, int axis_id, float x_value, float y_value); + void SetStickPosition(std::size_t player_index, VirtualStick axis_id, float x_value, + float y_value); + + /// Restores all inputs into the neutral position + void ResetControllers(); + +private: + /// Returns the correct identifier corresponding to the player index + PadIdentifier GetIdentifier(std::size_t player_index) const; +}; + +} // namespace InputCommon |