Re: [hatari-devel] Little regression in hatari GUI filesystem in fullscreen mode ?

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi Laurent,

Attached is potential fix, can you verify it works for you?


The reason why it worked for you with 1.x Hatari version was that using SDL1 instead of SDL2 i.e. handling F11 *completely* differently.

SDL1 & Hatari version using it, changes monitor resolution. Whereas with SDL2, window buffer is scaled to current fullscreen resolution by SDL2 internally and mouse coordinates did not match what Hatari expected any more.

You'll see the same problem just by scaling Hatari window, there's no need to switch to fullscreen for it.


	- Eero

PS. I'm wondering why application needs to do mouse coordinate scaling instead of SDL2 doing that automatically for it. That seems really broken.

On 17.3.2024 13.52, Eero Tamminen wrote:
On 17.3.2024 11.12, Laurent Sallafranque wrote:
While testing hatari on some demos and games, I noticed I couldn't move the scrollbar by clicking on it and moving the mouse up/down into the fileselector GUI.

It works in windowed mode, but not in fullscreen mode.

Do you have the same behaviour ?

I do the test like this :

     -  F12 (to open the GUI)

     -  Click on "Floppy disks"

     -  Then I click "UP" 3 times until I reach a folder with more files than the screen

     -  Then I click on the slidebar and move the mouse up/down.

I've done a quick test with hatari 1.6.2 version, and it worked (but in fullscreen, hatari was displayed on my 2 screens ;)

Problem seems SDL2 event reporting, it does not scale the events it reports although it has internally scaled the output.

Hatari has some code for working around that, but it's not applied here (and potentially in few other places). I'm working on fix..

     - Eero

From 6b809759b94b6c4661fcf0e9bb4edcc92805a590 Mon Sep 17 00:00:00 2001
From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
Date: Sun, 17 Mar 2024 12:23:45 +0200
Subject: [PATCH] Fix fsel scrollbar mouse coords for scaled SDL2 windows

Apply same fix also to one missing place in SDLGui_DoDialogExt()
object finding.
---
 src/gui-sdl/dlgFileSelect.c |  1 +
 src/gui-sdl/sdlgui.c        | 31 +++++++++++++++++++++----------
 src/includes/sdlgui.h       |  1 +
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/src/gui-sdl/dlgFileSelect.c b/src/gui-sdl/dlgFileSelect.c
index fc1012e0..c402c805 100644
--- a/src/gui-sdl/dlgFileSelect.c
+++ b/src/gui-sdl/dlgFileSelect.c
@@ -303,6 +303,7 @@ static void DlgFileSelect_ManageScrollbar(void)
 	float scrollMove;
 
 	SDL_GetMouseState(&x, &y);
+	SDLGui_ScaleMouseStateCoordinates(&x, &y);
 
 	/* If mouse is down on the scrollbar for the first time */
 	if (fsdlg[SGFSDLG_SCROLLBAR].state & SG_MOUSEDOWN) {
diff --git a/src/gui-sdl/sdlgui.c b/src/gui-sdl/sdlgui.c
index fe867b17..bcc29ea3 100644
--- a/src/gui-sdl/sdlgui.c
+++ b/src/gui-sdl/sdlgui.c
@@ -1057,18 +1057,28 @@ static int SDLGui_HandleShortcut(SGOBJ *dlg, int key)
 }
 
 /**
- * Scale mouse coordinates in case we've got a re-sized SDL2 window
+ * Scale mouse state coordinates in case we've got a re-sized SDL2 window
  */
-static void SDLGui_ScaleMouseButtonCoordinates(SDL_MouseButtonEvent *bev)
+void SDLGui_ScaleMouseStateCoordinates(int *x, int *y)
 {
 	int win_width, win_height;
+	SDL_GetWindowSize(sdlWindow, &win_width, &win_height);
+
+	*x = *x * pSdlGuiScrn->w / win_width;
+	*y = *y * pSdlGuiScrn->h / win_height;
+}
 
+/**
+ * Scale mouse event coordinates in case we've got a re-sized SDL2 window
+ */
+static void SDLGui_ScaleMouseButtonCoordinates(SDL_MouseButtonEvent *bev)
+{
 	if (bInFullScreen)
 		return;
 
-	SDL_GetWindowSize(sdlWindow, &win_width, &win_height);
-	bev->x = bev->x * pSdlGuiScrn->w / win_width;
-	bev->y = bev->y * pSdlGuiScrn->h / win_height;
+	int x = bev->x, y = bev->y;
+	SDLGui_ScaleMouseStateCoordinates(&x, &y);
+	bev->x = x; bev->y = y;
 }
 
 /*-----------------------------------------------------------------------*/
@@ -1093,7 +1103,7 @@ int SDLGui_DoDialogExt(SGOBJ *dlg, bool (*isEventOut)(SDL_EventType), SDL_Event
 {
 	int oldbutton = SDLGUI_NOTFOUND;
 	int retbutton = SDLGUI_NOTFOUND;
-	int i, j, b, value, obj;
+	int b, x, y, value, obj;
 	SDL_Keycode key;
 	int focused;
 	SDL_Event sdlEvent;
@@ -1156,7 +1166,7 @@ int SDLGui_DoDialogExt(SGOBJ *dlg, bool (*isEventOut)(SDL_EventType), SDL_Event
 
 	/* Is the left mouse button still pressed? Yes -> Handle TOUCHEXIT objects here */
 	SDL_PumpEvents();
-	b = SDL_GetMouseState(&i, &j);
+	b = SDL_GetMouseState(&x, &y);
 
 	/* If current object is the scrollbar, and mouse is still down, we can scroll it */
 	/* also if the mouse pointer has left the scrollbar */
@@ -1172,9 +1182,10 @@ int SDLGui_DoDialogExt(SGOBJ *dlg, bool (*isEventOut)(SDL_EventType), SDL_Event
 		{
 			dlg[obj].state &= ~SG_MOUSEDOWN;
 		}
-	}
-	else {
-		obj = SDLGui_FindObj(dlg, i, j);
+	} else {
+		SDLGui_ScaleMouseStateCoordinates(&x, &y);
+		obj = SDLGui_FindObj(dlg, x, y);
+
 		current_object = obj;
 		if (obj != SDLGUI_NOTFOUND && (dlg[obj].flags&SG_TOUCHEXIT) )
 		{
diff --git a/src/includes/sdlgui.h b/src/includes/sdlgui.h
index 464f25c6..3ff3b5ab 100644
--- a/src/includes/sdlgui.h
+++ b/src/includes/sdlgui.h
@@ -80,6 +80,7 @@ extern int SDLGui_SetScreen(SDL_Surface *pScrn);
 extern void SDLGui_GetFontSize(int *width, int *height);
 extern void SDLGui_Text(int x, int y, const char *txt);
 extern void SDLGui_DrawDialog(const SGOBJ *dlg);
+extern void SDLGui_ScaleMouseStateCoordinates(int *x, int *y);
 extern int SDLGui_DoDialogExt(SGOBJ *dlg, bool (*isEventOut)(SDL_EventType), SDL_Event *pEventOut, int current_object);
 extern int SDLGui_DoDialog(SGOBJ *dlg);
 extern void SDLGui_CenterDlg(SGOBJ *dlg);
-- 
2.39.2



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/