Исходник Multicolor loading circle

Stop Staring At the Shadows
Участник
Участник
Статус
Оффлайн
Регистрация
10 Окт 2020
Сообщения
535
Реакции
508
1662834773153.png
Большинству больше всего понравился мультиколор круг (в моём прошлом посте) - выкладываю его вам.
В шапке всё понятно, есть 2 разные анимации, на этом всё, как изменить цвета под себя поймёт даже ребёнок (в прототип не добавлял, было впадлу :roflanEbalo:)
По коду понятно что он кликабелен и всё остальное, короче делайте с ним че ваша душа пожелает.

imgui_widgets.cpp:
Expand Collapse Copy
bool ImGui::Loading(const char* itemid, float radius, int thickness, int multicoloralpha, const ImU32& darkcolor, ImDrawList* drawlist, CircleAnimBase flags) {

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

    ImVec2 hue_wheel_center(GetIO().DisplaySize.x / 2.f, GetIO().DisplaySize.y / 2.f);
    const ImGuiID id = window->GetID(itemid);

    const ImRect bb(ImVec2(hue_wheel_center.x - radius, hue_wheel_center.y - radius), ImVec2(hue_wheel_center.x + radius, hue_wheel_center.y + radius));
    ItemSize(bb, -1);
    if (!ItemAdd(bb, id))
        return false;


    const ImU32 hue_wheel[6 + 1] = { ImColor(30,50,195,255), ImColor(255,20,60,255), ImColor(0,65,255,255), ImColor(0,155,255,255), ImColor(255,145,0,255), ImColor(101,50,255,255), ImColor(30,50,195,255) };
    const ImU32 col_white = ImColor(255, 255, 255, multicoloralpha);
    const float aeps = 0.5f / (radius / 2.f);
    const int segmentation = ImMax(4, 512);
    for (int i = 0; i < 6; i++)
    {
        const float a0 = (i) / 6.0f * 2.0f * IM_PI - aeps;
        const float a1 = (i + 1.0f) / 6.0f * 2.0f * IM_PI + aeps;
        const int buff_start_idx = drawlist->VtxBuffer.Size;
        drawlist->PathArcTo(hue_wheel_center, radius, a0, a1, segmentation);
        drawlist->PathStroke(col_white, 0, thickness - 1);
        const int buff_end_idx = drawlist->VtxBuffer.Size;

        // Переливание пикселей при помощи ShadeVerts
        ImVec2 gradient_p0(hue_wheel_center.x + ImCos(a0) * radius, hue_wheel_center.y + ImSin(a0) * radius);
        ImVec2 gradient_p1(hue_wheel_center.x + ImCos(a1) * radius, hue_wheel_center.y + ImSin(a1) * radius);
        ShadeVertsLinearColorGradientKeepAlpha(drawlist, buff_start_idx, buff_end_idx, gradient_p0, gradient_p1, hue_wheel[i], hue_wheel[i + 1]);
    }


    static float position = 0.f;
    position = ImLerp(position, IM_PI * 1.7f, 0.01);

    if (flags == CircleAnimBase_Adjusted)
    {
        drawlist->PathClear();
        drawlist->PathArcTo(hue_wheel_center, radius, IM_PI * 2.f + (position * 3.8f), IM_PI * 3.8f + (position * 3.9f), 40.f);
        drawlist->PathStroke(darkcolor, 0, thickness + 1);
    }
    if (flags == CircleAnimBase_Default)
    {
        drawlist->PathClear();
        drawlist->PathArcTo(hue_wheel_center, radius, IM_PI * 2.5f + (position * 2.5f), IM_PI * (3.35f + 0.45F) + (position * 2.6f), 40.f);
        drawlist->PathStroke(darkcolor, 0, thickness + 1);
    }

    //Reset anim
    if (position >= IM_PI * 1.5f)
        position = -0.16f;
}
imgui.h:
Expand Collapse Copy
enum CircleAnimBase_
{
    CircleAnimBase_Default = 0,
    CircleAnimBase_Adjusted = 1
};
imgui.h:
Expand Collapse Copy
typedef int CircleAnimBase; // -> enum CircleAnimBase // Flags: for CircleLoad function
initialize:
Expand Collapse Copy
Loading("##loader", 90, 4, 255, ImColor(23, 23, 23, 255), GetForegroundDrawList(), CircleAnimBase_Adjusted);
 
thx release +rep
 
Посмотреть вложение 220495
Большинству больше всего понравился мультиколор круг (в моём прошлом посте) - выкладываю его вам.
В шапке всё понятно, есть 2 разные анимации, на этом всё, как изменить цвета под себя поймёт даже ребёнок (в прототип не добавлял, было впадлу :roflanEbalo:)
По коду понятно что он кликабелен и всё остальное, короче делайте с ним че ваша душа пожелает.

imgui_widgets.cpp:
Expand Collapse Copy
bool ImGui::Loading(const char* itemid, float radius, int thickness, int multicoloralpha, const ImU32& darkcolor, ImDrawList* drawlist, CircleAnimBase flags) {

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

    ImVec2 hue_wheel_center(GetIO().DisplaySize.x / 2.f, GetIO().DisplaySize.y / 2.f);
    const ImGuiID id = window->GetID(itemid);

    const ImRect bb(ImVec2(hue_wheel_center.x - radius, hue_wheel_center.y - radius), ImVec2(hue_wheel_center.x + radius, hue_wheel_center.y + radius));
    ItemSize(bb, -1);
    if (!ItemAdd(bb, id))
        return false;


    const ImU32 hue_wheel[6 + 1] = { ImColor(30,50,195,255), ImColor(255,20,60,255), ImColor(0,65,255,255), ImColor(0,155,255,255), ImColor(255,145,0,255), ImColor(101,50,255,255), ImColor(30,50,195,255) };
    const ImU32 col_white = ImColor(255, 255, 255, multicoloralpha);
    const float aeps = 0.5f / (radius / 2.f);
    const int segmentation = ImMax(4, 512);
    for (int i = 0; i < 6; i++)
    {
        const float a0 = (i) / 6.0f * 2.0f * IM_PI - aeps;
        const float a1 = (i + 1.0f) / 6.0f * 2.0f * IM_PI + aeps;
        const int buff_start_idx = drawlist->VtxBuffer.Size;
        drawlist->PathArcTo(hue_wheel_center, radius, a0, a1, segmentation);
        drawlist->PathStroke(col_white, 0, thickness - 1);
        const int buff_end_idx = drawlist->VtxBuffer.Size;

        // Переливание пикселей при помощи ShadeVerts
        ImVec2 gradient_p0(hue_wheel_center.x + ImCos(a0) * radius, hue_wheel_center.y + ImSin(a0) * radius);
        ImVec2 gradient_p1(hue_wheel_center.x + ImCos(a1) * radius, hue_wheel_center.y + ImSin(a1) * radius);
        ShadeVertsLinearColorGradientKeepAlpha(drawlist, buff_start_idx, buff_end_idx, gradient_p0, gradient_p1, hue_wheel[i], hue_wheel[i + 1]);
    }


    static float position = 0.f;
    position = ImLerp(position, IM_PI * 1.7f, 0.01);

    if (flags == CircleAnimBase_Adjusted)
    {
        drawlist->PathClear();
        drawlist->PathArcTo(hue_wheel_center, radius, IM_PI * 2.f + (position * 3.8f), IM_PI * 3.8f + (position * 3.9f), 40.f);
        drawlist->PathStroke(darkcolor, 0, thickness + 1);
    }
    if (flags == CircleAnimBase_Default)
    {
        drawlist->PathClear();
        drawlist->PathArcTo(hue_wheel_center, radius, IM_PI * 2.5f + (position * 2.5f), IM_PI * (3.35f + 0.45F) + (position * 2.6f), 40.f);
        drawlist->PathStroke(darkcolor, 0, thickness + 1);
    }

    //Reset anim
    if (position >= IM_PI * 1.5f)
        position = -0.16f;
}
imgui.h:
Expand Collapse Copy
enum CircleAnimBase_
{
    CircleAnimBase_Default = 0,
    CircleAnimBase_Adjusted = 1
};
imgui.h:
Expand Collapse Copy
typedef int CircleAnimBase; // -> enum CircleAnimBase // Flags: for CircleLoad function
initialize:
Expand Collapse Copy
Loading("##loader", 90, 4, 255, ImColor(23, 23, 23, 255), GetForegroundDrawList(), CircleAnimBase_Adjusted);
Че делать, если он только в верхнем углу работает? SetCursorPos не помогает
 
Назад
Сверху Снизу