Исходник Rect With Radial Gradient ImGui

Эксперт
Статус
Оффлайн
Регистрация
14 Июл 2019
Сообщения
1,100
Реакции[?]
496
Поинты[?]
31K
C++:
void ImDrawList::AddRectRadial(const ImVec2& p_min, const ImVec2& p_max, ImU32 center, ImU32 edge, float rounding, ImU32 background, ImDrawFlags flags)
{
    rounding = ImMin(rounding, ImFabs(p_max.x - p_min.x) * (((flags & ImDrawCornerFlags_Top) == ImDrawCornerFlags_Top) || ((flags & ImDrawCornerFlags_Bot) == ImDrawCornerFlags_Bot) ? 0.5f : 1.0f) - 1.0f);
    rounding = ImMin(rounding, ImFabs(p_max.y - p_min.y) * (((flags & ImDrawCornerFlags_Left) == ImDrawCornerFlags_Left) || ((flags & ImDrawCornerFlags_Right) == ImDrawCornerFlags_Right) ? 0.5f : 1.0f) - 1.0f);

    PushClipRect(p_min, p_max);

    
    float raduis = (p_max.x - p_min.x) / 2 > (p_max.y - p_min.y) / 2 ? (p_max.x - p_min.x) / 2 * 1.5f : (p_max.y - p_min.y) / 2 * 1.5f;
    _PathArcToFastEx(ImVec2((p_min.x + p_max.x) / 2, (p_min.y + p_max.y) / 2), raduis, 0, IM_DRAWLIST_ARCFAST_SAMPLE_MAX, 0);


    const int count = _Path.Size - 1;

    unsigned int vtx_base = _VtxCurrentIdx;
    PrimReserve(count * 3, count + 1);

    const ImVec2 uv = _Data->TexUvWhitePixel;
    PrimWriteVtx(ImVec2((p_min.x + p_max.x) / 2, (p_min.y + p_max.y) / 2), uv, center);
    for (int n = 0; n < count; n++)
        PrimWriteVtx(_Path[n], uv, edge);

    for (int n = 0; n < count; n++)
    {
        PrimWriteIdx((ImDrawIdx)(vtx_base));
        PrimWriteIdx((ImDrawIdx)(vtx_base + 1 + n));
        PrimWriteIdx((ImDrawIdx)(vtx_base + 1 + ((n + 1) % count)));
    }
    _Path.Size = 0;
    PopClipRect();

    if (rounding > 0.0f)
    {
        const float rounding_tl = (flags & ImDrawCornerFlags_TopLeft) ? rounding : 0.0f;
        const float rounding_tr = (flags & ImDrawCornerFlags_TopRight) ? rounding : 0.0f;
        const float rounding_br = (flags & ImDrawCornerFlags_BotRight) ? rounding : 0.0f;
        const float rounding_bl = (flags & ImDrawCornerFlags_BotLeft) ? rounding : 0.0f;

        PathLineTo(p_min);
        PathArcTo(ImVec2(p_min.x + rounding_tl, p_min.y + rounding_tl), rounding_tl, 4.820f, 3.100f);
        PathFillConvex(background);

        PathLineTo(ImVec2(p_max.x, p_min.y));
        PathArcTo(ImVec2(p_max.x - rounding_tr, p_min.y + rounding_tr), rounding_tr, 6.3400f, 4.620f);
        PathFillConvex(background);

        PathLineTo(ImVec2(p_max.x, p_max.y));
        PathArcTo(ImVec2(p_max.x - rounding_br, p_max.y - rounding_br), rounding_br, 7.960f, 6.240f);
        PathFillConvex(background);

        PathLineTo(ImVec2(p_min.x, p_max.y));
        PathArcTo(ImVec2(p_min.x + rounding_bl, p_max.y - rounding_bl), rounding_bl, 9.5f, 7.770f);
        PathFillConvex(background);
    }
}
1663346337597.png
 
Последнее редактирование:
Сверху Снизу