summaryrefslogtreecommitdiff
path: root/src/input_common/touch_from_button.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/touch_from_button.cpp')
-rw-r--r--src/input_common/touch_from_button.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/input_common/touch_from_button.cpp b/src/input_common/touch_from_button.cpp
new file mode 100644
index 000000000..a07124a86
--- /dev/null
+++ b/src/input_common/touch_from_button.cpp
@@ -0,0 +1,51 @@
1// Copyright 2020 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "core/frontend/framebuffer_layout.h"
6#include "core/settings.h"
7#include "input_common/touch_from_button.h"
8
9namespace InputCommon {
10
11class TouchFromButtonDevice final : public Input::TouchDevice {
12public:
13 TouchFromButtonDevice() {
14 const auto button_index =
15 static_cast<std::size_t>(Settings::values.touch_from_button_map_index);
16 const auto& buttons = Settings::values.touch_from_button_maps[button_index].buttons;
17
18 for (const auto& config_entry : buttons) {
19 const Common::ParamPackage package{config_entry};
20 map.emplace_back(
21 Input::CreateDevice<Input::ButtonDevice>(config_entry),
22 std::clamp(package.Get("x", 0), 0, static_cast<int>(Layout::ScreenUndocked::Width)),
23 std::clamp(package.Get("y", 0), 0,
24 static_cast<int>(Layout::ScreenUndocked::Height)));
25 }
26 }
27
28 std::tuple<float, float, bool> GetStatus() const override {
29 for (const auto& m : map) {
30 const bool state = std::get<0>(m)->GetStatus();
31 if (state) {
32 const float x = static_cast<float>(std::get<1>(m)) /
33 static_cast<int>(Layout::ScreenUndocked::Width);
34 const float y = static_cast<float>(std::get<2>(m)) /
35 static_cast<int>(Layout::ScreenUndocked::Height);
36 return {x, y, true};
37 }
38 }
39 return {};
40 }
41
42private:
43 // A vector of the mapped button, its x and its y-coordinate
44 std::vector<std::tuple<std::unique_ptr<Input::ButtonDevice>, int, int>> map;
45};
46
47std::unique_ptr<Input::TouchDevice> TouchFromButtonFactory::Create(const Common::ParamPackage&) {
48 return std::make_unique<TouchFromButtonDevice>();
49}
50
51} // namespace InputCommon