From a2c6a789add62c52b993024cc9bade1b36f2797e Mon Sep 17 00:00:00 2001 From: rofl0r Date: Mon, 25 Oct 2021 01:02:04 +0000 Subject: [PATCH] cli frontend: fix mouse input there were 2 logical issues which caused reproducible misbehaviour. for example when starting up pokemon soulsilver, one can click away the intro, but it's not possible to click on the "load savegame" icon. the issues were: 1) failure to record whether the down event has been passed to the emulator before abandoning it and turning it into a click event (on a fast click, both events would happen during the same SDL_Pollevent loop), and 2) mouse coordinates were discarded and unless the mouse down event was registered. that means if the down and up events happen on the exact same coordinate, the .x and .y of the mouse weren't updated at all. --- desmume/src/frontend/posix/cli/main.cpp | 7 +++++-- desmume/src/frontend/posix/shared/ctrlssdl.cpp | 16 ++++++++-------- desmume/src/frontend/posix/shared/ctrlssdl.h | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/desmume/src/frontend/posix/cli/main.cpp b/desmume/src/frontend/posix/cli/main.cpp index c47213c3b..d8117b4ce 100644 --- a/desmume/src/frontend/posix/cli/main.cpp +++ b/desmume/src/frontend/posix/cli/main.cpp @@ -481,11 +481,14 @@ static void desmume_cycle(struct ctrls_event_config * cfg) } /* Update mouse position and click */ - if(mouse.down) NDS_setTouchPos(mouse.x, mouse.y); + if(mouse.down) { + NDS_setTouchPos(mouse.x, mouse.y); + mouse.down = 2; + } if(mouse.click) { NDS_releaseTouch(); - mouse.click = FALSE; + mouse.click = 0; } update_keypad(cfg->keypad); /* Update keypad */ diff --git a/desmume/src/frontend/posix/shared/ctrlssdl.cpp b/desmume/src/frontend/posix/shared/ctrlssdl.cpp index 09e8fdf26..febf08e27 100644 --- a/desmume/src/frontend/posix/shared/ctrlssdl.cpp +++ b/desmume/src/frontend/posix/shared/ctrlssdl.cpp @@ -576,14 +576,12 @@ process_ctrls_event( SDL_Event& event, break; case SDL_MOUSEBUTTONDOWN: - if(event.button.button==1) - mouse.down = TRUE; + if(event.button.button==1 && !mouse.down) + mouse.down = 1; break; - + case SDL_MOUSEMOTION: - if(!mouse.down) - break; - else { + { signed long scaled_x = screen_to_touch_range( event.button.x, cfg->nds_screen_size_ratio); @@ -597,8 +595,10 @@ process_ctrls_event( SDL_Event& event, break; case SDL_MOUSEBUTTONUP: - if(mouse.down) mouse.click = TRUE; - mouse.down = FALSE; + if(mouse.down) { + mouse.click = 1; + if(mouse.down > 1) mouse.down = 0; + } break; case SDL_QUIT: diff --git a/desmume/src/frontend/posix/shared/ctrlssdl.h b/desmume/src/frontend/posix/shared/ctrlssdl.h index 466bc6c9d..1903ee58f 100644 --- a/desmume/src/frontend/posix/shared/ctrlssdl.h +++ b/desmume/src/frontend/posix/shared/ctrlssdl.h @@ -75,8 +75,8 @@ struct mouse_status { signed long x; signed long y; - BOOL click; - BOOL down; + int click; + int down; }; extern mouse_status mouse;