mirror of
https://github.com/ocornut/imgui.git
synced 2026-03-30 13:05:23 -05:00
Windows 98 style
This commit is contained in:
116
imgui.cpp
116
imgui.cpp
@@ -3523,8 +3523,12 @@ void ImGui::RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border,
|
||||
const float border_size = g.Style.FrameBorderSize;
|
||||
if (border && border_size > 0.0f)
|
||||
{
|
||||
#ifdef WIN98
|
||||
WinAddRect(p_min, p_max, true);
|
||||
#else
|
||||
window->DrawList->AddRect(p_min + ImVec2(1, 1), p_max + ImVec2(1, 1), GetColorU32(ImGuiCol_BorderShadow), rounding, 0, border_size);
|
||||
window->DrawList->AddRect(p_min, p_max, GetColorU32(ImGuiCol_Border), rounding, 0, border_size);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6193,7 +6197,48 @@ static inline void ClampWindowPos(ImGuiWindow* window, const ImRect& visibility_
|
||||
window->Pos = ImClamp(window->Pos, visibility_rect.Min - size_for_clamping, visibility_rect.Max);
|
||||
}
|
||||
|
||||
static void RenderWindowOuterSingleBorder(ImGuiWindow* window, int border_n, ImU32 border_col, float border_size)
|
||||
void ImGui::WinAddRect(const ImVec2& min, const ImVec2& max, bool inset)
|
||||
{
|
||||
ImU32 top_left = IM_COL32(255,255,255,255);
|
||||
ImU32 bottom_right = IM_COL32(0,0,0,255);
|
||||
ImU32 top_left_inner = IM_COL32(223,223,223,255);
|
||||
ImU32 bottom_right_inner = IM_COL32(128,128,128,255);
|
||||
|
||||
if (inset) {
|
||||
ImU32 tmp = top_left; top_left = bottom_right; bottom_right = tmp;
|
||||
tmp = top_left_inner; top_left_inner = bottom_right_inner; bottom_right_inner = tmp;
|
||||
}
|
||||
|
||||
// ImU32 fill_col = IM_COL32(192,192,192,255);
|
||||
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
ImVec2 a = min + ImVec2(0.5f, 0.5f);
|
||||
ImVec2 b = max - ImVec2(0.5f, 0.5f);
|
||||
|
||||
draw_list->PathLineTo(ImVec2(a.x, b.y));
|
||||
draw_list->PathLineTo(a);
|
||||
draw_list->PathLineTo(ImVec2(b.x, a.y));
|
||||
draw_list->PathStroke(top_left, false, 1.0f);
|
||||
|
||||
draw_list->PathLineTo(ImVec2(a.x, b.y));
|
||||
draw_list->PathLineTo(b);
|
||||
draw_list->PathLineTo(ImVec2(b.x, a.y));
|
||||
draw_list->PathStroke(bottom_right, false, 1.0f);
|
||||
|
||||
|
||||
draw_list->PathLineTo(ImVec2(a.x, b.y) + ImVec2(1, -1));
|
||||
draw_list->PathLineTo(a + ImVec2(1, 1));
|
||||
draw_list->PathLineTo(ImVec2(b.x, a.y) + ImVec2(-1, 1));
|
||||
draw_list->PathStroke(top_left_inner, false, 1.0f);
|
||||
|
||||
draw_list->PathLineTo(ImVec2(a.x, b.y) + ImVec2(1, -1));
|
||||
draw_list->PathLineTo(b + ImVec2(-1, -1));
|
||||
draw_list->PathLineTo(ImVec2(b.x, a.y) + ImVec2(-1, 1));
|
||||
draw_list->PathStroke(bottom_right_inner, false, 1.0f);
|
||||
}
|
||||
|
||||
#ifndef WIN98
|
||||
static void RenderWindowOuterSingleBorder(ImGuiWindow * window, int border_n, ImU32 border_col, float border_size)
|
||||
{
|
||||
const ImGuiResizeBorderDef& def = resize_border_def[border_n];
|
||||
const float rounding = window->WindowRounding;
|
||||
@@ -6202,12 +6247,19 @@ static void RenderWindowOuterSingleBorder(ImGuiWindow* window, int border_n, ImU
|
||||
window->DrawList->PathArcTo(ImLerp(border_r.Min, border_r.Max, def.SegmentN2) + ImVec2(0.5f, 0.5f) + def.InnerDir * rounding, rounding, def.OuterAngle, def.OuterAngle + IM_PI * 0.25f);
|
||||
window->DrawList->PathStroke(border_col, ImDrawFlags_None, border_size);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window)
|
||||
static void ImGui::RenderWindowOuterBorders(ImGuiWindow * window)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
const float border_size = window->WindowBorderSize;
|
||||
const ImU32 border_col = GetColorU32(ImGuiCol_Border);
|
||||
|
||||
#ifdef WIN98 // window borders
|
||||
IM_UNUSED(g);
|
||||
if (border_size > 0.0f && !(window->Flags & ImGuiWindowFlags_NoBackground))
|
||||
WinAddRect(window->Pos, window->Pos + window->Size, false);
|
||||
#else
|
||||
if (border_size > 0.0f && (window->Flags & ImGuiWindowFlags_NoBackground) == 0)
|
||||
window->DrawList->AddRect(window->Pos, window->Pos + window->Size, border_col, window->WindowRounding, 0, window->WindowBorderSize);
|
||||
else if (border_size > 0.0f)
|
||||
@@ -6228,6 +6280,7 @@ static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window)
|
||||
float y = window->Pos.y + window->TitleBarHeight - 1;
|
||||
window->DrawList->AddLine(ImVec2(window->Pos.x + border_size, y), ImVec2(window->Pos.x + window->Size.x - border_size, y), border_col, g.Style.FrameBorderSize);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Draw background and borders
|
||||
@@ -6340,6 +6393,11 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl
|
||||
float pad_l = style.FramePadding.x;
|
||||
float pad_r = style.FramePadding.x;
|
||||
float button_sz = g.FontSize;
|
||||
#ifdef WIN98 // draw title bar
|
||||
button_sz = 16.0f;
|
||||
// pad_l = 0.0f;
|
||||
pad_r = 0.0f;
|
||||
#endif
|
||||
ImVec2 close_button_pos;
|
||||
ImVec2 collapse_button_pos;
|
||||
if (has_close_button)
|
||||
@@ -6358,6 +6416,38 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl
|
||||
pad_l += button_sz + style.ItemInnerSpacing.x;
|
||||
}
|
||||
|
||||
#ifdef WIN98 // windows style title bar
|
||||
|
||||
close_button_pos += ImVec2(0.0f, 2.0f);
|
||||
collapse_button_pos += ImVec2(0.0f, 2.0f);
|
||||
|
||||
ImU32 col_left = IM_COL32(128,128,128,255);
|
||||
ImU32 col_right = IM_COL32(181,181,181,255);
|
||||
|
||||
bool focused = IsWindowFocused(ImGuiFocusedFlags_ChildWindows);
|
||||
if (focused) {
|
||||
|
||||
// Windows98 colors are (0,0,128), (16,132,208)
|
||||
// This code generates the secondary color from the primary while
|
||||
// keeping the original windows colors
|
||||
col_left = GetColorU32(ImGuiCol_TitleBgActive);
|
||||
|
||||
ImVec4 secondary = GetStyleColorVec4(ImGuiCol_TitleBgActive);
|
||||
ImVec4 secondary_hsv;
|
||||
ColorConvertRGBtoHSV(secondary.x, secondary.y, secondary.z, secondary_hsv.x, secondary_hsv.y, secondary_hsv.z);
|
||||
secondary_hsv.x -= 0.1f;
|
||||
if (secondary_hsv.x < 0.0f) secondary_hsv.x += 1.0f;
|
||||
secondary_hsv.y *= 0.92f;
|
||||
secondary_hsv.z *= 1.625f;
|
||||
ColorConvertHSVtoRGB(secondary_hsv.x, secondary_hsv.y, secondary_hsv.z, secondary.x, secondary.y, secondary.z);
|
||||
|
||||
col_right = ColorConvertFloat4ToU32(secondary);
|
||||
}
|
||||
|
||||
|
||||
window->DrawList->AddRectFilledMultiColor(title_bar_rect.Min, title_bar_rect.Max, col_left, col_right, col_right, col_left);
|
||||
#endif
|
||||
|
||||
// Collapse button (submitting first so it gets priority when choosing a navigation init fallback)
|
||||
if (has_collapse_button)
|
||||
if (CollapseButton(window->GetID("#COLLAPSE"), collapse_button_pos))
|
||||
@@ -6390,6 +6480,14 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl
|
||||
pad_r = ImMax(pad_r, pad_extend * centerness);
|
||||
}
|
||||
|
||||
#ifdef WIN98 // windows title font
|
||||
if (focused) PushStyleColor(ImGuiCol_Text, IM_COL32(255,255,255,255));
|
||||
else PushStyleColor(ImGuiCol_Text, IM_COL32(192,192,192,255));
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImFont* font = io.Fonts->Fonts[1]; // Assume the icon font is here. pretty bad
|
||||
PushFont(font);
|
||||
#endif
|
||||
|
||||
ImRect layout_r(title_bar_rect.Min.x + pad_l, title_bar_rect.Min.y, title_bar_rect.Max.x - pad_r, title_bar_rect.Max.y);
|
||||
ImRect clip_r(layout_r.Min.x, layout_r.Min.y, ImMin(layout_r.Max.x + g.Style.ItemInnerSpacing.x, title_bar_rect.Max.x), layout_r.Max.y);
|
||||
if (flags & ImGuiWindowFlags_UnsavedDocument)
|
||||
@@ -6406,6 +6504,11 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl
|
||||
//if (g.IO.KeyShift) window->DrawList->AddRect(layout_r.Min, layout_r.Max, IM_COL32(255, 128, 0, 255)); // [DEBUG]
|
||||
//if (g.IO.KeyCtrl) window->DrawList->AddRect(clip_r.Min, clip_r.Max, IM_COL32(255, 128, 0, 255)); // [DEBUG]
|
||||
RenderTextClipped(layout_r.Min, layout_r.Max, name, NULL, &text_size, style.WindowTitleAlign, &clip_r);
|
||||
|
||||
#ifdef WIN98
|
||||
PopFont();
|
||||
PopStyleColor();
|
||||
#endif
|
||||
}
|
||||
|
||||
void ImGui::UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window)
|
||||
@@ -7119,7 +7222,16 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
|
||||
// Title bar
|
||||
if (!(flags & ImGuiWindowFlags_NoTitleBar))
|
||||
{
|
||||
#ifdef WIN98 // title bar sizing
|
||||
ImRect inset_title_rect = title_bar_rect;
|
||||
inset_title_rect.Min += ImVec2(2.0f, 2.0f);
|
||||
inset_title_rect.Max -= ImVec2(2.0f, 0.0f);
|
||||
RenderWindowTitleBarContents(window, inset_title_rect, name, p_open);
|
||||
#else
|
||||
RenderWindowTitleBarContents(window, ImRect(title_bar_rect.Min.x + window->WindowBorderSize, title_bar_rect.Min.y, title_bar_rect.Max.x - window->WindowBorderSize, title_bar_rect.Max.y), name, p_open);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Clear hit test shape every frame
|
||||
window->HitTestHoleSize.x = window->HitTestHoleSize.y = 0;
|
||||
|
||||
Reference in New Issue
Block a user