summaryrefslogtreecommitdiffstats
path: root/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
diff options
context:
space:
mode:
authorNeatNit <neatnit@gmail.com>2018-10-01 21:42:49 +0200
committerfearlessTobi <thm.frey@gmail.com>2018-10-09 20:26:57 +0200
commit4f24343f32ed253efb2cedba03d20c620841dca1 (patch)
tree1fffd231c45fa4681c0a20c682c3ba5f7946c27c /src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
parentMerge pull request #1423 from DarkLordZach/romfs-file-exts (diff)
downloadyuzu-4f24343f32ed253efb2cedba03d20c620841dca1.tar
yuzu-4f24343f32ed253efb2cedba03d20c620841dca1.tar.gz
yuzu-4f24343f32ed253efb2cedba03d20c620841dca1.tar.bz2
yuzu-4f24343f32ed253efb2cedba03d20c620841dca1.tar.lz
yuzu-4f24343f32ed253efb2cedba03d20c620841dca1.tar.xz
yuzu-4f24343f32ed253efb2cedba03d20c620841dca1.tar.zst
yuzu-4f24343f32ed253efb2cedba03d20c620841dca1.zip
Diffstat (limited to 'src/yuzu_cmd/emu_window/emu_window_sdl2.cpp')
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
index 155095095..a9ad92a80 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
@@ -40,6 +40,35 @@ void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {
}
}
+std::pair<unsigned, unsigned> EmuWindow_SDL2::TouchToPixelPos(float touch_x, float touch_y) const {
+ int w, h;
+ SDL_GetWindowSize(render_window, &w, &h);
+
+ touch_x *= w;
+ touch_y *= h;
+
+ return {static_cast<unsigned>(std::max(std::round(touch_x), 0.0f)),
+ 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
+
+ const auto [px, py] = TouchToPixelPos(x, y);
+ TouchPressed(px, py);
+}
+
+void EmuWindow_SDL2::OnFingerMotion(float x, float y) {
+ const auto [px, py] = TouchToPixelPos(x, y);
+ TouchMoved(px, py);
+}
+
+void EmuWindow_SDL2::OnFingerUp() {
+ TouchReleased();
+}
+
void EmuWindow_SDL2::OnKeyEvent(int key, u8 state) {
if (state == SDL_PRESSED) {
InputCommon::GetKeyboard()->PressKey(key);
@@ -219,11 +248,26 @@ void EmuWindow_SDL2::PollEvents() {
OnKeyEvent(static_cast<int>(event.key.keysym.scancode), event.key.state);
break;
case SDL_MOUSEMOTION:
- OnMouseMotion(event.motion.x, event.motion.y);
+ // ignore if it came from touch
+ if (event.button.which != SDL_TOUCH_MOUSEID)
+ OnMouseMotion(event.motion.x, event.motion.y);
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
- OnMouseButton(event.button.button, event.button.state, event.button.x, event.button.y);
+ // ignore if it came from touch
+ if (event.button.which != SDL_TOUCH_MOUSEID) {
+ OnMouseButton(event.button.button, event.button.state, event.button.x,
+ event.button.y);
+ }
+ break;
+ case SDL_FINGERDOWN:
+ OnFingerDown(event.tfinger.x, event.tfinger.y);
+ break;
+ case SDL_FINGERMOTION:
+ OnFingerMotion(event.tfinger.x, event.tfinger.y);
+ break;
+ case SDL_FINGERUP:
+ OnFingerUp();
break;
case SDL_QUIT:
is_open = false;