Backends: Win32: Viewports: handle WM_DPICHANGED in backend when ImGuiConfigFlags_DpiEnableScaleViewports flag is enabled.
This commit is contained in:
parent
ac6b84a7d7
commit
a92b53df7b
@ -23,6 +23,7 @@
|
|||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2025-06-02: [Docking] WM_DPICHANGED also apply ImGuiConfigFlags_DpiEnableScaleViewports for main viewport instead of letting it be done by application code.
|
||||||
// 2025-04-30: Inputs: Fixed an issue where externally losing mouse capture (due to e.g. focus loss) would fail to claim it again the next subsequent click. (#8594)
|
// 2025-04-30: Inputs: Fixed an issue where externally losing mouse capture (due to e.g. focus loss) would fail to claim it again the next subsequent click. (#8594)
|
||||||
// 2025-03-26: [Docking] Viewports: fixed an issue when closing a window from the OS close button (with io.ConfigViewportsNoDecoration = false) while user code was discarding the 'bool* p_open = false' output from Begin(). Because we allowed the Win32 window to close early, Windows destroyed it and our imgui window became not visible even though user code was still submitting it.
|
// 2025-03-26: [Docking] Viewports: fixed an issue when closing a window from the OS close button (with io.ConfigViewportsNoDecoration = false) while user code was discarding the 'bool* p_open = false' output from Begin(). Because we allowed the Win32 window to close early, Windows destroyed it and our imgui window became not visible even though user code was still submitting it.
|
||||||
// 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
|
// 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
|
||||||
@ -705,6 +706,10 @@ static ImGuiMouseSource ImGui_ImplWin32_GetMouseSourceFromMessageExtraInfo()
|
|||||||
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); // Use ImGui::GetCurrentContext()
|
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); // Use ImGui::GetCurrentContext()
|
||||||
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandlerEx(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, ImGuiIO& io); // Doesn't use ImGui::GetCurrentContext()
|
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandlerEx(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, ImGuiIO& io); // Doesn't use ImGui::GetCurrentContext()
|
||||||
|
|
||||||
|
#ifndef WM_DPICHANGED
|
||||||
|
#define WM_DPICHANGED 0x02E0 // From Windows SDK 8.1+ headers
|
||||||
|
#endif
|
||||||
|
|
||||||
IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
// Most backends don't have silent checks like this one, but we need it because WndProc are called early in CreateWindow().
|
// Most backends don't have silent checks like this one, but we need it because WndProc are called early in CreateWindow().
|
||||||
@ -899,6 +904,13 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandlerEx(HWND hwnd, UINT msg, WPA
|
|||||||
if (wParam == SPI_SETWORKAREA)
|
if (wParam == SPI_SETWORKAREA)
|
||||||
bd->WantUpdateMonitors = true;
|
bd->WantUpdateMonitors = true;
|
||||||
return 0;
|
return 0;
|
||||||
|
case WM_DPICHANGED:
|
||||||
|
{
|
||||||
|
const RECT* suggested_rect = (RECT*)lParam;
|
||||||
|
if (io.ConfigFlags & ImGuiConfigFlags_DpiEnableScaleViewports)
|
||||||
|
::SetWindowPos(hwnd, nullptr, suggested_rect->left, suggested_rect->top, suggested_rect->right - suggested_rect->left, suggested_rect->bottom - suggested_rect->top, SWP_NOZORDER | SWP_NOACTIVATE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -171,14 +171,16 @@ Docking+Viewports Branch:
|
|||||||
(this per-se doesn't fix the font quality which requires setting RasterizerDensity
|
(this per-se doesn't fix the font quality which requires setting RasterizerDensity
|
||||||
separately. More on this later as it should soon become automatic).
|
separately. More on this later as it should soon become automatic).
|
||||||
(#1065, #1542, #1676, #1786, #2826, #3757, #5081, #5580, #5592, #6465, #7273, #7779 etc.)
|
(#1065, #1542, #1676, #1786, #2826, #3757, #5081, #5580, #5592, #6465, #7273, #7779 etc.)
|
||||||
- Viewports: fixed handling of simultaneous move + resize (e.g. toggling maximized) when
|
- Viewports: fixed handling of simultaneous move + resize (e.g. toggling maximized)
|
||||||
ImGuiConfigFlags_DpiEnableScaleViewports is enabled.
|
when ImGuiConfigFlags_DpiEnableScaleViewports is enabled.
|
||||||
- Backends: Win32: Viewports: fixed an issue when closing a window from
|
- Backends: Win32: Viewports: fixed an issue when closing a window from
|
||||||
the OS close button (with io.ConfigViewportsNoDecoration=false) while
|
the OS close button (with io.ConfigViewportsNoDecoration=false) while
|
||||||
user code is discarding the 'bool *p_open=false output' from Begin().
|
user code is discarding the 'bool *p_open=false output' from Begin().
|
||||||
Because we allowed the Win32 window to close early, Windows destroyed
|
Because we allowed the Win32 window to close early, Windows destroyed
|
||||||
it and our imgui window became not visible even though user code was
|
it and our imgui window became not visible even though user code was
|
||||||
still submitting it.
|
still submitting it.
|
||||||
|
- Backends: Win32: Viewports: handle WM_DPICHANGED in backend when
|
||||||
|
ImGuiConfigFlags_DpiEnableScaleViewports is enabled.
|
||||||
- Backends: GLFW, SDL2, SDL3, Apple: provide Platform_GetWindowFramebufferScale handler,
|
- Backends: GLFW, SDL2, SDL3, Apple: provide Platform_GetWindowFramebufferScale handler,
|
||||||
(#1065, #1542, #1676, #1786, #2826, #3757, #5081, #5580, #5592, #6465, #7273, #7779 etc.)
|
(#1065, #1542, #1676, #1786, #2826, #3757, #5081, #5580, #5592, #6465, #7273, #7779 etc.)
|
||||||
- Backends: SDLGPU3 for SDL3: added multi-viewport support. (#8573) [@Lekoopapaul]
|
- Backends: SDLGPU3 for SDL3: added multi-viewport support. (#8573) [@Lekoopapaul]
|
||||||
|
|||||||
@ -264,10 +264,6 @@ void CleanupRenderTarget()
|
|||||||
if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = nullptr; }
|
if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = nullptr; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WM_DPICHANGED
|
|
||||||
#define WM_DPICHANGED 0x02E0 // From Windows SDK 8.1+ headers
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Forward declare message handler from imgui_impl_win32.cpp
|
// Forward declare message handler from imgui_impl_win32.cpp
|
||||||
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
@ -296,15 +292,6 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
::PostQuitMessage(0);
|
::PostQuitMessage(0);
|
||||||
return 0;
|
return 0;
|
||||||
case WM_DPICHANGED:
|
|
||||||
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DpiEnableScaleViewports)
|
|
||||||
{
|
|
||||||
//const int dpi = HIWORD(wParam);
|
|
||||||
//printf("WM_DPICHANGED to %d (%.0f%%)\n", dpi, (float)dpi / 96.0f * 100.0f);
|
|
||||||
const RECT* suggested_rect = (RECT*)lParam;
|
|
||||||
::SetWindowPos(hWnd, nullptr, suggested_rect->left, suggested_rect->top, suggested_rect->right - suggested_rect->left, suggested_rect->bottom - suggested_rect->top, SWP_NOZORDER | SWP_NOACTIVATE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return ::DefWindowProcW(hWnd, msg, wParam, lParam);
|
return ::DefWindowProcW(hWnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -250,10 +250,6 @@ void ResetDevice()
|
|||||||
ImGui_ImplDX9_CreateDeviceObjects();
|
ImGui_ImplDX9_CreateDeviceObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WM_DPICHANGED
|
|
||||||
#define WM_DPICHANGED 0x02E0 // From Windows SDK 8.1+ headers
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Forward declare message handler from imgui_impl_win32.cpp
|
// Forward declare message handler from imgui_impl_win32.cpp
|
||||||
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
@ -282,15 +278,6 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
::PostQuitMessage(0);
|
::PostQuitMessage(0);
|
||||||
return 0;
|
return 0;
|
||||||
case WM_DPICHANGED:
|
|
||||||
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DpiEnableScaleViewports)
|
|
||||||
{
|
|
||||||
//const int dpi = HIWORD(wParam);
|
|
||||||
//printf("WM_DPICHANGED to %d (%.0f%%)\n", dpi, (float)dpi / 96.0f * 100.0f);
|
|
||||||
const RECT* suggested_rect = (RECT*)lParam;
|
|
||||||
::SetWindowPos(hWnd, nullptr, suggested_rect->left, suggested_rect->top, suggested_rect->right - suggested_rect->left, suggested_rect->bottom - suggested_rect->top, SWP_NOZORDER | SWP_NOACTIVATE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return ::DefWindowProcW(hWnd, msg, wParam, lParam);
|
return ::DefWindowProcW(hWnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|||||||
2
imgui.h
2
imgui.h
@ -1666,7 +1666,7 @@ enum ImGuiConfigFlags_
|
|||||||
// [BETA] Viewports
|
// [BETA] Viewports
|
||||||
// When using viewports it is recommended that your default value for ImGuiCol_WindowBg is opaque (Alpha=1.0) so transition to a viewport won't be noticeable.
|
// When using viewports it is recommended that your default value for ImGuiCol_WindowBg is opaque (Alpha=1.0) so transition to a viewport won't be noticeable.
|
||||||
ImGuiConfigFlags_ViewportsEnable = 1 << 10, // Viewport enable flags (require both ImGuiBackendFlags_PlatformHasViewports + ImGuiBackendFlags_RendererHasViewports set by the respective backends)
|
ImGuiConfigFlags_ViewportsEnable = 1 << 10, // Viewport enable flags (require both ImGuiBackendFlags_PlatformHasViewports + ImGuiBackendFlags_RendererHasViewports set by the respective backends)
|
||||||
ImGuiConfigFlags_DpiEnableScaleViewports= 1 << 14, // [BETA: Don't use] FIXME-DPI: Reposition and resize imgui windows when the DpiScale of a viewport changed (mostly useful for the main viewport hosting other window). Note that resizing the main window itself is up to your application.
|
ImGuiConfigFlags_DpiEnableScaleViewports= 1 << 14, // [BETA: Don't use] FIXME-DPI: Reposition and resize imgui and platform windows when the DpiScale of a viewport changed.
|
||||||
ImGuiConfigFlags_DpiEnableScaleFonts = 1 << 15, // [BETA: Don't use] FIXME-DPI: Request bitmap-scaled fonts to match DpiScale. This is a very low-quality workaround. The correct way to handle DPI is _currently_ to replace the atlas and/or fonts in the Platform_OnChangedViewport callback, but this is all early work in progress.
|
ImGuiConfigFlags_DpiEnableScaleFonts = 1 << 15, // [BETA: Don't use] FIXME-DPI: Request bitmap-scaled fonts to match DpiScale. This is a very low-quality workaround. The correct way to handle DPI is _currently_ to replace the atlas and/or fonts in the Platform_OnChangedViewport callback, but this is all early work in progress.
|
||||||
|
|
||||||
// User storage (to allow your backend/engine to communicate to code that may be shared between multiple projects. Those flags are NOT used by core Dear ImGui)
|
// User storage (to allow your backend/engine to communicate to code that may be shared between multiple projects. Those flags are NOT used by core Dear ImGui)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user