diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/common/point.h | 57 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/gesture.h | 36 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/touchscreen.cpp | 13 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/touchscreen.h | 7 |
5 files changed, 75 insertions, 39 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index eafb96b0b..7a4d9e354 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -154,6 +154,7 @@ add_library(common STATIC | |||
| 154 | param_package.cpp | 154 | param_package.cpp |
| 155 | param_package.h | 155 | param_package.h |
| 156 | parent_of_member.h | 156 | parent_of_member.h |
| 157 | point.h | ||
| 157 | quaternion.h | 158 | quaternion.h |
| 158 | ring_buffer.h | 159 | ring_buffer.h |
| 159 | scm_rev.cpp | 160 | scm_rev.cpp |
diff --git a/src/common/point.h b/src/common/point.h new file mode 100644 index 000000000..c0a52ad8d --- /dev/null +++ b/src/common/point.h | |||
| @@ -0,0 +1,57 @@ | |||
| 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 <type_traits> | ||
| 8 | |||
| 9 | namespace Common { | ||
| 10 | |||
| 11 | // Represents a point within a 2D space. | ||
| 12 | template <typename T> | ||
| 13 | struct Point { | ||
| 14 | static_assert(std::is_arithmetic_v<T>, "T must be an arithmetic type!"); | ||
| 15 | |||
| 16 | T x{}; | ||
| 17 | T y{}; | ||
| 18 | |||
| 19 | #define ARITHMETIC_OP(op, compound_op) \ | ||
| 20 | friend constexpr Point operator op(const Point& lhs, const Point& rhs) noexcept { \ | ||
| 21 | return { \ | ||
| 22 | .x = static_cast<T>(lhs.x op rhs.x), \ | ||
| 23 | .y = static_cast<T>(lhs.y op rhs.y), \ | ||
| 24 | }; \ | ||
| 25 | } \ | ||
| 26 | friend constexpr Point operator op(const Point& lhs, T value) noexcept { \ | ||
| 27 | return { \ | ||
| 28 | .x = static_cast<T>(lhs.x op value), \ | ||
| 29 | .y = static_cast<T>(lhs.y op value), \ | ||
| 30 | }; \ | ||
| 31 | } \ | ||
| 32 | friend constexpr Point operator op(T value, const Point& rhs) noexcept { \ | ||
| 33 | return { \ | ||
| 34 | .x = static_cast<T>(value op rhs.x), \ | ||
| 35 | .y = static_cast<T>(value op rhs.y), \ | ||
| 36 | }; \ | ||
| 37 | } \ | ||
| 38 | friend constexpr Point& operator compound_op(Point& lhs, const Point& rhs) noexcept { \ | ||
| 39 | lhs.x = static_cast<T>(lhs.x op rhs.x); \ | ||
| 40 | lhs.y = static_cast<T>(lhs.y op rhs.y); \ | ||
| 41 | return lhs; \ | ||
| 42 | } \ | ||
| 43 | friend constexpr Point& operator compound_op(Point& lhs, T value) noexcept { \ | ||
| 44 | lhs.x = static_cast<T>(lhs.x op value); \ | ||
| 45 | lhs.y = static_cast<T>(lhs.y op value); \ | ||
| 46 | return lhs; \ | ||
| 47 | } | ||
| 48 | ARITHMETIC_OP(+, +=) | ||
| 49 | ARITHMETIC_OP(-, -=) | ||
| 50 | ARITHMETIC_OP(*, *=) | ||
| 51 | ARITHMETIC_OP(/, /=) | ||
| 52 | #undef ARITHMETIC_OP | ||
| 53 | |||
| 54 | friend constexpr bool operator==(const Point&, const Point&) = default; | ||
| 55 | }; | ||
| 56 | |||
| 57 | } // namespace Common | ||
diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h index eecfeaad5..7e7ae6625 100644 --- a/src/core/hle/service/hid/controllers/gesture.h +++ b/src/core/hle/service/hid/controllers/gesture.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include "common/bit_field.h" | 8 | #include "common/bit_field.h" |
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "common/point.h" | ||
| 10 | #include "core/frontend/input.h" | 11 | #include "core/frontend/input.h" |
| 11 | #include "core/hle/service/hid/controllers/controller_base.h" | 12 | #include "core/hle/service/hid/controllers/controller_base.h" |
| 12 | 13 | ||
| @@ -63,44 +64,21 @@ private: | |||
| 63 | }; | 64 | }; |
| 64 | static_assert(sizeof(Attribute) == 4, "Attribute is an invalid size"); | 65 | static_assert(sizeof(Attribute) == 4, "Attribute is an invalid size"); |
| 65 | 66 | ||
| 66 | template <typename T> | ||
| 67 | struct Point { | ||
| 68 | T x{}; | ||
| 69 | T y{}; | ||
| 70 | |||
| 71 | friend Point operator+(const Point& lhs, const Point& rhs) { | ||
| 72 | return { | ||
| 73 | .x = lhs.x + rhs.x, | ||
| 74 | .y = lhs.y + rhs.y, | ||
| 75 | }; | ||
| 76 | } | ||
| 77 | |||
| 78 | friend Point operator-(const Point& lhs, const Point& rhs) { | ||
| 79 | return { | ||
| 80 | .x = lhs.x - rhs.x, | ||
| 81 | .y = lhs.y - rhs.y, | ||
| 82 | }; | ||
| 83 | } | ||
| 84 | |||
| 85 | friend bool operator==(const Point&, const Point&) = default; | ||
| 86 | }; | ||
| 87 | static_assert(sizeof(Point<s32_le>) == 8, "Point is an invalid size"); | ||
| 88 | |||
| 89 | struct GestureState { | 67 | struct GestureState { |
| 90 | s64_le sampling_number; | 68 | s64_le sampling_number; |
| 91 | s64_le sampling_number2; | 69 | s64_le sampling_number2; |
| 92 | s64_le detection_count; | 70 | s64_le detection_count; |
| 93 | TouchType type; | 71 | TouchType type; |
| 94 | Direction direction; | 72 | Direction direction; |
| 95 | Point<s32_le> pos; | 73 | Common::Point<s32_le> pos; |
| 96 | Point<s32_le> delta; | 74 | Common::Point<s32_le> delta; |
| 97 | f32 vel_x; | 75 | f32 vel_x; |
| 98 | f32 vel_y; | 76 | f32 vel_y; |
| 99 | Attribute attributes; | 77 | Attribute attributes; |
| 100 | f32 scale; | 78 | f32 scale; |
| 101 | f32 rotation_angle; | 79 | f32 rotation_angle; |
| 102 | s32_le point_count; | 80 | s32_le point_count; |
| 103 | std::array<Point<s32_le>, 4> points; | 81 | std::array<Common::Point<s32_le>, 4> points; |
| 104 | }; | 82 | }; |
| 105 | static_assert(sizeof(GestureState) == 0x68, "GestureState is an invalid size"); | 83 | static_assert(sizeof(GestureState) == 0x68, "GestureState is an invalid size"); |
| 106 | 84 | ||
| @@ -111,14 +89,14 @@ private: | |||
| 111 | static_assert(sizeof(SharedMemory) == 0x708, "SharedMemory is an invalid size"); | 89 | static_assert(sizeof(SharedMemory) == 0x708, "SharedMemory is an invalid size"); |
| 112 | 90 | ||
| 113 | struct Finger { | 91 | struct Finger { |
| 114 | Point<f32> pos{}; | 92 | Common::Point<f32> pos{}; |
| 115 | bool pressed{}; | 93 | bool pressed{}; |
| 116 | }; | 94 | }; |
| 117 | 95 | ||
| 118 | struct GestureProperties { | 96 | struct GestureProperties { |
| 119 | std::array<Point<s32_le>, MAX_POINTS> points{}; | 97 | std::array<Common::Point<s32_le>, MAX_POINTS> points{}; |
| 120 | std::size_t active_points{}; | 98 | std::size_t active_points{}; |
| 121 | Point<s32_le> mid_point{}; | 99 | Common::Point<s32_le> mid_point{}; |
| 122 | s64_le detection_count{}; | 100 | s64_le detection_count{}; |
| 123 | u64_le delta_time{}; | 101 | u64_le delta_time{}; |
| 124 | f32 average_distance{}; | 102 | f32 average_distance{}; |
diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp index ac9112c40..6ef17acc5 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.cpp +++ b/src/core/hle/service/hid/controllers/touchscreen.cpp | |||
| @@ -74,8 +74,11 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin | |||
| 74 | for (std::size_t id = 0; id < MAX_FINGERS; ++id) { | 74 | for (std::size_t id = 0; id < MAX_FINGERS; ++id) { |
| 75 | auto& touch_entry = cur_entry.states[id]; | 75 | auto& touch_entry = cur_entry.states[id]; |
| 76 | if (id < active_fingers_count) { | 76 | if (id < active_fingers_count) { |
| 77 | touch_entry.x = static_cast<u16>(active_fingers[id].x * Layout::ScreenUndocked::Width); | 77 | const auto& [active_x, active_y] = active_fingers[id].position; |
| 78 | touch_entry.y = static_cast<u16>(active_fingers[id].y * Layout::ScreenUndocked::Height); | 78 | touch_entry.position = { |
| 79 | .x = static_cast<u16>(active_x * Layout::ScreenUndocked::Width), | ||
| 80 | .y = static_cast<u16>(active_y * Layout::ScreenUndocked::Height), | ||
| 81 | }; | ||
| 79 | touch_entry.diameter_x = Settings::values.touchscreen.diameter_x; | 82 | touch_entry.diameter_x = Settings::values.touchscreen.diameter_x; |
| 80 | touch_entry.diameter_y = Settings::values.touchscreen.diameter_y; | 83 | touch_entry.diameter_y = Settings::values.touchscreen.diameter_y; |
| 81 | touch_entry.rotation_angle = Settings::values.touchscreen.rotation_angle; | 84 | touch_entry.rotation_angle = Settings::values.touchscreen.rotation_angle; |
| @@ -86,8 +89,7 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin | |||
| 86 | } else { | 89 | } else { |
| 87 | // Clear touch entry | 90 | // Clear touch entry |
| 88 | touch_entry.attribute.raw = 0; | 91 | touch_entry.attribute.raw = 0; |
| 89 | touch_entry.x = 0; | 92 | touch_entry.position = {}; |
| 90 | touch_entry.y = 0; | ||
| 91 | touch_entry.diameter_x = 0; | 93 | touch_entry.diameter_x = 0; |
| 92 | touch_entry.diameter_y = 0; | 94 | touch_entry.diameter_y = 0; |
| 93 | touch_entry.rotation_angle = 0; | 95 | touch_entry.rotation_angle = 0; |
| @@ -140,8 +142,7 @@ std::size_t Controller_Touchscreen::UpdateTouchInputEvent( | |||
| 140 | fingers[finger_id].id = static_cast<u32_le>(finger_id); | 142 | fingers[finger_id].id = static_cast<u32_le>(finger_id); |
| 141 | attribute.start_touch.Assign(1); | 143 | attribute.start_touch.Assign(1); |
| 142 | } | 144 | } |
| 143 | fingers[finger_id].x = x; | 145 | fingers[finger_id].position = {x, y}; |
| 144 | fingers[finger_id].y = y; | ||
| 145 | fingers[finger_id].attribute = attribute; | 146 | fingers[finger_id].attribute = attribute; |
| 146 | return finger_id; | 147 | return finger_id; |
| 147 | } | 148 | } |
diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h index 2869d0cfd..ef2becefd 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.h +++ b/src/core/hle/service/hid/controllers/touchscreen.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "common/bit_field.h" | 7 | #include "common/bit_field.h" |
| 8 | #include "common/common_funcs.h" | 8 | #include "common/common_funcs.h" |
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "common/point.h" | ||
| 10 | #include "common/swap.h" | 11 | #include "common/swap.h" |
| 11 | #include "core/frontend/input.h" | 12 | #include "core/frontend/input.h" |
| 12 | #include "core/hle/service/hid/controllers/controller_base.h" | 13 | #include "core/hle/service/hid/controllers/controller_base.h" |
| @@ -55,8 +56,7 @@ private: | |||
| 55 | u64_le delta_time; | 56 | u64_le delta_time; |
| 56 | Attributes attribute; | 57 | Attributes attribute; |
| 57 | u32_le finger; | 58 | u32_le finger; |
| 58 | u32_le x; | 59 | Common::Point<u32_le> position; |
| 59 | u32_le y; | ||
| 60 | u32_le diameter_x; | 60 | u32_le diameter_x; |
| 61 | u32_le diameter_y; | 61 | u32_le diameter_y; |
| 62 | u32_le rotation_angle; | 62 | u32_le rotation_angle; |
| @@ -81,8 +81,7 @@ private: | |||
| 81 | 81 | ||
| 82 | struct Finger { | 82 | struct Finger { |
| 83 | u64_le last_touch{}; | 83 | u64_le last_touch{}; |
| 84 | float x{}; | 84 | Common::Point<float> position; |
| 85 | float y{}; | ||
| 86 | u32_le id{}; | 85 | u32_le id{}; |
| 87 | bool pressed{}; | 86 | bool pressed{}; |
| 88 | Attributes attribute; | 87 | Attributes attribute; |