Skip to content

Commit

Permalink
emscripten: scale mousewheel X coordinates correctly, not just Y coor…
Browse files Browse the repository at this point in the history
…dinates.

Fixes #10454.
  • Loading branch information
icculus committed Oct 24, 2024
1 parent d0cf2c1 commit 4ea26a7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/video/emscripten/SDL_emscriptenevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,20 +360,24 @@ static EM_BOOL Emscripten_HandleWheel(int eventType, const EmscriptenWheelEvent
SDL_WindowData *window_data = userData;

float deltaY = wheelEvent->deltaY;
float deltaX = wheelEvent->deltaX;

switch (wheelEvent->deltaMode) {
case DOM_DELTA_PIXEL:
deltaX /= 100; // 100 pixels make up a step
deltaY /= 100; // 100 pixels make up a step
break;
case DOM_DELTA_LINE:
deltaX /= 3; // 3 lines make up a step
deltaY /= 3; // 3 lines make up a step
break;
case DOM_DELTA_PAGE:
deltaX *= 80; // A page makes up 80 steps
deltaY *= 80; // A page makes up 80 steps
break;
}

SDL_SendMouseWheel(0, window_data->window, SDL_DEFAULT_MOUSE_ID, (float)wheelEvent->deltaX, -deltaY, SDL_MOUSEWHEEL_NORMAL);
SDL_SendMouseWheel(0, window_data->window, SDL_DEFAULT_MOUSE_ID, deltaX, -deltaY, SDL_MOUSEWHEEL_NORMAL);
return SDL_EventEnabled(SDL_EVENT_MOUSE_WHEEL);
}

Expand Down

0 comments on commit 4ea26a7

Please sign in to comment.