From 85872d7e715e49c4995fb66cf045c227a0fed965 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Tue, 14 May 2024 20:58:51 +0200 Subject: [PATCH] port: add mouse controls to virtual keyboard --- src/game/menuitem.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/game/menuitem.c b/src/game/menuitem.c index 117d92bd4..6f585b75b 100644 --- a/src/game/menuitem.c +++ b/src/game/menuitem.c @@ -1366,6 +1366,34 @@ bool menuitemKeyboardTick(struct menuitem *item, struct menuinputs *inputs, u32 s16 prevcol = kb->col; s16 prevrow = kb->row; +#ifndef PLATFORM_N64 + // handle mouse + struct menudialog *dialog = g_Menus[g_MpPlayerNum].curdialog; + if (dialog && dialog->usingmouse && !inputs->leftright && !inputs->updown) { + const s32 dleft = dialog->x + 4; + const s32 dright = dleft + 12 * 10; + const s32 dtop = dialog->y + 13 + 12; + const s32 dbottom = dtop + 11 * 5; + const s32 mx = inputs->mousex; + const s32 my = inputs->mousey; + if (mx > dleft && mx < dright && my > dtop && my < dbottom) { + kb->row = (my - dtop) / 11; + kb->col = (mx - dleft) / 12; + if (kb->row == 4) { + if (kb->col < 2) { + kb->col = 0; + } else if (kb->col < 5) { + kb->col = 2; + } else if (kb->col < 8) { + kb->col = 5; + } else { + kb->col = 8; + } + } + } + } +#endif + // Handle left/right movement // In most cases the loop only runs once, but on row 4 the buttons span // across multiple columns so the loop will run again until the column