Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.5] Add scroll wheel support to keymapper #7648

Merged
merged 4 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Source/DiabloUI/settingsmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,19 @@ void UiSettingsMenu()
break;
}
break;
#if SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_MOUSEWHEEL:
if (event.wheel.y > 0) {
key = MouseScrollUpButton;
} else if (event.wheel.y < 0) {
key = MouseScrollDownButton;
} else if (event.wheel.x > 0) {
key = MouseScrollLeftButton;
} else if (event.wheel.x < 0) {
key = MouseScrollRightButton;
}
break;
#endif
}
// Ignore unknown keys
if (key == SDLK_UNKNOWN)
Expand Down
37 changes: 37 additions & 0 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,43 @@ void GameEventHandler(const SDL_Event &event, uint16_t modState)
MousePosition = { event.button.x, event.button.y };
HandleMouseButtonUp(event.button.button, modState);
return;
#if SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_MOUSEWHEEL:
if (event.wheel.y > 0) { // Up
if (stextflag != TalkID::None) {
StoreUp();
} else if (QuestLogIsOpen) {
QuestlogUp();
} else if (HelpFlag) {
HelpScrollUp();
} else if (ChatLogFlag) {
ChatLogScrollUp();
} else if (IsStashOpen) {
Stash.PreviousPage();
} else {
sgOptions.Keymapper.KeyPressed(MouseScrollUpButton);
}
} else if (event.wheel.y < 0) { // down
if (stextflag != TalkID::None) {
StoreDown();
} else if (QuestLogIsOpen) {
QuestlogDown();
} else if (HelpFlag) {
HelpScrollDown();
} else if (ChatLogFlag) {
ChatLogScrollDown();
} else if (IsStashOpen) {
Stash.NextPage();
} else {
sgOptions.Keymapper.KeyPressed(MouseScrollDownButton);
}
} else if (event.wheel.x > 0) { // left
sgOptions.Keymapper.KeyPressed(MouseScrollLeftButton);
} else if (event.wheel.x < 0) { // right
sgOptions.Keymapper.KeyPressed(MouseScrollRightButton);
}
break;
#endif
default:
if (IsCustomEvent(event.type)) {
if (gbIsMultiplayer)
Expand Down
13 changes: 1 addition & 12 deletions Source/engine/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ bool FetchMessage_Real(SDL_Event *event, uint16_t *modState)
case SDL_TEXTEDITING:
case SDL_TEXTINPUT:
case SDL_WINDOWEVENT:
case SDL_MOUSEWHEEL:
#else
case SDL_ACTIVEEVENT:
#endif
Expand All @@ -119,18 +120,6 @@ bool FetchMessage_Real(SDL_Event *event, uint16_t *modState)
*event = e;
break;
#ifndef USE_SDL1
case SDL_MOUSEWHEEL:
event->type = SDL_KEYDOWN;
if (e.wheel.y > 0) {
event->key.keysym.sym = (SDL_GetModState() & KMOD_CTRL) != 0 ? SDLK_KP_PLUS : SDLK_UP;
} else if (e.wheel.y < 0) {
event->key.keysym.sym = (SDL_GetModState() & KMOD_CTRL) != 0 ? SDLK_KP_MINUS : SDLK_DOWN;
} else if (e.wheel.x > 0) {
event->key.keysym.sym = SDLK_LEFT;
} else if (e.wheel.x < 0) {
event->key.keysym.sym = SDLK_RIGHT;
}
break;
#if SDL_VERSION_ATLEAST(2, 0, 4)
case SDL_AUDIODEVICEADDED:
return FalseAvail("SDL_AUDIODEVICEADDED", e.adevice.which);
Expand Down
4 changes: 4 additions & 0 deletions Source/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,10 @@ KeymapperOptions::KeymapperOptions()
keyIDToKeyName.emplace(SDL_BUTTON_MIDDLE | KeymapperMouseButtonMask, "MMOUSE");
keyIDToKeyName.emplace(SDL_BUTTON_X1 | KeymapperMouseButtonMask, "X1MOUSE");
keyIDToKeyName.emplace(SDL_BUTTON_X2 | KeymapperMouseButtonMask, "X2MOUSE");
keyIDToKeyName.emplace(MouseScrollUpButton, "SCROLLUPMOUSE");
keyIDToKeyName.emplace(MouseScrollDownButton, "SCROLLDOWNMOUSE");
keyIDToKeyName.emplace(MouseScrollLeftButton, "SCROLLLEFTMOUSE");
keyIDToKeyName.emplace(MouseScrollRightButton, "SCROLLRIGHTMOUSE");

keyNameToKeyID.reserve(keyIDToKeyName.size());
for (const auto &kv : keyIDToKeyName) {
Expand Down
4 changes: 4 additions & 0 deletions Source/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,10 @@ struct LanguageOptions : OptionCategoryBase {
};

constexpr uint32_t KeymapperMouseButtonMask = 1 << 31;
constexpr uint32_t MouseScrollUpButton = 65536 | KeymapperMouseButtonMask;
constexpr uint32_t MouseScrollDownButton = 65537 | KeymapperMouseButtonMask;
constexpr uint32_t MouseScrollLeftButton = 65538 | KeymapperMouseButtonMask;
constexpr uint32_t MouseScrollRightButton = 65539 | KeymapperMouseButtonMask;

/** The Keymapper maps keys to actions. */
struct KeymapperOptions : OptionCategoryBase {
Expand Down
7 changes: 7 additions & 0 deletions Source/panels/spell_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ void SetSpeedSpell(size_t slot)
return;
}
Player &myPlayer = *MyPlayer;

if (myPlayer._pSplHotKey[slot] == pSpell && myPlayer._pSplTHotKey[slot] == pSplType) {
// Unset spell hotkey
myPlayer._pSplHotKey[slot] = SpellID::Invalid;
return;
}

for (size_t i = 0; i < NumHotkeys; ++i) {
if (myPlayer._pSplHotKey[i] == pSpell && myPlayer._pSplTHotKey[i] == pSplType)
myPlayer._pSplHotKey[i] = SpellID::Invalid;
Expand Down
Loading