Skip to content

Commit

Permalink
SDL2: restore popping down menu for mouse press outside the menu
Browse files Browse the repository at this point in the history
Addresses Ituirth's report here, https://angband.live/forums/forum/angband/vanilla/10748-proposed-changes-for-sdl2?p=248258#post248258 .  That's a regression introduced by d8518ad36119589cd966e18615881fcec0be1300 .
  • Loading branch information
backwardsEric authored and NickMcConnell committed Jan 21, 2024
1 parent 8be3c34 commit eb3d501
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 43 deletions.
24 changes: 21 additions & 3 deletions src/main-sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3533,10 +3533,28 @@ static bool handle_mousebutton(struct my_app *a,
}

/* Have a menu or dialog handle the event if appropriate. */
if (a->w_mouse->d_mouse && a->w_mouse->d_mouse->ftb->handle_mouseclick
&& (*a->w_mouse->d_mouse->ftb->handle_mouseclick)(
if (a->w_mouse->d_mouse) {
/*
* Press events outside of the dialog will act as if the dialog
* lost mouse focus to another unknown dialog. Do not do the
* same for release events in case the press happens in a
* dialog, followed by mouse motion, and then the release
* happens outside the dialog.
*/
if (mouse->state == SDL_PRESSED && !sdlpui_is_in_dialog(
a->w_mouse->d_mouse, mouse->x, mouse->y)) {
if (a->w_mouse->d_mouse->ftb->handle_loses_mouse) {
(*a->w_mouse->d_mouse->ftb->handle_loses_mouse)(
a->w_mouse->d_mouse, a->w_mouse,
NULL, NULL);
}
return true;
}
if (a->w_mouse->d_mouse->ftb->handle_mouseclick
&& (*a->w_mouse->d_mouse->ftb->handle_mouseclick)(
a->w_mouse->d_mouse, a->w_mouse, mouse)) {
return true;
return true;
}
}

/* Otherwise only react to the button press and not the release. */
Expand Down
39 changes: 3 additions & 36 deletions src/sdl2/pui-dlg.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static const struct sdlpui_dialog_funcs simple_menu_funcs = {
handle_simple_menu_key,
handle_simple_menu_textin,
sdlpui_dialog_handle_textedit,
sdlpui_menu_handle_mouseclick,
sdlpui_dialog_handle_mouseclick,
sdlpui_dialog_handle_mousemove,
sdlpui_dialog_handle_mousewheel,
sdlpui_menu_handle_loses_mouse,
Expand Down Expand Up @@ -1478,7 +1478,7 @@ bool sdlpui_dialog_handle_textedit(struct sdlpui_dialog *d,


/**
* Perform basic handling of a mouse button event for a dialog.
* Perform basic handling of a mouse button event for a dialog or menu.
*
* \param d is the dialog.
* \param w is the window containing the dialog.
Expand All @@ -1501,40 +1501,7 @@ bool sdlpui_dialog_handle_mouseclick(struct sdlpui_dialog *d,
}


/**
* Perform basic handling of a mouse button event for a menu.
*
* \param d is the menu.
* \param w is the window containing the menu.
* \param e is the event to handle.
* \return true if the event is handled and doesn't need further processing by
* the window; otherwise return false.
*/
bool sdlpui_menu_handle_mouseclick(struct sdlpui_dialog *d,
struct sdlpui_window *w, const struct SDL_MouseButtonEvent *e)
{
/* Relay to the control with focus. If it handles it, we are done. */
if (d->c_mouse && d->c_mouse->ftb->handle_mouseclick
&& (*d->c_mouse->ftb->handle_mouseclick)(
d->c_mouse, d, w, e)) {
return true;
}

/*
* Button events while the mouse is outside the menu will act as if
* the menu lost mouse focus to another unknown dialog.
*/
if (!sdlpui_is_in_dialog(d, e->x, e->y)) {
sdlpui_menu_handle_loses_mouse(d, w, NULL, NULL);
return true;
}

/* Do nothing and swallow the event. */
return true;
}


/**
/*
* Perform basic handling of a mouse motion event for a menu or dialog.
*
* \param d is the menu or dialog.
Expand Down
4 changes: 0 additions & 4 deletions src/sdl2/pui-dlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,8 @@ bool sdlpui_dialog_handle_textedit(struct sdlpui_dialog *d,
struct sdlpui_window *w, const struct SDL_TextEditingEvent *e);
bool sdlpui_dialog_handle_mouseclick(struct sdlpui_dialog *d,
struct sdlpui_window *w, const struct SDL_MouseButtonEvent *e);
bool sdlpui_menu_handle_mouseclick(struct sdlpui_dialog *d,
struct sdlpui_window *w, const struct SDL_MouseButtonEvent *e);
bool sdlpui_dialog_handle_mousemove(struct sdlpui_dialog *d,
struct sdlpui_window *w, const struct SDL_MouseMotionEvent *e);
bool sdlpui_menu_handle_mousemove(struct sdlpui_dialog *d,
struct sdlpui_window *w, const struct SDL_MouseMotionEvent *e);
bool sdlpui_dialog_handle_mousewheel(struct sdlpui_dialog *d,
struct sdlpui_window *w, const struct SDL_MouseWheelEvent *e);
void sdlpui_dismiss_dialog(struct sdlpui_dialog *d, struct sdlpui_window *w);
Expand Down

0 comments on commit eb3d501

Please sign in to comment.