GUI: fix input scaling
This commit is contained in:
parent
373367724b
commit
c6e21e3da5
|
@ -276,9 +276,6 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
{
|
{
|
||||||
ImVec2 mouse_pos((float)event->motion.x, (float)event->motion.y);
|
ImVec2 mouse_pos((float)event->motion.x, (float)event->motion.y);
|
||||||
#ifdef __APPLE__
|
|
||||||
|
|
||||||
#endif
|
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
{
|
{
|
||||||
int window_x, window_y;
|
int window_x, window_y;
|
||||||
|
@ -286,16 +283,14 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
|
||||||
mouse_pos.x += window_x;
|
mouse_pos.x += window_x;
|
||||||
mouse_pos.y += window_y;
|
mouse_pos.y += window_y;
|
||||||
}
|
}
|
||||||
#ifdef __APPLE__
|
// Fix for high DPI mac/idevice/wayland
|
||||||
// Fix for high DPI mac
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
if (!platform_io.Monitors.empty() && platform_io.Monitors[0].DpiScale > 1.0f)
|
||||||
if (!platform_io.Monitors.empty() && platform_io.Monitors[0].DpiScale > 1.0f)
|
{
|
||||||
{
|
// The Framebuffer is scaled by an integer ceiling of the actual ratio, so 2.0 not 1.685 on Mac!
|
||||||
// The Framebuffer is scaled by an integer ceiling of the actual ratio, so 2.0 not 1.685 on Mac!
|
mouse_pos.x *= std::ceil(platform_io.Monitors[0].DpiScale);
|
||||||
mouse_pos.x *= std::ceil(platform_io.Monitors[0].DpiScale);
|
mouse_pos.y *= std::ceil(platform_io.Monitors[0].DpiScale);
|
||||||
mouse_pos.y *= std::ceil(platform_io.Monitors[0].DpiScale);
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
io.AddMousePosEvent(mouse_pos.x, mouse_pos.y);
|
io.AddMousePosEvent(mouse_pos.x, mouse_pos.y);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -551,16 +546,14 @@ static void ImGui_ImplSDL2_UpdateMouseData()
|
||||||
mouse_x -= window_x;
|
mouse_x -= window_x;
|
||||||
mouse_y -= window_y;
|
mouse_y -= window_y;
|
||||||
}
|
}
|
||||||
#ifdef __APPLE__
|
// Fix for high DPI mac/idevice/wayland
|
||||||
// Fix for high DPI mac
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
if (!platform_io.Monitors.empty() && platform_io.Monitors[0].DpiScale > 1.0f)
|
||||||
if (!platform_io.Monitors.empty() && platform_io.Monitors[0].DpiScale > 1.0f)
|
{
|
||||||
{
|
// The Framebuffer is scaled by an integer ceiling of the actual ratio, so 2.0 not 1.685 on Mac!
|
||||||
// The Framebuffer is scaled by an integer ceiling of the actual ratio, so 2.0 not 1.685 on Mac!
|
mouse_x *= std::ceil(platform_io.Monitors[0].DpiScale);
|
||||||
mouse_x *= std::ceil(platform_io.Monitors[0].DpiScale);
|
mouse_y *= std::ceil(platform_io.Monitors[0].DpiScale);
|
||||||
mouse_y *= std::ceil(platform_io.Monitors[0].DpiScale);
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
io.AddMousePosEvent((float)mouse_x, (float)mouse_y);
|
io.AddMousePosEvent((float)mouse_x, (float)mouse_y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -669,13 +662,7 @@ static void ImGui_ImplSDL2_UpdateMonitors()
|
||||||
monitor.WorkSize = ImVec2((float)r.w, (float)r.h);
|
monitor.WorkSize = ImVec2((float)r.w, (float)r.h);
|
||||||
#endif
|
#endif
|
||||||
#if SDL_HAS_PER_MONITOR_DPI
|
#if SDL_HAS_PER_MONITOR_DPI
|
||||||
#ifdef __APPLE__
|
monitor.DpiScale = 1.0f;
|
||||||
monitor.DpiScale=getMacDPIScale();
|
|
||||||
#else
|
|
||||||
float dpi = 0.0f;
|
|
||||||
if (!SDL_GetDisplayDPI(n, &dpi, NULL, NULL))
|
|
||||||
monitor.DpiScale = dpi / 96.0f;
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
platform_io.Monitors.push_back(monitor);
|
platform_io.Monitors.push_back(monitor);
|
||||||
}
|
}
|
||||||
|
@ -701,15 +688,14 @@ void ImGui_ImplSDL2_NewFrame()
|
||||||
if (w > 0 && h > 0)
|
if (w > 0 && h > 0)
|
||||||
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
|
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
// On Apple and Wayland, The window size is reported in Low DPI, even when running in high DPI mode
|
||||||
// On Apple, The window size is reported in Low DPI, even when running in high DPI mode
|
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
if (!platform_io.Monitors.empty() && platform_io.Monitors[0].DpiScale > 1.0f && display_h != h)
|
if (!platform_io.Monitors.empty() /*&& platform_io.Monitors[0].DpiScale > 1.0f*/ && display_h != h)
|
||||||
{
|
{
|
||||||
io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f);
|
io.DisplayFramebufferScale = ImVec2(1.0f, 1.0f);
|
||||||
io.DisplaySize = ImVec2((float)display_w, (float)display_h);
|
io.DisplaySize = ImVec2((float)display_w, (float)display_h);
|
||||||
|
platform_io.Monitors[0].DpiScale=(float)display_w/(float)w;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
|
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
|
||||||
static Uint64 frequency = SDL_GetPerformanceFrequency();
|
static Uint64 frequency = SDL_GetPerformanceFrequency();
|
||||||
|
|
Loading…
Reference in New Issue