Added ImGuiCorner enum to clarify some internal code

This commit is contained in:
ocornut 2016-10-09 10:56:23 +02:00
parent d567595dde
commit 1810b3ff38
2 changed files with 15 additions and 7 deletions

View File

@ -4192,8 +4192,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
window->ScrollbarSizes = ImVec2(window->ScrollbarY ? style.ScrollbarSize : 0.0f, window->ScrollbarX ? style.ScrollbarSize : 0.0f); window->ScrollbarSizes = ImVec2(window->ScrollbarY ? style.ScrollbarSize : 0.0f, window->ScrollbarX ? style.ScrollbarSize : 0.0f);
window->BorderSize = (flags & ImGuiWindowFlags_ShowBorders) ? 1.0f : 0.0f; window->BorderSize = (flags & ImGuiWindowFlags_ShowBorders) ? 1.0f : 0.0f;
// Window background // Window background, Default Alpha
// Default alpha
ImGuiCol bg_color_idx = ImGuiCol_WindowBg; ImGuiCol bg_color_idx = ImGuiCol_WindowBg;
if ((flags & ImGuiWindowFlags_ComboBox) != 0) if ((flags & ImGuiWindowFlags_ComboBox) != 0)
bg_color_idx = ImGuiCol_ComboBg; bg_color_idx = ImGuiCol_ComboBg;
@ -4206,19 +4205,19 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
bg_color.w = bg_alpha; bg_color.w = bg_alpha;
bg_color.w *= style.Alpha; bg_color.w *= style.Alpha;
if (bg_color.w > 0.0f) if (bg_color.w > 0.0f)
window->DrawList->AddRectFilled(window->Pos+ImVec2(0,window->TitleBarHeight()), window->Pos+window->Size, ColorConvertFloat4ToU32(bg_color), window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? 15 : 4|8); window->DrawList->AddRectFilled(window->Pos+ImVec2(0,window->TitleBarHeight()), window->Pos+window->Size, ColorConvertFloat4ToU32(bg_color), window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? ImGuiCorner_All : ImGuiCorner_BottomLeft|ImGuiCorner_BottomRight);
// Title bar // Title bar
if (!(flags & ImGuiWindowFlags_NoTitleBar)) if (!(flags & ImGuiWindowFlags_NoTitleBar))
window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), GetColorU32((g.FocusedWindow && window->RootNonPopupWindow == g.FocusedWindow->RootNonPopupWindow) ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg), window_rounding, 1|2); window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), GetColorU32((g.FocusedWindow && window->RootNonPopupWindow == g.FocusedWindow->RootNonPopupWindow) ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg), window_rounding, ImGuiCorner_TopLeft|ImGuiCorner_TopRight);
// Menu bar // Menu bar
if (flags & ImGuiWindowFlags_MenuBar) if (flags & ImGuiWindowFlags_MenuBar)
{ {
ImRect menu_bar_rect = window->MenuBarRect(); ImRect menu_bar_rect = window->MenuBarRect();
window->DrawList->AddRectFilled(menu_bar_rect.GetTL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, 1|2);
if (flags & ImGuiWindowFlags_ShowBorders) if (flags & ImGuiWindowFlags_ShowBorders)
window->DrawList->AddLine(menu_bar_rect.GetBL()-ImVec2(0,0), menu_bar_rect.GetBR()-ImVec2(0,0), GetColorU32(ImGuiCol_Border)); window->DrawList->AddLine(menu_bar_rect.GetBL()-ImVec2(0,0), menu_bar_rect.GetBR()-ImVec2(0,0), GetColorU32(ImGuiCol_Border));
window->DrawList->AddRectFilled(menu_bar_rect.GetTL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, ImGuiCorner_TopLeft|ImGuiCorner_TopRight);
} }
// Scrollbars // Scrollbars
@ -4426,9 +4425,9 @@ static void Scrollbar(ImGuiWindow* window, bool horizontal)
float window_rounding = (window->Flags & ImGuiWindowFlags_ChildWindow) ? style.ChildWindowRounding : style.WindowRounding; float window_rounding = (window->Flags & ImGuiWindowFlags_ChildWindow) ? style.ChildWindowRounding : style.WindowRounding;
int window_rounding_corners; int window_rounding_corners;
if (horizontal) if (horizontal)
window_rounding_corners = 8 | (other_scrollbar ? 0 : 4); window_rounding_corners = ImGuiCorner_BottomLeft | (other_scrollbar ? 0 : ImGuiCorner_BottomRight);
else else
window_rounding_corners = (((window->Flags & ImGuiWindowFlags_NoTitleBar) && !(window->Flags & ImGuiWindowFlags_MenuBar)) ? 2 : 0) | (other_scrollbar ? 0 : 4); window_rounding_corners = (((window->Flags & ImGuiWindowFlags_NoTitleBar) && !(window->Flags & ImGuiWindowFlags_MenuBar)) ? ImGuiCorner_TopRight : 0) | (other_scrollbar ? 0 : ImGuiCorner_BottomRight);
window->DrawList->AddRectFilled(bb.Min, bb.Max, ImGui::GetColorU32(ImGuiCol_ScrollbarBg), window_rounding, window_rounding_corners); window->DrawList->AddRectFilled(bb.Min, bb.Max, ImGui::GetColorU32(ImGuiCol_ScrollbarBg), window_rounding, window_rounding_corners);
bb.Reduce(ImVec2(ImClamp((float)(int)((bb.Max.x - bb.Min.x - 2.0f) * 0.5f), 0.0f, 3.0f), ImClamp((float)(int)((bb.Max.y - bb.Min.y - 2.0f) * 0.5f), 0.0f, 3.0f))); bb.Reduce(ImVec2(ImClamp((float)(int)((bb.Max.x - bb.Min.x - 2.0f) * 0.5f), 0.0f, 3.0f), ImClamp((float)(int)((bb.Max.y - bb.Min.y - 2.0f) * 0.5f), 0.0f, 3.0f)));

View File

@ -197,6 +197,15 @@ enum ImGuiDataType
ImGuiDataType_Float2, ImGuiDataType_Float2,
}; };
enum ImGuiCorner
{
ImGuiCorner_TopLeft = 1 << 0, // 1
ImGuiCorner_TopRight = 1 << 1, // 2
ImGuiCorner_BottomRight = 1 << 2, // 4
ImGuiCorner_BottomLeft = 1 << 3, // 8
ImGuiCorner_All = 0x0F
};
// 2D axis aligned bounding-box // 2D axis aligned bounding-box
// NB: we can't rely on ImVec2 math operators being available here // NB: we can't rely on ImVec2 math operators being available here
struct IMGUI_API ImRect struct IMGUI_API ImRect