forked from suyu/suyu
yuzu_cmd: Use new input
This commit is contained in:
parent
737d305f63
commit
14b949a0da
3 changed files with 39 additions and 45 deletions
|
@ -9,10 +9,10 @@
|
|||
#include "common/settings.h"
|
||||
#include "core/core.h"
|
||||
#include "core/perf_stats.h"
|
||||
#include "input_common/keyboard.h"
|
||||
#include "input_common/drivers/keyboard.h"
|
||||
#include "input_common/drivers/mouse.h"
|
||||
#include "input_common/drivers/touch_screen.h"
|
||||
#include "input_common/main.h"
|
||||
#include "input_common/mouse/mouse_input.h"
|
||||
#include "input_common/sdl/sdl.h"
|
||||
#include "yuzu_cmd/emu_window/emu_window_sdl2.h"
|
||||
#include "yuzu_cmd/yuzu_icon.h"
|
||||
|
||||
|
@ -32,42 +32,32 @@ EmuWindow_SDL2::~EmuWindow_SDL2() {
|
|||
}
|
||||
|
||||
void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) {
|
||||
TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0), 0);
|
||||
|
||||
input_subsystem->GetMouse()->MouseMove(x, y, 0, 0);
|
||||
input_subsystem->GetMouse()->MouseMove(x, y, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
MouseInput::MouseButton EmuWindow_SDL2::SDLButtonToMouseButton(u32 button) const {
|
||||
InputCommon::MouseButton EmuWindow_SDL2::SDLButtonToMouseButton(u32 button) const {
|
||||
switch (button) {
|
||||
case SDL_BUTTON_LEFT:
|
||||
return MouseInput::MouseButton::Left;
|
||||
return InputCommon::MouseButton::Left;
|
||||
case SDL_BUTTON_RIGHT:
|
||||
return MouseInput::MouseButton::Right;
|
||||
return InputCommon::MouseButton::Right;
|
||||
case SDL_BUTTON_MIDDLE:
|
||||
return MouseInput::MouseButton::Wheel;
|
||||
return InputCommon::MouseButton::Wheel;
|
||||
case SDL_BUTTON_X1:
|
||||
return MouseInput::MouseButton::Backward;
|
||||
return InputCommon::MouseButton::Backward;
|
||||
case SDL_BUTTON_X2:
|
||||
return MouseInput::MouseButton::Forward;
|
||||
return InputCommon::MouseButton::Forward;
|
||||
default:
|
||||
return MouseInput::MouseButton::Undefined;
|
||||
return InputCommon::MouseButton::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {
|
||||
const auto mouse_button = SDLButtonToMouseButton(button);
|
||||
if (button == SDL_BUTTON_LEFT) {
|
||||
if (state == SDL_PRESSED) {
|
||||
TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0), 0);
|
||||
} else {
|
||||
TouchReleased(0);
|
||||
}
|
||||
if (state == SDL_PRESSED) {
|
||||
input_subsystem->GetMouse()->PressButton(x, y, 0, 0, mouse_button);
|
||||
} else {
|
||||
if (state == SDL_PRESSED) {
|
||||
input_subsystem->GetMouse()->PressButton(x, y, mouse_button);
|
||||
} else {
|
||||
input_subsystem->GetMouse()->ReleaseButton(mouse_button);
|
||||
}
|
||||
input_subsystem->GetMouse()->ReleaseButton(mouse_button);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,29 +72,35 @@ std::pair<unsigned, unsigned> EmuWindow_SDL2::TouchToPixelPos(float touch_x, flo
|
|||
static_cast<unsigned>(std::max(std::round(touch_y), 0.0f))};
|
||||
}
|
||||
|
||||
void EmuWindow_SDL2::OnFingerDown(float x, float y) {
|
||||
// TODO(NeatNit): keep track of multitouch using the fingerID and a dictionary of some kind
|
||||
// This isn't critical because the best we can do when we have that is to average them, like the
|
||||
// 3DS does
|
||||
|
||||
void EmuWindow_SDL2::OnFingerDown(float x, float y, std::size_t id) {
|
||||
int width, height;
|
||||
SDL_GetWindowSize(render_window, &width, &height);
|
||||
const auto [px, py] = TouchToPixelPos(x, y);
|
||||
TouchPressed(px, py, 0);
|
||||
const float fx = px * 1.0f / width;
|
||||
const float fy = py * 1.0f / height;
|
||||
|
||||
input_subsystem->GetTouchScreen()->TouchPressed(fx, fy, id);
|
||||
}
|
||||
|
||||
void EmuWindow_SDL2::OnFingerMotion(float x, float y) {
|
||||
void EmuWindow_SDL2::OnFingerMotion(float x, float y, std::size_t id) {
|
||||
int width, height;
|
||||
SDL_GetWindowSize(render_window, &width, &height);
|
||||
const auto [px, py] = TouchToPixelPos(x, y);
|
||||
TouchMoved(px, py, 0);
|
||||
const float fx = px * 1.0f / width;
|
||||
const float fy = py * 1.0f / height;
|
||||
|
||||
input_subsystem->GetTouchScreen()->TouchMoved(fx, fy, id);
|
||||
}
|
||||
|
||||
void EmuWindow_SDL2::OnFingerUp() {
|
||||
TouchReleased(0);
|
||||
input_subsystem->GetTouchScreen()->TouchReleased(0);
|
||||
}
|
||||
|
||||
void EmuWindow_SDL2::OnKeyEvent(int key, u8 state) {
|
||||
if (state == SDL_PRESSED) {
|
||||
input_subsystem->GetKeyboard()->PressKey(key);
|
||||
input_subsystem->GetKeyboard()->PressKey(static_cast<std::size_t>(key));
|
||||
} else if (state == SDL_RELEASED) {
|
||||
input_subsystem->GetKeyboard()->ReleaseKey(key);
|
||||
input_subsystem->GetKeyboard()->ReleaseKey(static_cast<std::size_t>(key));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,10 +201,12 @@ void EmuWindow_SDL2::WaitEvent() {
|
|||
}
|
||||
break;
|
||||
case SDL_FINGERDOWN:
|
||||
OnFingerDown(event.tfinger.x, event.tfinger.y);
|
||||
OnFingerDown(event.tfinger.x, event.tfinger.y,
|
||||
static_cast<std::size_t>(event.tfinger.touchId));
|
||||
break;
|
||||
case SDL_FINGERMOTION:
|
||||
OnFingerMotion(event.tfinger.x, event.tfinger.y);
|
||||
OnFingerMotion(event.tfinger.x, event.tfinger.y,
|
||||
static_cast<std::size_t>(event.tfinger.touchId));
|
||||
break;
|
||||
case SDL_FINGERUP:
|
||||
OnFingerUp();
|
||||
|
|
|
@ -16,11 +16,8 @@ class System;
|
|||
|
||||
namespace InputCommon {
|
||||
class InputSubsystem;
|
||||
}
|
||||
|
||||
namespace MouseInput {
|
||||
enum class MouseButton;
|
||||
}
|
||||
} // namespace InputCommon
|
||||
|
||||
class EmuWindow_SDL2 : public Core::Frontend::EmuWindow {
|
||||
public:
|
||||
|
@ -47,7 +44,7 @@ protected:
|
|||
void OnMouseMotion(s32 x, s32 y);
|
||||
|
||||
/// Converts a SDL mouse button into MouseInput mouse button
|
||||
MouseInput::MouseButton SDLButtonToMouseButton(u32 button) const;
|
||||
InputCommon::MouseButton SDLButtonToMouseButton(u32 button) const;
|
||||
|
||||
/// Called by WaitEvent when a mouse button is pressed or released
|
||||
void OnMouseButton(u32 button, u8 state, s32 x, s32 y);
|
||||
|
@ -56,10 +53,10 @@ protected:
|
|||
std::pair<unsigned, unsigned> TouchToPixelPos(float touch_x, float touch_y) const;
|
||||
|
||||
/// Called by WaitEvent when a finger starts touching the touchscreen
|
||||
void OnFingerDown(float x, float y);
|
||||
void OnFingerDown(float x, float y, std::size_t id);
|
||||
|
||||
/// Called by WaitEvent when a finger moves while touching the touchscreen
|
||||
void OnFingerMotion(float x, float y);
|
||||
void OnFingerMotion(float x, float y, std::size_t id);
|
||||
|
||||
/// Called by WaitEvent when a finger stops touching the touchscreen
|
||||
void OnFingerUp();
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "common/settings.h"
|
||||
#include "common/string_util.h"
|
||||
#include "core/core.h"
|
||||
#include "input_common/keyboard.h"
|
||||
#include "input_common/main.h"
|
||||
#include "video_core/renderer_base.h"
|
||||
#include "yuzu_cmd/emu_window/emu_window_sdl2_gl.h"
|
||||
|
|
Loading…
Reference in a new issue