Viewports: store Viewport field in ImGuiWindow to facilitate using code accross branches + fix PVS warnings.

This commit is contained in:
ocornut 2022-03-25 12:36:52 +01:00
parent dfbe938e54
commit 3587ee492b
3 changed files with 15 additions and 3 deletions

View File

@ -3709,7 +3709,7 @@ ImGuiContext* ImGui::CreateContext(ImFontAtlas* shared_font_atlas)
void ImGui::DestroyContext(ImGuiContext* ctx) void ImGui::DestroyContext(ImGuiContext* ctx)
{ {
ImGuiContext* prev_ctx = GetCurrentContext(); ImGuiContext* prev_ctx = GetCurrentContext();
if (ctx == NULL) if (ctx == NULL) //-V1051
ctx = prev_ctx; ctx = prev_ctx;
SetCurrentContext(ctx); SetCurrentContext(ctx);
Shutdown(); Shutdown();
@ -6179,6 +6179,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// SELECT VIEWPORT // SELECT VIEWPORT
// FIXME-VIEWPORT: In the docking/viewport branch, this is the point where we select the current viewport (which may affect the style) // FIXME-VIEWPORT: In the docking/viewport branch, this is the point where we select the current viewport (which may affect the style)
ImGuiViewportP* viewport = (ImGuiViewportP*)(void*)GetMainViewport();
SetWindowViewport(window, viewport);
SetCurrentWindow(window); SetCurrentWindow(window);
// LOCK BORDER SIZE AND PADDING FOR THE FRAME (so that altering them doesn't cause inconsistencies) // LOCK BORDER SIZE AND PADDING FOR THE FRAME (so that altering them doesn't cause inconsistencies)
@ -6292,7 +6295,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// Calculate the range of allowed position for that window (to be movable and visible past safe area padding) // Calculate the range of allowed position for that window (to be movable and visible past safe area padding)
// When clamping to stay visible, we will enforce that window->Pos stays inside of visibility_rect. // When clamping to stay visible, we will enforce that window->Pos stays inside of visibility_rect.
ImGuiViewportP* viewport = (ImGuiViewportP*)(void*)GetMainViewport();
ImRect viewport_rect(viewport->GetMainRect()); ImRect viewport_rect(viewport->GetMainRect());
ImRect viewport_work_rect(viewport->GetWorkRect()); ImRect viewport_work_rect(viewport->GetWorkRect());
ImVec2 visibility_padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding); ImVec2 visibility_padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding);
@ -11846,6 +11848,7 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
// [SECTION] VIEWPORTS, PLATFORM WINDOWS // [SECTION] VIEWPORTS, PLATFORM WINDOWS
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// - GetMainViewport() // - GetMainViewport()
// - SetWindowViewport() [Internal]
// - UpdateViewportsNewFrame() [Internal] // - UpdateViewportsNewFrame() [Internal]
// (this section is more complete in the 'docking' branch) // (this section is more complete in the 'docking' branch)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -11856,6 +11859,11 @@ ImGuiViewport* ImGui::GetMainViewport()
return g.Viewports[0]; return g.Viewports[0];
} }
void ImGui::SetWindowViewport(ImGuiWindow* window, ImGuiViewportP* viewport)
{
window->Viewport = viewport;
}
// Update viewports and monitor infos // Update viewports and monitor infos
static void ImGui::UpdateViewportsNewFrame() static void ImGui::UpdateViewportsNewFrame()
{ {

View File

@ -65,7 +65,7 @@ Index of this file:
// Version // Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
#define IMGUI_VERSION "1.88 WIP" #define IMGUI_VERSION "1.88 WIP"
#define IMGUI_VERSION_NUM 18711 #define IMGUI_VERSION_NUM 18712
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
#define IMGUI_HAS_TABLE #define IMGUI_HAS_TABLE

View File

@ -2017,6 +2017,7 @@ struct IMGUI_API ImGuiWindow
char* Name; // Window name, owned by the window. char* Name; // Window name, owned by the window.
ImGuiID ID; // == ImHashStr(Name) ImGuiID ID; // == ImHashStr(Name)
ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_ ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_
ImGuiViewportP* Viewport; // Always set in Begin(). Inactive windows may have a NULL value here if their viewport was discarded.
ImVec2 Pos; // Position (always rounded-up to nearest pixel) ImVec2 Pos; // Position (always rounded-up to nearest pixel)
ImVec2 Size; // Current size (==SizeFull or collapsed title bar size) ImVec2 Size; // Current size (==SizeFull or collapsed title bar size)
ImVec2 SizeFull; // Size when non collapsed ImVec2 SizeFull; // Size when non collapsed
@ -2534,6 +2535,9 @@ namespace ImGui
IMGUI_API void RemoveContextHook(ImGuiContext* context, ImGuiID hook_to_remove); IMGUI_API void RemoveContextHook(ImGuiContext* context, ImGuiID hook_to_remove);
IMGUI_API void CallContextHooks(ImGuiContext* context, ImGuiContextHookType type); IMGUI_API void CallContextHooks(ImGuiContext* context, ImGuiContextHookType type);
// Viewports
IMGUI_API void SetWindowViewport(ImGuiWindow* window, ImGuiViewportP* viewport);
// Settings // Settings
IMGUI_API void MarkIniSettingsDirty(); IMGUI_API void MarkIniSettingsDirty();
IMGUI_API void MarkIniSettingsDirty(ImGuiWindow* window); IMGUI_API void MarkIniSettingsDirty(ImGuiWindow* window);