From a6e7d503e6fac76a267c7e0dc5cc3b255a9ca976 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Tue, 14 May 2024 23:16:36 +0200 Subject: [PATCH] port: add mouse controls to sliders --- src/game/menuitem.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/game/menuitem.c b/src/game/menuitem.c index d64706f15..27e1f0353 100644 --- a/src/game/menuitem.c +++ b/src/game/menuitem.c @@ -2454,6 +2454,34 @@ bool menuitemSliderTick(struct menuitem *item, struct menudialog *dialog, struct f32 f14; if ((tickflags & MENUTICKFLAG_ITEMISFOCUSED)) { +#ifndef PLATFORM_N64 + if (g_MenuUsingMouse && inputs->select) { + // handle mouse + struct menudialog *dialog = g_Menus[g_MpPlayerNum].curdialog; + if (dialog) { + const s32 left = dialog->x + dialog->width - 82; + const s32 right = dialog->x + dialog->width - 7; + const s32 size = right - left; + const s32 delta = inputs->mousex - left; + if (delta >= -8 && delta <= size + 8) { + index = (delta / (f32)size) * item->param3; + if (index < 0) { + index = 0; + } + if (index > item->param3) { + index = item->param3; + } + if (item->handler) { + item->handler(MENUOP_GET, item, &handlerdata); + handlerdata.slider.value = index; + item->handler(MENUOP_SET, item, &handlerdata); + } + return true; + } + } + } +#endif + if (tickflags & MENUTICKFLAG_DIALOGISDIMMED) { if (item->handler) { item->handler(MENUOP_GETSLIDER, item, &handlerdata);