Загрузка...

Checkboxes on imgui

Thread in C/C++ created by billiedark Oct 22, 2021. 549 views

  1. billiedark
    billiedark Topic starter Oct 22, 2021 разработка на заказ: lolz.live/threads/8957669/ 2296 Dec 7, 2018
    [IMG]
    Code
    bool ImGui :: Checkbox (const char * label, bool * v)
    {
    ImGuiWindow * window = GetCurrentWindow ();
    if (window-> SkipItems)
    return false;
    ImGuiContext & g = * GImGui;
    const ImGuiStyle & style = ImGuiStyle :: ImGuiStyle ();
    const ImGuiID id = window-> GetID (label);
    const ImVec2 label_size = CalcTextSize (label, NULL, true);
    const ImVec2 pading = ImVec2 (2, 2);
    const ImRect check_bb (window-> DC.CursorPos, window-> DC.CursorPos + ImVec2 (label_size.y + style.FramePadding.x * 6, label_size.y + style.FramePadding.y / 2));
    ItemSize (check_bb, style.FramePadding.y);
    ImRect total_bb = check_bb;
    if (label_size.x> 0)
    SameLine (0, style.ItemInnerSpacing.x);
    const ImRect text_bb (window-> DC.CursorPos + ImVec2 (0, style.FramePadding.y), window-> DC.CursorPos + ImVec2 (0, style.FramePadding.y) + label_size);
    if (label_size.x> 0)
    {
    ItemSize (ImVec2 (text_bb.GetWidth (), check_bb.GetHeight ()), style.FramePadding.y);
    total_bb = ImRect (ImMin (check_bb.Min, text_bb.Min), ImMax (check_bb.Max, text_bb.Max));
    }
    if (! ItemAdd (total_bb, & id))
    return false;
    bool hovered, held;
    bool pressed = ButtonBehavior (total_bb, id, & hovered, & held);
    if (pressed)
    * v =! (* v);
    const float check_sz = ImMin (check_bb.GetWidth (), check_bb.GetHeight ());
    const float check_sz2 = check_sz / 2;
    const float pad = ImMax (1.0f, (float) (int) (check_sz / 4.f));
    //window-> DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2 (pad, pad), GetColorU32 (ImGuiCol_CheckMark), style.FrameRounding);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 + 6, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.20) f, 0.25f, 0.30f, 1.0f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 + 5, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.20 f, 0.25f, 0.30f, 1.0f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 + 4, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.20) f, 0.25f, 0.30f, 1.0f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 + 3, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.20) f, 0.25f, 0.30f, 1.0f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 + 2, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.20) f, 0.25f, 0.30f, 1.0f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 + 1, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.20) f, 0.25f, 0.30f, 1.0f)), 12);
    window, drawList-> AddCircleFilled (ImVec2 (check_bb.Min.x) / 2, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.20f, 0.25f, 0.30f, 1.0f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x - check_bb.Min.x) / 2 - 1, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.20 f, 0.25f, 0.30f, 1.0f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x - check_bb.Min.x) / 2 - 2, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.20) f, 0.25f, 0.30f, 1.0f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x - check_bb.Min.x) / 2 - 3, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.20 f, 0.25f, 0.30f, 1.0f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 - 4, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.20 f, 0.25f, 0.30f, 1.0f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 - 5, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.20) f, 0.25f, 0.30f, 1.0f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x - check_bb.Min.x) / 2 - 6, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.20 f, 0.25f, 0.30f, 1.0f)), 12);
    if (* v)
    {
    //window-> DrawList- >AddRectFilled(ImVec2(check_bb.Min.x + / (check_bb.Max.x - check_bb.Min.x) / 2, check_bb.Min.y), check_bb.Max, GetColorU32 (ImVec4 (0.34 f, 1.0f, 0.54f, 1.0f), 0);
    //window-> DrawList- >AddRectFilled(ImVec2(check_bb.Min.x + / (check_bb.Max.x - check_bb.Min.x) / 2, check_bb.Min.y), check_bb.Max, GetColorU32 (ImVec4 (0.34 f, 1.0f, 0.54f, 1.0f), 0);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 + 6, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.71) f, 0.18f, 0.29f, 1.00f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 + 5, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.71) f, 0.18f, 0.29f, 1.00f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 + 4, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.71) f, 0.18f, 0.29f, 1.00f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 + 3, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.71) f, 0.18f, 0.29f, 1.00f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 + 2, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.71) f, 0.18f, 0.29f, 1.00f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 + 1, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.71) f, 0.18f, 0.29f, 1.00f)), 12);
    window, drawList-> AddCircleFilled (ImVec2 (check_bb.Min.x) / 2, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.71f, 0.18f, 0.29f, 1.00f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x - check_bb.Min.x) / 2 - 1, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.71) f, 0.18f, 0.29f, 1.00f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x) / 2 - 2, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.71) f, 0.18f, 0.29f, 1.00f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x - check_bb.Min.x) / 2 - 3, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.71) f, 0.18f, 0.29f, 1.00f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 - 4, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.71) f, 0.18f, 0.29f, 1.00f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x - check_bb.Min.x) / 2 - 5, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.71) f, 0.18f, 0.29f, 1.00f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 - 6, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (0.71) f, 0.18f, 0.29f, 1.00f)), 12);
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 + 6, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (1.0 f, 1.0f, 1.0f, 1.0f), 12);
    }
    else
    {
    window-> DrawList-> AddCircleFilled (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2 - 6, check_bb.Min.y + 9), 7, GetColorU32 (ImVec4 (1.0 f, 1.0f, 1.0f, 1.0f), 12);
    }
    if (label_size.x> 0.0f)
    RenderText (text_bb.GetTL (), label);
    return pressed;
    }

    [IMG]
    Code
    bool ImGui :: Checkbox (const char * label, bool * v)
    {
    ImGuiWindow * window = GetCurrentWindow ();
    if (window-> SkipItems)
    return false;

    ImGuiContext & g = * GImGui;
    const ImGuiStyle & style = g.Style;
    const ImGuiID id = window-> GetID (label);
    const ImVec2 label_size = CalcTextSize (label, NULL, true);

    const ImRect check_bb (window-> DC.CursorPos, window-> DC.CursorPos + ImVec2 (label_size.y + style.FramePadding.y * 2, label_size.y + style.FramePadding.y * 2));
    ItemSize (check_bb, style.FramePadding.y);

    ImRect total_bb = check_bb;
    if (label_size.x> 0)
    SameLine (0, style.ItemInnerSpacing.x);
    const ImRect text_bb (window-> DC.CursorPos + ImVec2 (0, style.FramePadding.y), window-> DC.CursorPos + ImVec2 (0, style.FramePadding.y) + label_size);
    if (label_size.x> 0)
    {
    ItemSize (ImVec2 (text_bb.GetWidth (), check_bb.GetHeight ()), style.FramePadding.y);
    total_bb = ImRect (ImMin (check_bb.Min, text_bb.Min), ImMax (check_bb.Max, text_bb.Max));
    }

    if (! ItemAdd (total_bb, & id))
    return false;

    bool hovered, held;
    bool pressed = ButtonBehavior (total_bb, id, & hovered, & held);
    if (pressed)
    * v =! (* v);

    RenderFrame (check_bb.Min, check_bb.Max, GetColorU32 ((held && hovered)? ImGuiCol_FrameBgActive: hovered? ImGuiCol_FrameBgHovered: ImGuiCol_FrameBg), true, style.FrameRounding);
    if (* v)
    {
    const float check_sz = ImMin (check_bb.GetWidth (), check_bb.GetHeight ());
    const float pad = ImMax (1.0f, (float) (int) (check_sz / 6.0f));
    window-> DrawList-> AddRectFilled (check_bb.Min + ImVec2 (pad, pad), check_bb.Max-ImVec2 (pad, pad), GetColorU32 (ImGuiCol_CheckMark), style.FrameRounding);
    }

    if (g.LogEnabled)
    LogRenderedText (text_bb.GetTL (), * v? "[X]": "[]");
    if (label_size.x> 0.0f)
    RenderText (text_bb.GetTL (), label);

    return pressed;
    }

    [IMG]
    Code
    bool ImGui :: Checkbox (const char * label, bool * v)
    {
    ImGuiWindow * window = GetCurrentWindow ();
    if (window-> SkipItems)
    return false;

    ImGuiContext & g = * GImGui;
    const ImGuiStyle & style = g.Style;
    const ImGuiID id = window-> GetID (label);
    const ImVec2 label_size = CalcTextSize (label, NULL, true);

    const ImRect check_bb (window-> DC.CursorPos, window-> DC.CursorPos + ImVec2 (label_size.y + style.FramePadding.y * 2, label_size.y + style.FramePadding.y * 2));
    ItemSize (check_bb, style.FramePadding.y);

    ImRect total_bb = check_bb;
    if (label_size.x> 0)
    SameLine (0, style.ItemInnerSpacing.x);
    const ImRect text_bb (window-> DC.CursorPos + ImVec2 (0, style.FramePadding.y), window-> DC.CursorPos + ImVec2 (0, style.FramePadding.y) + label_size);
    if (label_size.x> 0)
    {
    ItemSize (ImVec2 (text_bb.GetWidth (), check_bb.GetHeight ()), style.FramePadding.y);
    total_bb = ImRect (ImMin (check_bb.Min, text_bb.Min), ImMax (check_bb.Max, text_bb.Max));
    }

    if (! ItemAdd (total_bb, & id))
    return false;

    bool hovered, held;
    bool pressed = ButtonBehavior (total_bb, id, & hovered, & held);
    if (pressed)
    * v =! (* v);

    RenderFrame (check_bb.Min, check_bb.Max, GetColorU32 ((held && hovered)? ImGuiCol_FrameBgActive: hovered? ImGuiCol_FrameBgHovered: ImGuiCol_FrameBg), true, style.FrameRounding);
    if (* v) // botão modificado
    {
    window) DrawList-> AddRectFilled (ImVec2 (check_bb.Min.x) / 2, check_bb.Min.y), check_bb.Max, GetColorU32 (ImGuiCol_CheckMark), 0) ;
    window, click on the right mouse button and drag it to the bottom of the window. Draw-> AddRect (ImVec2 (check_bb.Min.x + / check_bb.Max.x-check_bb.Min.x) / 2, check_bb.Min.y), check_bb.Max, GetColorU32 (ImGuiCol_Border), 0, -12);
    }
    else
    {
    window-> DrawList-> AddRectFilled (ImVec2 (check_bb.Min.x, check_bb.Min.y), ImVec2 (check_bb.Min.x + (check_bb.Max.x-check_bb.Min.x) / 2, check_bb.Max .y), GetColorU32 (ImGuiCol_CheckMark), 0);
    window-> DrawList-> AddRect (ImVec2 (check_bb.Min.x, check_bb.Min.y), ImVec2 (check_bb.Min.x + (check_bb.Max.x-check_bb.Min.x) / 2, check_bb.Max .y), GetColorU32 (ImGuiCol_Border), 0);
    }

    if (g.LogEnabled)
    LogRenderedText (text_bb.GetTL (), * v? "[X]": "[]");
    if (label_size.x> 0.0f)
    RenderText (text_bb.GetTL (), label);

    return pressed;
    }

    [IMG]
    Code
    bool ImGui :: Checkbox (const char * label, bool * v)

    {
    ImGuiWindow * window = GetCurrentWindow ();
    if (window-> SkipItems)
    return false;

    ImGuiContext & g = * GImGui;
    const ImGuiStyle & style = g.Style;
    const ImGuiID id = window-> GetID (label);
    const ImVec2 label_size = CalcTextSize (label, NULL, true);

    const ImRect check_bb (window-> DC.CursorPos, window-> DC.CursorPos + ImVec2 (label_size.y + style.FramePadding.y * 0.5, label_size.y + style.FramePadding.y * 0.5));
    ItemSize (check_bb, style.FramePadding.y);

    ImRect total_bb = check_bb;
    if (label_size.x> 0)
    SameLine (0, style.ItemInnerSpacing.x);
    const ImRect text_bb (window-> DC.CursorPos + ImVec2 (0, style.FramePadding.y) - ImVec2 (0, 2), window-> DC.CursorPos + ImVec2 (0, style.FramePadding.y) + label_size);
    if (label_size.x> 0)
    {
    ItemSize (ImVec2 (text_bb.GetWidth (), check_bb.GetHeight ()), style.FramePadding.y);
    total_bb = ImRect (ImMin (check_bb.Min, text_bb.Min), ImMax (check_bb.Max, text_bb.Max));
    }

    if (! ItemAdd (total_bb, & id))
    return false;

    bool hovered, held;
    bool pressed = ButtonBehavior (total_bb, id, & hovered, & held);
    if (pressed)
    * v =! (* v);

    RenderFrame (check_bb.Min, check_bb.Max, GetColorU32 ((held && hovered)? ImGuiCol_FrameBgActive: hovered? ImGuiCol_FrameBgHovered: ImGuiCol_FrameBg), true, style.FrameRounding);
    if (* v)
    {
    const float check_sz = ImMin (check_bb.GetWidth (), check_bb.GetHeight ());
    const float pad = ImMax (1.0f, (float) (int) (check_sz / 6.0f));
    const ImVec2 pts [] = {
    ImVec2 {check_bb.Min.x + pad, check_bb.Min.y + ((check_bb.Max.y - check_bb.Min.y) / 2)},
    ImVec2 {check_bb.Min.x + ((check_bb.Max.x - check_bb.Min.x) / 3), check_bb.Max.y - pad * 1.5f},
    ImVec2 {check_bb.Max.x - pad, check_bb.Min.y + pad}
    };};
    window-> DrawList-> AddPolyline (pts, 3, GetColorU32 (ImGuiCol_CheckMark), false, 2.0f, true);
    }

    if (g.LogEnabled)
    LogRenderedText (text_bb.GetTL (), * v? "[X]": "[]");
    if (label_size.x> 0.0f)
    RenderText (text_bb.GetTL (), label);

    return pressed;
    }
     
Top
Loading...