summaryrefslogtreecommitdiffstats
path: root/src/yuzu_cmd
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
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')
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp48
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.h12
2 files changed, 58 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;
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.h b/src/yuzu_cmd/emu_window/emu_window_sdl2.h
index d34902109..b0d4116cc 100644
--- a/src/yuzu_cmd/emu_window/emu_window_sdl2.h
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.h
@@ -40,6 +40,18 @@ private:
/// Called by PollEvents when a mouse button is pressed or released
void OnMouseButton(u32 button, u8 state, s32 x, s32 y);
+ /// Translates pixel position (0..1) to pixel positions
+ std::pair<unsigned, unsigned> TouchToPixelPos(float touch_x, float touch_y) const;
+
+ /// Called by PollEvents when a finger starts touching the touchscreen
+ void OnFingerDown(float x, float y);
+
+ /// Called by PollEvents when a finger moves while touching the touchscreen
+ void OnFingerMotion(float x, float y);
+
+ /// Called by PollEvents when a finger stops touching the touchscreen
+ void OnFingerUp();
+
/// Called by PollEvents when any event that may cause the window to be resized occurs
void OnResize();