Skip to content

Commit

Permalink
Allow dragging sliders with the mouse
Browse files Browse the repository at this point in the history
Additional code was introduced to handle edge cases. Sliders are always
dimmed when clicked with the mouse, now. When the mouse button is
release, dimmed mode is turned off. This was done to prevent adjacent
slider items from being accidentally modified by moving the mouse over
them with the left mouse button held down, as well as to allow proper
functioning of deferred sliders with the mouse.
  • Loading branch information
ZenithMDC committed Dec 6, 2024
1 parent 23d3465 commit c8baaa6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
17 changes: 17 additions & 0 deletions src/game/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ s32 g_MpPlayerNum = 0;
#ifndef PLATFORM_N64
s32 g_MenuMouseControl = true;
s32 g_MenuUsingMouse = false;
s32 g_AllowMouseHeld = true;
s32 g_MouseDimmedMode = false;
#endif

void menuPlaySound(s32 menusound)
Expand Down Expand Up @@ -1507,6 +1509,12 @@ void menuOpenDialog(struct menudialogdef *dialogdef, struct menudialog *dialog,

void menuPushDialog(struct menudialogdef *dialogdef)
{
#ifndef PLATFORM_N64
// Prevent the mouse from immediately changing a slider's value, as was
// happening while entering the Audio menu.
g_AllowMouseHeld = false;
#endif

if (dialogdef) {
menuUnsetModel(&g_Menus[g_MpPlayerNum].menumodel);

Expand Down Expand Up @@ -4695,6 +4703,7 @@ void menuProcessInput(void)
inputs.back2 = 0;

#ifndef PLATFORM_N64
inputs.mouseheld = false;
inputs.mousemoved = false;
inputs.mousescroll = 0;
inputs.mousex = 0;
Expand All @@ -4704,6 +4713,14 @@ void menuProcessInput(void)
// ESC always acts as back
inputs.back = inputKeyJustPressed(VK_ESCAPE);
if (inputMouseIsEnabled() && !inputMouseIsLocked() && g_MenuMouseControl) {
inputs.mouseheld = inputKeyPressed(VK_MOUSE_LEFT);
if (!inputs.mouseheld) {
g_AllowMouseHeld = true;
if (g_MouseDimmedMode) {
g_MouseDimmedMode = false;
dialog->dimmed = false;
}
}
inputs.mousescroll = inputKeyPressed(VK_MOUSE_WHEEL_DN) - inputKeyPressed(VK_MOUSE_WHEEL_UP);
inputs.mousemoved = inputMouseGetPosition(&inputs.mousex, &inputs.mousey) || inputs.mousescroll;
// aspect correct the X
Expand Down
30 changes: 17 additions & 13 deletions src/game/menuitem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2455,7 +2455,7 @@ bool menuitemSliderTick(struct menuitem *item, struct menudialog *dialog, struct

if ((tickflags & MENUTICKFLAG_ITEMISFOCUSED)) {
#ifndef PLATFORM_N64
if (g_MenuUsingMouse && inputs->select) {
if (g_AllowMouseHeld && g_MenuUsingMouse && (inputs->select || inputs->mouseheld)) {
// handle mouse
struct menudialog *dialog = g_Menus[g_MpPlayerNum].curdialog;
if (dialog) {
Expand All @@ -2464,19 +2464,23 @@ bool menuitemSliderTick(struct menuitem *item, struct menudialog *dialog, struct
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);
if ((tickflags & MENUTICKFLAG_DIALOGISDIMMED) == 0) {
g_MouseDimmedMode = true;
} else {
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;
}
return true;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ extern const struct weathercfg g_DefaultWeatherConfig;
extern const struct weathercfg *g_CurWeatherConfig;

extern s32 g_MenuUsingMouse;
extern s32 g_AllowMouseHeld;
extern s32 g_MouseDimmedMode;

extern f32 g_ViShakeIntensityMult;
extern u32 g_TexFilter2D;
Expand Down
5 changes: 3 additions & 2 deletions src/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -4996,8 +4996,9 @@ struct menuinputs {
/*0x10*/ s32 unk10;
/*0x14*/ u8 unk14;
#ifndef PLATFORM_N64
/*0x15*/ u8 mousemoved;
/*0x16*/ s8 mousescroll;
/*0x15*/ u8 mouseheld;
/*0x16*/ u8 mousemoved;
/*0x17*/ s8 mousescroll;
/*0x18*/ s32 mousex;
/*0x1c*/ s32 mousey;
#endif
Expand Down

0 comments on commit c8baaa6

Please sign in to comment.