- 307
- 218
ВотА что это за элементы ? Дай код
C++:
#define RGBA_TO_FLOAT(r,g,b,a) (float)r/255.0f, (float)g/255.0f, (float)b/255.0f, (float)a/255.0f
void PlayerItem(const char* str_id, bool *online = nullptr, bool *spectate = nullptr)
{
ImVec2 p = ImGui::GetCursorScreenPos();
ImDrawList* draw_list = ImGui::GetWindowDrawList();
float height = ImGui::GetFrameHeight() + 0.001;
float width = ImGui::GetWindowContentRegionWidth() + 0.001 - height / 2;
p.x += height / 2;
ImGui::InvisibleButton(str_id, ImVec2(width, height));
ImGuiContext& g = *GImGui;
float t = ImGui::IsItemHovered() ? 1.0f : 0.0f;
float ANIM_SPEED = 0.00001f;
if (g.LastActiveId == g.CurrentWindow->GetID(str_id))
{
float t_anim = ImSaturate(g.LastActiveIdTimer / ANIM_SPEED);
t = ImGui::IsItemHovered() ? (t_anim) : (1.0f - t_anim);
}
ImU32 col_bg;
const ImVec2 text_size = CalcTextSize(str_id);
col_bg = ImGui::GetColorU32(ImLerp(ImVec4(RGBA_TO_FLOAT(19, 26, 19, 255)), ImVec4(RGBA_TO_FLOAT(15, 40, 15, 255)), t));
draw_list->AddRectFilled(p, ImVec2(p.x + width, p.y + height), col_bg, height * 0.2f);
RenderTextClipped(ImVec2(p.x + height / 2, p.y + (height - text_size.y)/2), ImVec2(p.x + width - height - height / 4, p.y + height / 2 + height / 4), str_id, (const char *)0, &text_size);
if (online != nullptr) {
draw_list->AddCircleFilled(ImVec2(p.x + width - height/2, p.y + height / 2), height / 4, ImGui::GetColorU32(*online ? ImVec4(RGBA_TO_FLOAT(2, 114, 6, 255)) : ImVec4(RGBA_TO_FLOAT(184, 19, 19, 255))));
}
if (spectate != nullptr && *spectate) {
draw_list->AddTriangleFilled(
ImVec2(p.x + width - height - height / 4, p.y + height / 2 + height / 4),
ImVec2(p.x + width - height, p.y + height / 2 - height / 4),
ImVec2(p.x + width - height + height / 4, p.y + height / 2 + height / 4),
ImGui::GetColorU32(ImVec4(RGBA_TO_FLOAT(224, 217, 15, 255))));
}
}
Последнее редактирование: