diff options
author | wwylele <wwylele@gmail.com> | 2016-12-11 22:32:41 +0100 |
---|---|---|
committer | wwylele <wwylele@gmail.com> | 2016-12-26 09:52:16 +0100 |
commit | bcf9d20d5713e7003792bb8fa740b19a7204920e (patch) | |
tree | a5fd21a9dd1587d8dedddc33a19b09490ceb164d /src/citra | |
parent | Common: add Quaternion (diff) | |
download | yuzu-bcf9d20d5713e7003792bb8fa740b19a7204920e.tar yuzu-bcf9d20d5713e7003792bb8fa740b19a7204920e.tar.gz yuzu-bcf9d20d5713e7003792bb8fa740b19a7204920e.tar.bz2 yuzu-bcf9d20d5713e7003792bb8fa740b19a7204920e.tar.lz yuzu-bcf9d20d5713e7003792bb8fa740b19a7204920e.tar.xz yuzu-bcf9d20d5713e7003792bb8fa740b19a7204920e.tar.zst yuzu-bcf9d20d5713e7003792bb8fa740b19a7204920e.zip |
Diffstat (limited to '')
-rw-r--r-- | src/citra/emu_window/emu_window_sdl2.cpp | 22 | ||||
-rw-r--r-- | src/citra/emu_window/emu_window_sdl2.h | 5 | ||||
-rw-r--r-- | src/citra_qt/bootmanager.cpp | 10 | ||||
-rw-r--r-- | src/citra_qt/bootmanager.h | 4 |
4 files changed, 33 insertions, 8 deletions
diff --git a/src/citra/emu_window/emu_window_sdl2.cpp b/src/citra/emu_window/emu_window_sdl2.cpp index b0d82b670..81a3abe3f 100644 --- a/src/citra/emu_window/emu_window_sdl2.cpp +++ b/src/citra/emu_window/emu_window_sdl2.cpp @@ -19,16 +19,22 @@ void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); + motion_emu->Tilt(x, y); } void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { - if (button != SDL_BUTTON_LEFT) - return; - - if (state == SDL_PRESSED) { - TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); - } else { - TouchReleased(); + if (button == SDL_BUTTON_LEFT) { + if (state == SDL_PRESSED) { + TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); + } else { + TouchReleased(); + } + } else if (button == SDL_BUTTON_RIGHT) { + if (state == SDL_PRESSED) { + motion_emu->BeginTilt(x, y); + } else { + motion_emu->EndTilt(); + } } } @@ -54,6 +60,7 @@ EmuWindow_SDL2::EmuWindow_SDL2() { keyboard_id = KeyMap::NewDeviceId(); ReloadSetKeymaps(); + motion_emu = std::make_unique<Motion::MotionEmu>(*this); SDL_SetMainReady(); @@ -109,6 +116,7 @@ EmuWindow_SDL2::EmuWindow_SDL2() { EmuWindow_SDL2::~EmuWindow_SDL2() { SDL_GL_DeleteContext(gl_context); SDL_Quit(); + motion_emu = nullptr; } void EmuWindow_SDL2::SwapBuffers() { diff --git a/src/citra/emu_window/emu_window_sdl2.h b/src/citra/emu_window/emu_window_sdl2.h index c8cd919c6..b1cbf16d7 100644 --- a/src/citra/emu_window/emu_window_sdl2.h +++ b/src/citra/emu_window/emu_window_sdl2.h @@ -4,8 +4,10 @@ #pragma once +#include <memory> #include <utility> #include "core/frontend/emu_window.h" +#include "core/frontend/motion_emu.h" struct SDL_Window; @@ -61,4 +63,7 @@ private: /// Device id of keyboard for use with KeyMap int keyboard_id; + + /// Motion sensors emulation + std::unique_ptr<Motion::MotionEmu> motion_emu; }; diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 57fde6caa..4ea332a9f 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -191,6 +191,7 @@ qreal GRenderWindow::windowPixelRatio() { } void GRenderWindow::closeEvent(QCloseEvent* event) { + motion_emu = nullptr; emit Closed(); QWidget::closeEvent(event); } @@ -204,11 +205,13 @@ void GRenderWindow::keyReleaseEvent(QKeyEvent* event) { } void GRenderWindow::mousePressEvent(QMouseEvent* event) { + auto pos = event->pos(); if (event->button() == Qt::LeftButton) { - auto pos = event->pos(); qreal pixelRatio = windowPixelRatio(); this->TouchPressed(static_cast<unsigned>(pos.x() * pixelRatio), static_cast<unsigned>(pos.y() * pixelRatio)); + } else if (event->button() == Qt::RightButton) { + motion_emu->BeginTilt(pos.x(), pos.y()); } } @@ -217,11 +220,14 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) { qreal pixelRatio = windowPixelRatio(); this->TouchMoved(std::max(static_cast<unsigned>(pos.x() * pixelRatio), 0u), std::max(static_cast<unsigned>(pos.y() * pixelRatio), 0u)); + motion_emu->Tilt(pos.x(), pos.y()); } void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) { if (event->button() == Qt::LeftButton) this->TouchReleased(); + else if (event->button() == Qt::RightButton) + motion_emu->EndTilt(); } void GRenderWindow::ReloadSetKeymaps() { @@ -279,11 +285,13 @@ void GRenderWindow::OnMinimalClientAreaChangeRequest( } void GRenderWindow::OnEmulationStarting(EmuThread* emu_thread) { + motion_emu = std::make_unique<Motion::MotionEmu>(*this); this->emu_thread = emu_thread; child->DisablePainting(); } void GRenderWindow::OnEmulationStopping() { + motion_emu = nullptr; emu_thread = nullptr; child->EnablePainting(); } diff --git a/src/citra_qt/bootmanager.h b/src/citra_qt/bootmanager.h index 43015390b..7dac1c480 100644 --- a/src/citra_qt/bootmanager.h +++ b/src/citra_qt/bootmanager.h @@ -11,6 +11,7 @@ #include <QThread> #include "common/thread.h" #include "core/frontend/emu_window.h" +#include "core/frontend/motion_emu.h" class QKeyEvent; class QScreen; @@ -156,6 +157,9 @@ private: EmuThread* emu_thread; + /// Motion sensors emulation + std::unique_ptr<Motion::MotionEmu> motion_emu; + protected: void showEvent(QShowEvent* event) override; }; |