Docking: Added io.ConfigDockingTransparentPayload option (to use with ImGuiConfigFlags_ViewportsNoMerge)

This commit is contained in:
omar
2018-11-29 15:56:51 +01:00
parent 3bcc25f588
commit 19d17ed274
3 changed files with 45 additions and 14 deletions

View File

@ -920,6 +920,9 @@ static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f; // Time
static const float RESIZE_WINDOWS_FROM_EDGES_HALF_THICKNESS = 4.0f; // Extend outside and inside windows. Affect FindHoveredWindow().
static const float RESIZE_WINDOWS_FROM_EDGES_FEEDBACK_TIMER = 0.04f; // Reduce visual noise by only highlighting the border after a certain time.
// Docking
static const float DOCKING_TRANSPARENT_PAYLOAD_ALPHA = 0.50f; // For use with io.ConfigDockingTransparentPayload. Apply to Viewport _or_ WindowBg in host viewport.
//-------------------------------------------------------------------------
// [SECTION] FORWARD DECLARATIONS
//-------------------------------------------------------------------------
@ -1114,6 +1117,7 @@ ImGuiIO::ImGuiIO()
// Miscellaneous configuration options
ConfigDockingWithShift = false;
ConfigDockingTransparentPayload = false;
#ifdef __APPLE__
ConfigMacOSXBehaviors = true; // Set Mac OS X style defaults based on __APPLE__ compile time flag
#else
@ -3281,6 +3285,8 @@ void ImGui::NewFrame()
IM_ASSERT(g.PlatformIO.Platform_GetWindowSize != NULL && "Platform init didn't install handlers?");
IM_ASSERT(g.PlatformIO.Platform_SetWindowSize != NULL && "Platform init didn't install handlers?");
IM_ASSERT((g.Viewports[0]->PlatformUserData != NULL || g.Viewports[0]->PlatformHandle != NULL) && "Platform init didn't setup main viewport.");
if (g.IO.ConfigDockingTransparentPayload && (g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable))
IM_ASSERT(g.PlatformIO.Platform_SetWindowAlpha != NULL && "Platform_SetWindowAlpha handler is required to use io.ConfigDockingTransparent!");
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
IM_ASSERT(g.IO.RenderDrawListsFn == NULL); // Call ImGui::Render() then pass ImGui::GetDrawData() yourself to your render function!
#endif
@ -5367,13 +5373,29 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// Window background
if (!(flags & ImGuiWindowFlags_NoBackground))
{
bool is_docking_transparent_payload = false;
if (g.DragDropActive && (g.FrameCount - g.DragDropAcceptFrameCount) <= 1 && g.IO.ConfigDockingTransparentPayload)
if (g.DragDropPayload.IsDataType(IMGUI_PAYLOAD_TYPE_WINDOW) && *(ImGuiWindow**)g.DragDropPayload.Data == window)
is_docking_transparent_payload = true;
ImU32 bg_col = GetColorU32(GetWindowBgColorIdxFromFlags(flags));
if (g.NextWindowData.BgAlphaCond != 0)
bg_col = (bg_col & ~IM_COL32_A_MASK) | (IM_F32_TO_INT8_SAT(g.NextWindowData.BgAlphaVal) << IM_COL32_A_SHIFT);
if (window->ViewportOwned)
{
//window->Viewport->Alpha = ((bg_col & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT) / 255.0f;
// No alpha
bg_col = (bg_col | IM_COL32_A_MASK);
if (is_docking_transparent_payload)
window->Viewport->Alpha *= DOCKING_TRANSPARENT_PAYLOAD_ALPHA;
}
else
{
// Adjust alpha. For docking
float alpha = 1.0f;
if (g.NextWindowData.BgAlphaCond != 0)
alpha = g.NextWindowData.BgAlphaVal;
if (is_docking_transparent_payload)
alpha *= DOCKING_TRANSPARENT_PAYLOAD_ALPHA;
if (alpha != 1.0f)
bg_col = (bg_col & ~IM_COL32_A_MASK) | (IM_F32_TO_INT8_SAT(alpha) << IM_COL32_A_SHIFT);
}
window->DrawList->AddRectFilled(window->Pos + ImVec2(0, window->TitleBarHeight()), window->Pos + window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? ImDrawCornerFlags_All : ImDrawCornerFlags_Bot);
}
@ -7534,7 +7556,7 @@ static void ImGui::UpdateViewports()
if (g.PlatformIO.Platform_GetWindowMinimized && (n == 0 || viewport->CreatedPlatformWindow))
viewport->PlatformIsMinimized = g.PlatformIO.Platform_GetWindowMinimized(viewport);
// Apply Position and Size (from Platform Window to ImGui) if requested.
// Update Position and Size (from Platform Window to ImGui) if requested.
// We do it early in the frame instead of waiting for UpdatePlatformWindows() to avoid a frame of lag when moving/resizing using OS facilities.
if (!viewport->PlatformIsMinimized)
{
@ -7548,6 +7570,9 @@ static void ImGui::UpdateViewports()
viewport->PlatformMonitor = FindPlatformMonitorForRect(viewport->GetRect());
}
// Reset alpha every frame. Users of transparency (docking) needs to request a lower alpha back.
viewport->Alpha = 1.0f;
// Translate imgui windows when a Host Viewport has been moved
// (This additionally keeps windows at the same place when ImGuiConfigFlags_ViewportsEnable is toggled!)
ImVec2 viewport_delta = viewport->Pos - viewport->LastPos;
@ -11352,19 +11377,23 @@ static void ImGui::DockNodePreviewDockRender(ImGuiWindow* host_window, ImGuiDock
{
ImGuiContext& g = *GImGui;
// With this option, we only display the preview on the target viewport, and the payload viewport is made transparent.
// To compensate for the single layer obstructed by the payload, we'll increase the alpha of the preview nodes.
const bool is_transparent_payload = g.IO.ConfigDockingTransparentPayload;
// In case the two windows involved are on different viewports, we will draw the overlay on each of them.
int overlay_draw_lists_count = 0;
ImDrawList* overlay_draw_lists[2];
overlay_draw_lists[overlay_draw_lists_count++] = GetOverlayDrawList(host_window->Viewport);
if (host_window->Viewport != root_payload->Viewport)
if (host_window->Viewport != root_payload->Viewport && !is_transparent_payload)
overlay_draw_lists[overlay_draw_lists_count++] = GetOverlayDrawList(root_payload->Viewport);
// Draw main preview rectangle
const ImU32 overlay_col_tabs = GetColorU32(ImGuiCol_TabActive);
const ImU32 overlay_col_main = GetColorU32(ImGuiCol_DockingPreview, 0.40f);
const ImU32 overlay_col_drop = GetColorU32(ImGuiCol_DockingPreview, 0.70f);
const ImU32 overlay_col_drop_hovered = GetColorU32(ImGuiCol_DockingPreview);
const ImU32 overlay_col_lines = GetColorU32(ImGuiCol_NavWindowingHighlight, 0.60f);
const ImU32 overlay_col_main = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 0.60f : 0.40f);
const ImU32 overlay_col_drop = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 0.90f : 0.70f);
const ImU32 overlay_col_drop_hovered = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 1.20f : 1.00f);
const ImU32 overlay_col_lines = GetColorU32(ImGuiCol_NavWindowingHighlight, is_transparent_payload ? 0.80f : 0.60f);
// Display area preview
const bool can_preview_tabs = (root_payload->DockNodeAsHost == NULL || root_payload->DockNodeAsHost->Windows.Size > 0);