Skip to content

Commit

Permalink
Fixed SDL(3)_SetRenderScale handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bog-dan-ro committed Dec 29, 2023
1 parent 4a24264 commit a182970
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion backends/imgui_impl_sdl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event)
{
ImVec2 mouse_pos((float)event->motion.x, (float)event->motion.y);
io.AddMouseSourceEvent(event->motion.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
float rsx = 1.0f;
float rsy = 1.0f;
SDL_GetRenderScale(bd->Renderer, &rsx, &rsy);
mouse_pos.x /= rsx;
mouse_pos.y /= rsy;
io.AddMousePosEvent(mouse_pos.x, mouse_pos.y);
return true;
}
Expand All @@ -276,6 +281,11 @@ bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event)
wheel_x /= 100.0f;
#endif
io.AddMouseSourceEvent(event->wheel.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
float rsx = 1.0f;
float rsy = 1.0f;
SDL_GetRenderScale(bd->Renderer, &rsx, &rsy);
wheel_x /= rsx;
wheel_y /= rsy;
io.AddMouseWheelEvent(wheel_x, wheel_y);
return true;
}
Expand Down Expand Up @@ -492,7 +502,14 @@ static void ImGui_ImplSDL3_UpdateMouseData()
int window_x, window_y;
SDL_GetGlobalMouseState(&mouse_x_global, &mouse_y_global);
SDL_GetWindowPosition(focused_window, &window_x, &window_y);
io.AddMousePosEvent(mouse_x_global - window_x, mouse_y_global - window_y);
mouse_x_global -= window_x;
mouse_y_global -= window_y;
float rsx = 1.0f;
float rsy = 1.0f;
SDL_GetRenderScale(bd->Renderer, &rsx, &rsy);
mouse_x_global /= rsx;
mouse_y_global /= rsy;
io.AddMousePosEvent(mouse_x_global, mouse_y_global);
}
}
}
Expand Down

0 comments on commit a182970

Please sign in to comment.