Skip to content

Commit 9fbdf90

Browse files
SDL3 renderer: Handle context dimensions with SDL_SetRenderLogicalPresentation enabled (#889)
1 parent d6a80ca commit 9fbdf90

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Backends/RmlUi_Platform_SDL.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,24 @@ bool RmlSDL::InputEventHandler(Rml::Context* context, SDL_Window* window, SDL_Ev
242242
case event_window_size_changed:
243243
{
244244
Rml::Vector2i dimensions(ev.window.data1, ev.window.data2);
245+
246+
#if SDL_MAJOR_VERSION >= 3
247+
// SDL_Renderer backend (SDL3): if SDL_SetRenderLogicalPresentation() is enabled, the renderer uses a fixed logical
248+
// output size (render coordinates) and scales it to the window; use that logical size for the RmlUi context.
249+
// Input events should be converted to render coordinates first (e.g. SDL_ConvertEventToRenderCoordinates()).
250+
SDL_Renderer* renderer = SDL_GetRenderer(window);
251+
if (renderer)
252+
{
253+
int logical_w = 0;
254+
int logical_h = 0;
255+
SDL_RendererLogicalPresentation mode{};
256+
if (SDL_GetRenderLogicalPresentation(renderer, &logical_w, &logical_h, &mode)
257+
&& mode != SDL_LOGICAL_PRESENTATION_DISABLED
258+
&& logical_w > 0 && logical_h > 0)
259+
dimensions = Rml::Vector2i(logical_w, logical_h);
260+
}
261+
#endif
262+
245263
context->SetDimensions(dimensions);
246264
}
247265
break;

Backends/RmlUi_Platform_SDL.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class SystemInterface_SDL : public Rml::SystemInterface {
4444
namespace RmlSDL {
4545

4646
// Applies input on the context based on the given SDL event.
47+
//
48+
// Note (SDL3 + SDL_Renderer): When using SDL_SetRenderLogicalPresentation(), SDL_Renderer operates in render
49+
// coordinates (logical coordinates). Therefore, before passing an SDL_Event to InputEventHandler, input event
50+
// coordinates (mouse/touch/etc.) should be converted to render coordinates, e.g.
51+
// SDL_ConvertEventToRenderCoordinates(renderer, &ev).
4752
// @return True if the event is still propagating, false if it was handled by the context.
4853
bool InputEventHandler(Rml::Context* context, SDL_Window* window, SDL_Event& ev);
4954

0 commit comments

Comments
 (0)