mirror of
https://github.com/ocornut/imgui.git
synced 2025-09-10 05:18:23 +00:00
Backends: SDL+GLFW, Examples: SDL+Metal, GLFW+Metal: Fix viewport support with Metal backend.
Fixes #5392 + alignment fixes and removed static_cast<> + Amended with fix.
This commit is contained in:
@@ -408,12 +408,16 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void
|
||||
// Our mouse update function expect PlatformHandle to be filled for the main viewport
|
||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||
main_viewport->PlatformHandle = (void*)window;
|
||||
#ifdef _WIN32
|
||||
SDL_SysWMinfo info;
|
||||
SDL_VERSION(&info.version);
|
||||
if (SDL_GetWindowWMInfo(window, &info))
|
||||
{
|
||||
#ifdef _WIN32
|
||||
main_viewport->PlatformHandleRaw = (void*)info.info.win.window;
|
||||
#elif defined(__APPLE__)
|
||||
main_viewport->PlatformHandleRaw = (void*)info.info.cocoa.window;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't emit the event.
|
||||
// Without this, when clicking to gain focus, our widgets wouldn't activate even though they showed as hovered.
|
||||
@@ -639,6 +643,8 @@ static void ImGui_ImplSDL2_UpdateMonitors()
|
||||
monitor.WorkSize = ImVec2((float)r.w, (float)r.h);
|
||||
#endif
|
||||
#if SDL_HAS_PER_MONITOR_DPI
|
||||
// FIXME-VIEWPORT: On MacOS SDL reports actual monitor DPI scale, ignoring OS configuration. We may want to set
|
||||
// DpiScale to cocoa_window.backingScaleFactor here.
|
||||
float dpi = 0.0f;
|
||||
if (!SDL_GetDisplayDPI(n, &dpi, NULL, NULL))
|
||||
monitor.DpiScale = dpi / 96.0f;
|
||||
@@ -748,12 +754,16 @@ static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport)
|
||||
SDL_GL_MakeCurrent(vd->Window, backup_context);
|
||||
|
||||
viewport->PlatformHandle = (void*)vd->Window;
|
||||
#if defined(_WIN32)
|
||||
SDL_SysWMinfo info;
|
||||
SDL_VERSION(&info.version);
|
||||
if (SDL_GetWindowWMInfo(vd->Window, &info))
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
viewport->PlatformHandleRaw = info.info.win.window;
|
||||
#elif defined(__APPLE__)
|
||||
viewport->PlatformHandleRaw = (void*)info.info.cocoa.window;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL2_DestroyWindow(ImGuiViewport* viewport)
|
||||
|
Reference in New Issue
Block a user