diff options
| author | 2016-12-23 13:37:40 +0000 | |
|---|---|---|
| committer | 2016-12-23 13:42:39 +0000 | |
| commit | 64f98f4d0f33b5c626d86a05ab9dd8060e160cc5 (patch) | |
| tree | 8874f16f9f840add798f58981d5c2fcdf4da3c84 /src/core/frontend/emu_window.cpp | |
| parent | Merge pull request #2364 from mailwl/nwm-services (diff) | |
| download | yuzu-64f98f4d0f33b5c626d86a05ab9dd8060e160cc5.tar.gz yuzu-64f98f4d0f33b5c626d86a05ab9dd8060e160cc5.tar.xz yuzu-64f98f4d0f33b5c626d86a05ab9dd8060e160cc5.zip | |
core: Move emu_window and key_map into core
* Removes circular dependences (common should not depend on core)
Diffstat (limited to 'src/core/frontend/emu_window.cpp')
| -rw-r--r-- | src/core/frontend/emu_window.cpp | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp new file mode 100644 index 000000000..f6f90f9e1 --- /dev/null +++ b/src/core/frontend/emu_window.cpp | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cmath> | ||
| 7 | #include "common/assert.h" | ||
| 8 | #include "core/frontend/emu_window.h" | ||
| 9 | #include "core/frontend/key_map.h" | ||
| 10 | #include "video_core/video_core.h" | ||
| 11 | |||
| 12 | void EmuWindow::ButtonPressed(Service::HID::PadState pad) { | ||
| 13 | pad_state.hex |= pad.hex; | ||
| 14 | } | ||
| 15 | |||
| 16 | void EmuWindow::ButtonReleased(Service::HID::PadState pad) { | ||
| 17 | pad_state.hex &= ~pad.hex; | ||
| 18 | } | ||
| 19 | |||
| 20 | void EmuWindow::CirclePadUpdated(float x, float y) { | ||
| 21 | constexpr int MAX_CIRCLEPAD_POS = 0x9C; // Max value for a circle pad position | ||
| 22 | |||
| 23 | // Make sure the coordinates are in the unit circle, | ||
| 24 | // otherwise normalize it. | ||
| 25 | float r = x * x + y * y; | ||
| 26 | if (r > 1) { | ||
| 27 | r = std::sqrt(r); | ||
| 28 | x /= r; | ||
| 29 | y /= r; | ||
| 30 | } | ||
| 31 | |||
| 32 | circle_pad_x = static_cast<s16>(x * MAX_CIRCLEPAD_POS); | ||
| 33 | circle_pad_y = static_cast<s16>(y * MAX_CIRCLEPAD_POS); | ||
| 34 | } | ||
| 35 | |||
| 36 | /** | ||
| 37 | * Check if the given x/y coordinates are within the touchpad specified by the framebuffer layout | ||
| 38 | * @param layout FramebufferLayout object describing the framebuffer size and screen positions | ||
| 39 | * @param framebuffer_x Framebuffer x-coordinate to check | ||
| 40 | * @param framebuffer_y Framebuffer y-coordinate to check | ||
| 41 | * @return True if the coordinates are within the touchpad, otherwise false | ||
| 42 | */ | ||
| 43 | static bool IsWithinTouchscreen(const Layout::FramebufferLayout& layout, unsigned framebuffer_x, | ||
| 44 | unsigned framebuffer_y) { | ||
| 45 | return ( | ||
| 46 | framebuffer_y >= layout.bottom_screen.top && framebuffer_y < layout.bottom_screen.bottom && | ||
| 47 | framebuffer_x >= layout.bottom_screen.left && framebuffer_x < layout.bottom_screen.right); | ||
| 48 | } | ||
| 49 | |||
| 50 | std::tuple<unsigned, unsigned> EmuWindow::ClipToTouchScreen(unsigned new_x, unsigned new_y) { | ||
| 51 | new_x = std::max(new_x, framebuffer_layout.bottom_screen.left); | ||
| 52 | new_x = std::min(new_x, framebuffer_layout.bottom_screen.right - 1); | ||
| 53 | |||
| 54 | new_y = std::max(new_y, framebuffer_layout.bottom_screen.top); | ||
| 55 | new_y = std::min(new_y, framebuffer_layout.bottom_screen.bottom - 1); | ||
| 56 | |||
| 57 | return std::make_tuple(new_x, new_y); | ||
| 58 | } | ||
| 59 | |||
| 60 | void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) { | ||
| 61 | if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) | ||
| 62 | return; | ||
| 63 | |||
| 64 | touch_x = VideoCore::kScreenBottomWidth * | ||
| 65 | (framebuffer_x - framebuffer_layout.bottom_screen.left) / | ||
| 66 | (framebuffer_layout.bottom_screen.right - framebuffer_layout.bottom_screen.left); | ||
| 67 | touch_y = VideoCore::kScreenBottomHeight * | ||
| 68 | (framebuffer_y - framebuffer_layout.bottom_screen.top) / | ||
| 69 | (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top); | ||
| 70 | |||
| 71 | touch_pressed = true; | ||
| 72 | pad_state.touch.Assign(1); | ||
| 73 | } | ||
| 74 | |||
| 75 | void EmuWindow::TouchReleased() { | ||
| 76 | touch_pressed = false; | ||
| 77 | touch_x = 0; | ||
| 78 | touch_y = 0; | ||
| 79 | pad_state.touch.Assign(0); | ||
| 80 | } | ||
| 81 | |||
| 82 | void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) { | ||
| 83 | if (!touch_pressed) | ||
| 84 | return; | ||
| 85 | |||
| 86 | if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) | ||
| 87 | std::tie(framebuffer_x, framebuffer_y) = ClipToTouchScreen(framebuffer_x, framebuffer_y); | ||
| 88 | |||
| 89 | TouchPressed(framebuffer_x, framebuffer_y); | ||
| 90 | } | ||
| 91 | |||
| 92 | void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) { | ||
| 93 | Layout::FramebufferLayout layout; | ||
| 94 | switch (Settings::values.layout_option) { | ||
| 95 | case Settings::LayoutOption::SingleScreen: | ||
| 96 | layout = Layout::SingleFrameLayout(width, height, Settings::values.swap_screen); | ||
| 97 | break; | ||
| 98 | case Settings::LayoutOption::LargeScreen: | ||
| 99 | layout = Layout::LargeFrameLayout(width, height, Settings::values.swap_screen); | ||
| 100 | break; | ||
| 101 | case Settings::LayoutOption::Default: | ||
| 102 | default: | ||
| 103 | layout = Layout::DefaultFrameLayout(width, height, Settings::values.swap_screen); | ||
| 104 | break; | ||
| 105 | } | ||
| 106 | NotifyFramebufferLayoutChanged(layout); | ||
| 107 | } | ||