Гайд Rotated text (ImGui)

  • 140
  • 70
Контакты для связи отсутствуют.
Привет. Код для вращения текста в ImGui.
Помощь : caracusa.
Перед тем кем поставить текст, поставьте ImRotateStart. После текста напишите ImRotationEnd и подберите аргумент
C++:
int rotation_start_index;
void ImRotateStart()
{
    rotation_start_index = ImGui::GetWindowDrawList()->VtxBuffer.Size;
}

ImVec2 ImRotationCenter()
{
    ImVec2 l(FLT_MAX, FLT_MAX), u(-FLT_MAX, -FLT_MAX); // bounds

    const auto& buf = ImGui::GetWindowDrawList()->VtxBuffer;
    for (int i = rotation_start_index; i < buf.Size; i++)
        l = ImMin(l, buf[i].pos), u = ImMax(u, buf[i].pos);

    return ImVec2((l.x+u.x)/2, (l.y+u.y)/2); // or use _ClipRectStack?
}

ImVec2 operator-(const ImVec2& l, const ImVec2& r) { return{ l.x - r.x, l.y - r.y }; }

void ImRotateEnd(float rad, ImVec2 center = ImRotationCenter())
{
    float s=sin(rad), c=cos(rad);
    center = ImRotate(center, s, c) - center;

    auto& buf = ImGui::GetWindowDrawList()->VtxBuffer;
    for (int i = rotation_start_index; i < buf.Size; i++)
        buf[i].pos = ImRotate(buf[i].pos, s, c) - center;
}

void ImRotateDemo()
{
ImRotateStart();
    ImGui::Text("Текст");
    ImRotateEnd(0.005f*::GetTickCount()*!ImGui::IsItemHovered());
}
 
Активность
Пока что здесь никого нет
Сверху Снизу