summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/input_common/CMakeLists.txt2
-rw-r--r--src/input_common/drivers/touch_screen.cpp47
-rw-r--r--src/input_common/drivers/touch_screen.h50
3 files changed, 99 insertions, 0 deletions
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt
index 34b41ce01..71091767d 100644
--- a/src/input_common/CMakeLists.txt
+++ b/src/input_common/CMakeLists.txt
@@ -3,6 +3,8 @@ add_library(input_common STATIC
3 drivers/keyboard.h 3 drivers/keyboard.h
4 drivers/mouse.cpp 4 drivers/mouse.cpp
5 drivers/mouse.h 5 drivers/mouse.h
6 drivers/touch_screen.cpp
7 drivers/touch_screen.h
6 helpers/stick_from_buttons.cpp 8 helpers/stick_from_buttons.cpp
7 helpers/stick_from_buttons.h 9 helpers/stick_from_buttons.h
8 helpers/touch_from_buttons.cpp 10 helpers/touch_from_buttons.cpp
diff --git a/src/input_common/drivers/touch_screen.cpp b/src/input_common/drivers/touch_screen.cpp
new file mode 100644
index 000000000..e13835e9f
--- /dev/null
+++ b/src/input_common/drivers/touch_screen.cpp
@@ -0,0 +1,47 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included
4
5#include "common/param_package.h"
6#include "input_common/drivers/touch_screen.h"
7
8namespace InputCommon {
9
10TouchScreen::TouchScreen(const std::string input_engine_) : InputEngine(input_engine_) {
11 PreSetController(identifier);
12}
13
14void TouchScreen::TouchMoved(float x, float y, std::size_t finger) {
15 if (finger >= 16) {
16 return;
17 }
18 TouchPressed(x, y, finger);
19}
20
21void TouchScreen::TouchPressed(float x, float y, std::size_t finger) {
22 if (finger >= 16) {
23 return;
24 }
25 SetButton(identifier, static_cast<int>(finger), true);
26 SetAxis(identifier, static_cast<int>(finger * 2), x);
27 SetAxis(identifier, static_cast<int>(finger * 2 + 1), y);
28}
29
30void TouchScreen::TouchReleased(std::size_t finger) {
31 if (finger >= 16) {
32 return;
33 }
34 SetButton(identifier, static_cast<int>(finger), false);
35 SetAxis(identifier, static_cast<int>(finger * 2), 0.0f);
36 SetAxis(identifier, static_cast<int>(finger * 2 + 1), 0.0f);
37}
38
39void TouchScreen::ReleaseAllTouch() {
40 for (int index = 0; index < 16; ++index) {
41 SetButton(identifier, index, false);
42 SetAxis(identifier, index * 2, 0.0f);
43 SetAxis(identifier, index * 2 + 1, 0.0f);
44 }
45}
46
47} // namespace InputCommon
diff --git a/src/input_common/drivers/touch_screen.h b/src/input_common/drivers/touch_screen.h
new file mode 100644
index 000000000..5fbb2f47f
--- /dev/null
+++ b/src/input_common/drivers/touch_screen.h
@@ -0,0 +1,50 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included
4
5#pragma once
6
7#include "input_common/input_engine.h"
8
9namespace InputCommon {
10
11/**
12 * A button device factory representing a keyboard. It receives keyboard events and forward them
13 * to all button devices it created.
14 */
15class TouchScreen final : public InputCommon::InputEngine {
16public:
17 explicit TouchScreen(const std::string input_engine_);
18
19 /**
20 * Signals that mouse has moved.
21 * @param x the x-coordinate of the cursor
22 * @param y the y-coordinate of the cursor
23 * @param center_x the x-coordinate of the middle of the screen
24 * @param center_y the y-coordinate of the middle of the screen
25 */
26 void TouchMoved(float x, float y, std::size_t finger);
27
28 /**
29 * Sets the status of all buttons bound with the key to pressed
30 * @param key_code the code of the key to press
31 */
32 void TouchPressed(float x, float y, std::size_t finger);
33
34 /**
35 * Sets the status of all buttons bound with the key to released
36 * @param key_code the code of the key to release
37 */
38 void TouchReleased(std::size_t finger);
39
40 void ReleaseAllTouch();
41
42private:
43 const PadIdentifier identifier = {
44 .guid = Common::UUID{""},
45 .port = 0,
46 .pad = 0,
47 };
48};
49
50} // namespace InputCommon