mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-26 22:43:01 +00:00
GUI: fix input scaling
This commit is contained in:
parent
373367724b
commit
c6e21e3da5
1 changed files with 20 additions and 34 deletions
54
extern/imgui_patched/backends/imgui_impl_sdl.cpp
vendored
54
extern/imgui_patched/backends/imgui_impl_sdl.cpp
vendored
|
@ -276,9 +276,6 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
|
|||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
ImVec2 mouse_pos((float)event->motion.x, (float)event->motion.y);
|
||||
#ifdef __APPLE__
|
||||
|
||||
#endif
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||
{
|
||||
int window_x, window_y;
|
||||
|
@ -286,16 +283,14 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
|
|||
mouse_pos.x += window_x;
|
||||
mouse_pos.y += window_y;
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
// Fix for high DPI mac
|
||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||
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!
|
||||
mouse_pos.x *= std::ceil(platform_io.Monitors[0].DpiScale);
|
||||
mouse_pos.y *= std::ceil(platform_io.Monitors[0].DpiScale);
|
||||
}
|
||||
#endif
|
||||
// Fix for high DPI mac/idevice/wayland
|
||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||
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!
|
||||
mouse_pos.x *= std::ceil(platform_io.Monitors[0].DpiScale);
|
||||
mouse_pos.y *= std::ceil(platform_io.Monitors[0].DpiScale);
|
||||
}
|
||||
io.AddMousePosEvent(mouse_pos.x, mouse_pos.y);
|
||||
return true;
|
||||
}
|
||||
|
@ -551,16 +546,14 @@ static void ImGui_ImplSDL2_UpdateMouseData()
|
|||
mouse_x -= window_x;
|
||||
mouse_y -= window_y;
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
// Fix for high DPI mac
|
||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||
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!
|
||||
mouse_x *= std::ceil(platform_io.Monitors[0].DpiScale);
|
||||
mouse_y *= std::ceil(platform_io.Monitors[0].DpiScale);
|
||||
}
|
||||
#endif
|
||||
// Fix for high DPI mac/idevice/wayland
|
||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||
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!
|
||||
mouse_x *= std::ceil(platform_io.Monitors[0].DpiScale);
|
||||
mouse_y *= std::ceil(platform_io.Monitors[0].DpiScale);
|
||||
}
|
||||
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);
|
||||
#endif
|
||||
#if SDL_HAS_PER_MONITOR_DPI
|
||||
#ifdef __APPLE__
|
||||
monitor.DpiScale=getMacDPIScale();
|
||||
#else
|
||||
float dpi = 0.0f;
|
||||
if (!SDL_GetDisplayDPI(n, &dpi, NULL, NULL))
|
||||
monitor.DpiScale = dpi / 96.0f;
|
||||
#endif
|
||||
monitor.DpiScale = 1.0f;
|
||||
#endif
|
||||
platform_io.Monitors.push_back(monitor);
|
||||
}
|
||||
|
@ -701,15 +688,14 @@ void ImGui_ImplSDL2_NewFrame()
|
|||
if (w > 0 && h > 0)
|
||||
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
|
||||
|
||||
#if defined(__APPLE__)
|
||||
// On Apple, The window size is reported in Low DPI, even when running in high DPI mode
|
||||
// On Apple and Wayland, The window size is reported in Low DPI, even when running in high DPI mode
|
||||
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.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)
|
||||
static Uint64 frequency = SDL_GetPerformanceFrequency();
|
||||
|
|
Loading…
Reference in a new issue