Skip to content

Commit

Permalink
Backends: SDL, Win32: Fixed inverted horizontal mouse wheel axis. (oc…
Browse files Browse the repository at this point in the history
  • Loading branch information
rokups committed Oct 14, 2021
1 parent 13cdf2f commit 3c9858a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
12 changes: 10 additions & 2 deletions backends/imgui_impl_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2021-08-25: Inputs: Fixed inverted horizontal mouse wheel axis. (#4019)
// 2021-08-17: Calling io.AddFocusEvent() on SDL_WINDOWEVENT_FOCUS_GAINED/SDL_WINDOWEVENT_FOCUS_LOST.
// 2021-07-29: Inputs: MousePos is correctly reported when the host platform window is hovered but not focused (using SDL_GetMouseFocus() + SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, requires SDL 2.0.5+)
// 2021-06-29: *BREAKING CHANGE* Removed 'SDL_Window* window' parameter to ImGui_ImplSDL2_NewFrame() which was unnecessary.
Expand Down Expand Up @@ -67,6 +68,7 @@
#endif
#define SDL_HAS_MOUSE_FOCUS_CLICKTHROUGH SDL_VERSION_ATLEAST(2,0,5)
#define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6)
#define SDL_HAS_X11_HORIZONTAL_SCROLL_FIX SDL_VERSION_ATLEAST(2,0,17)

// SDL Data
struct ImGui_ImplSDL2_Data
Expand Down Expand Up @@ -119,8 +121,14 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
{
case SDL_MOUSEWHEEL:
{
if (event->wheel.x > 0) io.MouseWheelH += 1;
if (event->wheel.x < 0) io.MouseWheelH -= 1;
// SDL prior to 2.0.17 produced inverted horizontal scroll wheel values when running on X11.
#if SDL_HAS_X11_HORIZONTAL_SCROLL_FIX
const int horizontal_axis_mul = 1;
#else
static const int horizontal_axis_mul = strncmp(SDL_GetCurrentVideoDriver(), "x11", 3) == 0 ? -1 : +1;
#endif
if (event->wheel.x > 0) io.MouseWheelH -= 1 * horizontal_axis_mul;
if (event->wheel.x < 0) io.MouseWheelH += 1 * horizontal_axis_mul;
if (event->wheel.y > 0) io.MouseWheel += 1;
if (event->wheel.y < 0) io.MouseWheel -= 1;
return true;
Expand Down
3 changes: 2 additions & 1 deletion backends/imgui_impl_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef DWORD (WINAPI *PFN_XInputGetState)(DWORD, XINPUT_STATE*);

// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2021-08-25: Inputs: Fixed inverted horizontal mouse wheel axis. (#4019)
// 2021-08-17: Calling io.AddFocusEvent() on WM_SETFOCUS/WM_KILLFOCUS messages.
// 2021-08-02: Inputs: Fixed keyboard modifiers being reported when host windo doesn't have focus.
// 2021-07-29: Inputs: MousePos is correctly reported when the host platform window is hovered but not focused (using TrackMouseEvent() to receive WM_MOUSELEAVE events).
Expand Down Expand Up @@ -415,7 +416,7 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA
io.MouseWheel += (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA;
return 0;
case WM_MOUSEHWHEEL:
io.MouseWheelH += (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA;
io.MouseWheelH -= (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA;
return 0;
case WM_KEYDOWN:
case WM_KEYUP:
Expand Down
10 changes: 10 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ HOW TO UPDATE?
and API updates have been a little more frequent lately. They are documented below and in imgui.cpp and should not affect all users.
- Please report any issue!


-----------------------------------------------------------------------
VERSION 1.86 WIP (In Progress)
-----------------------------------------------------------------------

Other Changes:

- Backends: SDL, Win32: Fixed inverted horizontal mouse wheel axis. (#4019)


-----------------------------------------------------------------------
VERSION 1.85 (Released 2021-10-12)
-----------------------------------------------------------------------
Expand Down

0 comments on commit 3c9858a

Please sign in to comment.