Allow dragging sliders with the mouse

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.
This commit is contained in:
Matthew Coppola committed 2025-02-24 00:05:51 -05:00
1 parent a9752198c3
commit ea464ca6ac
4 files changed
+46 -20

No files matched your search

+18
View File
@@ -142,6 +142,9 @@ s32 g_MpPlayerNum = 0;
s32 g_MenuMouseControl = true;
s32 g_MenuUsingMouse = false;
s32 g_MenuKeyboardPlayer = -1;
s32 g_AllowMouseHeld = true;
s32 g_MouseDimmedMode = false;
s32 g_MouseEndDeferredSlider = false;
#endif
void menuPlaySound(s32 menusound)
@@ -1512,6 +1515,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);
@@ -4700,6 +4709,7 @@ void menuProcessInput(void)
inputs.back2 = 0;
#ifndef PLATFORM_N64
inputs.mouseheld = false;
inputs.mousemoved = false;
inputs.mousescroll = 0;
inputs.mousex = 0;
@@ -4709,6 +4719,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;
g_MouseEndDeferredSlider = true;
}
}
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
+22 -18
View File
@@ -2559,7 +2559,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) {
@@ -2568,24 +2568,27 @@ 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) {
if ((item->flags & MENUITEMFLAG_SLIDER_DEFERRED) &&
(tickflags & MENUTICKFLAG_DIALOGISDIMMED)) {
deferredindex = index;
} else {
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) {
if (item->flags & MENUITEMFLAG_SLIDER_DEFERRED) {
deferredindex = index;
} else {
item->handler(MENUOP_GET, item, &handlerdata);
handlerdata.slider.value = index;
item->handler(MENUOP_SET, item, &handlerdata);
}
}
return true;
}
return true;
}
}
}
@@ -2702,7 +2705,8 @@ bool menuitemSliderTick(struct menuitem *item, struct menudialog *dialog, struct
}
}
if (inputs->select) {
if (inputs->select || g_MouseEndDeferredSlider) {
g_MouseEndDeferredSlider = false;
if (item->flags & MENUITEMFLAG_SLIDER_DEFERRED) {
deferredindex = -1;
if (item->handler) {
+3
View File
@@ -539,6 +539,9 @@ extern const struct weathercfg *g_CurWeatherConfig;
extern s32 g_MenuUsingMouse;
extern s32 g_MenuKeyboardPlayer;
extern s32 g_AllowMouseHeld;
extern s32 g_MouseDimmedMode;
extern s32 g_MouseEndDeferredSlider;
extern f32 g_ViShakeIntensityMult;
extern u32 g_TexFilter2D;
+3 -2
View File
@@ -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