mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-04 07:01:04 +01:00 
			
		
		
		
	Internal: Extracted some of the Begin code into RenderWindowDecorations().
This commit is contained in:
		
							
								
								
									
										148
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										148
									
								
								imgui.cpp
									
									
									
									
									
								
							@@ -1077,6 +1077,7 @@ static void             UpdateMouseInputs();
 | 
				
			|||||||
static void             UpdateMouseWheel();
 | 
					static void             UpdateMouseWheel();
 | 
				
			||||||
static void             UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]);
 | 
					static void             UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]);
 | 
				
			||||||
static void             RenderWindowOuterBorders(ImGuiWindow* window);
 | 
					static void             RenderWindowOuterBorders(ImGuiWindow* window);
 | 
				
			||||||
 | 
					static void             RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size);
 | 
				
			||||||
static void             RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open);
 | 
					static void             RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -4964,6 +4965,82 @@ static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    ImGuiContext& g = *GImGui;
 | 
				
			||||||
 | 
					    ImGuiStyle& style = g.Style;
 | 
				
			||||||
 | 
					    ImGuiWindowFlags flags = window->Flags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Draw window + handle manual resize
 | 
				
			||||||
 | 
					    // As we highlight the title bar when want_focus is set, multiple reappearing windows will have have their title bar highlighted on their reappearing frame.
 | 
				
			||||||
 | 
					    const float window_rounding = window->WindowRounding;
 | 
				
			||||||
 | 
					    const float window_border_size = window->WindowBorderSize;
 | 
				
			||||||
 | 
					    if (window->Collapsed)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // Title bar only
 | 
				
			||||||
 | 
					        float backup_border_size = style.FrameBorderSize;
 | 
				
			||||||
 | 
					        g.Style.FrameBorderSize = window->WindowBorderSize;
 | 
				
			||||||
 | 
					        ImU32 title_bar_col = GetColorU32((title_bar_is_highlight && !g.NavDisableHighlight) ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBgCollapsed);
 | 
				
			||||||
 | 
					        RenderFrame(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, true, window_rounding);
 | 
				
			||||||
 | 
					        g.Style.FrameBorderSize = backup_border_size;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // Window background
 | 
				
			||||||
 | 
					        if (!(flags & ImGuiWindowFlags_NoBackground))
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            ImU32 bg_col = GetColorU32(GetWindowBgColorIdxFromFlags(flags));
 | 
				
			||||||
 | 
					            float alpha = 1.0f;
 | 
				
			||||||
 | 
					            if (g.NextWindowData.BgAlphaCond != 0)
 | 
				
			||||||
 | 
					                alpha = g.NextWindowData.BgAlphaVal;
 | 
				
			||||||
 | 
					            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);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        g.NextWindowData.BgAlphaCond = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Title bar
 | 
				
			||||||
 | 
					        if (!(flags & ImGuiWindowFlags_NoTitleBar))
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            ImU32 title_bar_col = GetColorU32(title_bar_is_highlight ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg);
 | 
				
			||||||
 | 
					            window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, window_rounding, ImDrawCornerFlags_Top);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Menu bar
 | 
				
			||||||
 | 
					        if (flags & ImGuiWindowFlags_MenuBar)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            ImRect menu_bar_rect = window->MenuBarRect();
 | 
				
			||||||
 | 
					            menu_bar_rect.ClipWith(window->Rect());  // Soft clipping, in particular child window don't have minimum size covering the menu bar so this is useful for them.
 | 
				
			||||||
 | 
					            window->DrawList->AddRectFilled(menu_bar_rect.Min + ImVec2(window_border_size, 0), menu_bar_rect.Max - ImVec2(window_border_size, 0), GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, ImDrawCornerFlags_Top);
 | 
				
			||||||
 | 
					            if (style.FrameBorderSize > 0.0f && menu_bar_rect.Max.y < window->Pos.y + window->Size.y)
 | 
				
			||||||
 | 
					                window->DrawList->AddLine(menu_bar_rect.GetBL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_Border), style.FrameBorderSize);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Scrollbars
 | 
				
			||||||
 | 
					        if (window->ScrollbarX)
 | 
				
			||||||
 | 
					            Scrollbar(ImGuiAxis_X);
 | 
				
			||||||
 | 
					        if (window->ScrollbarY)
 | 
				
			||||||
 | 
					            Scrollbar(ImGuiAxis_Y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Render resize grips (after their input handling so we don't have a frame of latency)
 | 
				
			||||||
 | 
					        if (!(flags & ImGuiWindowFlags_NoResize))
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                const ImGuiResizeGripDef& grip = resize_grip_def[resize_grip_n];
 | 
				
			||||||
 | 
					                const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, grip.CornerPosN);
 | 
				
			||||||
 | 
					                window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(window_border_size, resize_grip_draw_size) : ImVec2(resize_grip_draw_size, window_border_size)));
 | 
				
			||||||
 | 
					                window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(resize_grip_draw_size, window_border_size) : ImVec2(window_border_size, resize_grip_draw_size)));
 | 
				
			||||||
 | 
					                window->DrawList->PathArcToFast(ImVec2(corner.x + grip.InnerDir.x * (window_rounding + window_border_size), corner.y + grip.InnerDir.y * (window_rounding + window_border_size)), window_rounding, grip.AngleMin12, grip.AngleMax12);
 | 
				
			||||||
 | 
					                window->DrawList->PathFillConvex(resize_grip_col[resize_grip_n]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Borders
 | 
				
			||||||
 | 
					        RenderWindowOuterBorders(window);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open)
 | 
					void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ImGuiContext& g = *GImGui;
 | 
					    ImGuiContext& g = *GImGui;
 | 
				
			||||||
@@ -5349,7 +5426,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
 | 
				
			|||||||
        int border_held = -1;
 | 
					        int border_held = -1;
 | 
				
			||||||
        ImU32 resize_grip_col[4] = { 0 };
 | 
					        ImU32 resize_grip_col[4] = { 0 };
 | 
				
			||||||
        const int resize_grip_count = g.IO.ConfigWindowsResizeFromEdges ? 2 : 1; // 4
 | 
					        const int resize_grip_count = g.IO.ConfigWindowsResizeFromEdges ? 2 : 1; // 4
 | 
				
			||||||
        const float grip_draw_size = (float)(int)ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f);
 | 
					        const float resize_grip_draw_size = (float)(int)ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f);
 | 
				
			||||||
        if (!window->Collapsed)
 | 
					        if (!window->Collapsed)
 | 
				
			||||||
            UpdateManualResize(window, size_auto_fit, &border_held, resize_grip_count, &resize_grip_col[0]);
 | 
					            UpdateManualResize(window, size_auto_fit, &border_held, resize_grip_count, &resize_grip_col[0]);
 | 
				
			||||||
        window->ResizeBorderHeld = (signed char)border_held;
 | 
					        window->ResizeBorderHeld = (signed char)border_held;
 | 
				
			||||||
@@ -5423,76 +5500,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
 | 
				
			|||||||
                window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_NavWindowingHighlight, g.NavWindowingHighlightAlpha * 0.25f), g.Style.WindowRounding);
 | 
					                window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_NavWindowingHighlight, g.NavWindowingHighlightAlpha * 0.25f), g.Style.WindowRounding);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Draw window + handle manual resize
 | 
					 | 
				
			||||||
        // As we highlight the title bar when want_focus is set, multiple reappearing windows will have have their title bar highlighted on their reappearing frame.
 | 
					 | 
				
			||||||
        const float window_rounding = window->WindowRounding;
 | 
					 | 
				
			||||||
        const float window_border_size = window->WindowBorderSize;
 | 
					 | 
				
			||||||
        const ImGuiWindow* window_to_highlight = g.NavWindowingTarget ? g.NavWindowingTarget : g.NavWindow;
 | 
					        const ImGuiWindow* window_to_highlight = g.NavWindowingTarget ? g.NavWindowingTarget : g.NavWindow;
 | 
				
			||||||
        const bool title_bar_is_highlight = want_focus || (window_to_highlight && window->RootWindowForTitleBarHighlight == window_to_highlight->RootWindowForTitleBarHighlight);
 | 
					        const bool title_bar_is_highlight = want_focus || (window_to_highlight && window->RootWindowForTitleBarHighlight == window_to_highlight->RootWindowForTitleBarHighlight);
 | 
				
			||||||
        if (window->Collapsed)
 | 
					        RenderWindowDecorations(window, title_bar_rect, title_bar_is_highlight, resize_grip_count, resize_grip_col, resize_grip_draw_size);
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Title bar only
 | 
					 | 
				
			||||||
            float backup_border_size = style.FrameBorderSize;
 | 
					 | 
				
			||||||
            g.Style.FrameBorderSize = window->WindowBorderSize;
 | 
					 | 
				
			||||||
            ImU32 title_bar_col = GetColorU32((title_bar_is_highlight && !g.NavDisableHighlight) ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBgCollapsed);
 | 
					 | 
				
			||||||
            RenderFrame(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, true, window_rounding);
 | 
					 | 
				
			||||||
            g.Style.FrameBorderSize = backup_border_size;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Window background
 | 
					 | 
				
			||||||
            if (!(flags & ImGuiWindowFlags_NoBackground))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                ImU32 bg_col = GetColorU32(GetWindowBgColorIdxFromFlags(flags));
 | 
					 | 
				
			||||||
                float alpha = 1.0f;
 | 
					 | 
				
			||||||
                if (g.NextWindowData.BgAlphaCond != 0)
 | 
					 | 
				
			||||||
                    alpha = g.NextWindowData.BgAlphaVal;
 | 
					 | 
				
			||||||
                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);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            g.NextWindowData.BgAlphaCond = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Title bar
 | 
					 | 
				
			||||||
            if (!(flags & ImGuiWindowFlags_NoTitleBar))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                ImU32 title_bar_col = GetColorU32(title_bar_is_highlight ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg);
 | 
					 | 
				
			||||||
                window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, window_rounding, ImDrawCornerFlags_Top);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Menu bar
 | 
					 | 
				
			||||||
            if (flags & ImGuiWindowFlags_MenuBar)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                ImRect menu_bar_rect = window->MenuBarRect();
 | 
					 | 
				
			||||||
                menu_bar_rect.ClipWith(window->Rect());  // Soft clipping, in particular child window don't have minimum size covering the menu bar so this is useful for them.
 | 
					 | 
				
			||||||
                window->DrawList->AddRectFilled(menu_bar_rect.Min+ImVec2(window_border_size,0), menu_bar_rect.Max-ImVec2(window_border_size,0), GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, ImDrawCornerFlags_Top);
 | 
					 | 
				
			||||||
                if (style.FrameBorderSize > 0.0f && menu_bar_rect.Max.y < window->Pos.y + window->Size.y)
 | 
					 | 
				
			||||||
                    window->DrawList->AddLine(menu_bar_rect.GetBL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_Border), style.FrameBorderSize);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Scrollbars
 | 
					 | 
				
			||||||
            if (window->ScrollbarX)
 | 
					 | 
				
			||||||
                Scrollbar(ImGuiAxis_X);
 | 
					 | 
				
			||||||
            if (window->ScrollbarY)
 | 
					 | 
				
			||||||
                Scrollbar(ImGuiAxis_Y);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Render resize grips (after their input handling so we don't have a frame of latency)
 | 
					 | 
				
			||||||
            if (!(flags & ImGuiWindowFlags_NoResize))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    const ImGuiResizeGripDef& grip = resize_grip_def[resize_grip_n];
 | 
					 | 
				
			||||||
                    const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, grip.CornerPosN);
 | 
					 | 
				
			||||||
                    window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(window_border_size, grip_draw_size) : ImVec2(grip_draw_size, window_border_size)));
 | 
					 | 
				
			||||||
                    window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(grip_draw_size, window_border_size) : ImVec2(window_border_size, grip_draw_size)));
 | 
					 | 
				
			||||||
                    window->DrawList->PathArcToFast(ImVec2(corner.x + grip.InnerDir.x * (window_rounding + window_border_size), corner.y + grip.InnerDir.y * (window_rounding + window_border_size)), window_rounding, grip.AngleMin12, grip.AngleMax12);
 | 
					 | 
				
			||||||
                    window->DrawList->PathFillConvex(resize_grip_col[resize_grip_n]);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Borders
 | 
					 | 
				
			||||||
            RenderWindowOuterBorders(window);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Draw navigation selection/windowing rectangle border
 | 
					        // Draw navigation selection/windowing rectangle border
 | 
				
			||||||
        if (g.NavWindowingTargetAnim == window)
 | 
					        if (g.NavWindowingTargetAnim == window)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user