-
Автор темы
- #1
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Код:
bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format, bool minimum_damage, float power)
{
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return false;
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID(label);
const float w = CalcItemWidth();
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImRect frame_bb(window->DC.CursorPos + ImVec2(8, 8), window->DC.CursorPos + ImVec2(window->Size.x - 8, 16 + label_size.y + style.FramePadding.y * 2.0f));
const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
ItemSize(total_bb, style.FramePadding.y);
if (!ItemAdd(total_bb, id, &frame_bb))
return false;
ImGuiSliderFlags flags;
if (format == NULL)
format = DataTypeGetInfo(data_type)->PrintFmt;
else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0)
format = PatchFormatStringFloatToInt(format);
const bool hovered = ItemHoverable(frame_bb, id);
const bool temp_input_allowed = (flags & ImGuiSliderFlags_NoInput) == 0;
bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id);
if (!temp_input_is_active)
{
const bool focus_requested = temp_input_allowed && FocusableItemRegister(window, id);
const bool clicked = (hovered && g.IO.MouseClicked[0]);
if (focus_requested || clicked || g.NavActivateId == id || g.NavInputId == id)
{
SetActiveID(id, window);
SetFocusID(id, window);
FocusWindow(window);
g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right);
if (temp_input_allowed && (focus_requested || (clicked && g.IO.KeyCtrl) || g.NavInputId == id))
{
temp_input_is_active = true;
FocusableItemUnregister(window);
}
}
}
if (g_cfg.scripts.developer_mode && ImGui::IsItemHovered())
{
for (auto& item : cfg_manager->items)
{
if (p_data == item->pointer)
{
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8.0f, 6.0f));
ImGui::SetTooltip(item->name.c_str());
ImGui::PopStyleVar();
break;
}
}
}
if (temp_input_is_active)
{
const bool is_clamp_input = (flags & ImGuiSliderFlags_AlwaysClamp) != 0;
return TempInputScalar(frame_bb, id, label, data_type, p_data, format, is_clamp_input ? p_min : NULL, is_clamp_input ? p_max : NULL);
}
float deltatime = 1.5f * ImGui::GetIO().DeltaTime;
static std::map<ImGuiID, float> hover_animation;
auto it_hover = hover_animation.find(id);
if (it_hover == hover_animation.end())
{
hover_animation.insert({ id, 0.f });
it_hover = hover_animation.find(id);
}
it_hover->second = ImClamp(it_hover->second + (2.15f * ImGui::GetIO().DeltaTime * (hovered || IsItemActive() ? 1.f : -1.f)), 0.0f, 1.f);
it_hover->second *= GetStyle().Alpha;
static std::map<ImGuiID, float> filled_animation;
auto it_filled = filled_animation.find(id);
if (it_filled == filled_animation.end())
{
filled_animation.insert({ id, 0.f });
it_filled = filled_animation.find(id);
}
it_filled->second = ImClamp(it_filled->second + (1.15f * ImGui::GetIO().DeltaTime), 0.0f, 1.f);
it_filled->second *= min(GetStyle().Alpha * 1.5, 1.f);
// Draw frame
const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : g.HoveredId == id ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
RenderNavHighlight(frame_bb, id);
window->DrawList->AddRectFilled(ImVec2(frame_bb.Min.x, frame_bb.Min.y + 9), ImVec2(frame_bb.Max.x - 2, frame_bb.Max.y - 3 - 8), ImColor(29, 28, 30, int(255 * GetStyle().Alpha)), 4);
ImRect grab_bb;
const bool value_changed = SliderBehavior(frame_bb, id, data_type, p_data, p_min, p_max, format, power, ImGuiSliderFlags_None, &grab_bb);
if (value_changed)
MarkItemEdited(id);
struct values
{
float new_val = 0.f;
float old_val = 0.f;
};
static std::map<ImGuiID, values> act_anim;
auto it_act = act_anim.find(id);
if (it_act == act_anim.end())
{
act_anim.insert({ id,{ 0.f, frame_bb.Min.x} });
it_act = act_anim.find(id);
}
it_act->second.new_val = grab_bb.Max.x - 1;
if (it_hover->second > 0.001f || IsWindowHovered()) {
if (it_act->second.new_val >= it_act->second.old_val)
{
it_act->second.old_val += (350.f * ImGui::GetIO().DeltaTime);
}
if (it_act->second.new_val <= it_act->second.old_val)
{
it_act->second.old_val -= (350.f * ImGui::GetIO().DeltaTime);
}
}
else
{
it_act->second.old_val = it_act->second.new_val;
}
if (grab_bb.Max.x > grab_bb.Min.x) {
window->DrawList->AddRectFilled(ImVec2(frame_bb.Min.x, frame_bb.Min.y + 9), ImVec2(ImMax((it_act->second.old_val * ImMin(1.f, GetStyle().Alpha)), frame_bb.Min.x - 4), grab_bb.Max.y - 9), ImColor(100 / 255.f, 125 / 255.f, 200 / 255.f, 0.9f * GetStyle().Alpha), 4);
window->DrawList->AddCircleFilled(ImVec2(ImMax((it_act->second.old_val - 4) * ImMin(1.f, GetStyle().Alpha), frame_bb.Min.x - 4), grab_bb.Min.y + 11), 4 + 2 * it_hover->second, ImColor(255 / 255.f, 255 / 255.f, 255 / 255.f, 1 * GetStyle().Alpha), 36);
window->DrawList->AddCircle(ImVec2(ImMax((it_act->second.old_val - 4) * ImMin(1.f, GetStyle().Alpha), frame_bb.Min.x - 4), grab_bb.Min.y + 11), 4 + 2 * it_hover->second, ImColor(200 / 255.f, 200 / 255.f, 200 / 255.f, 1 * GetStyle().Alpha), 36);
}
char value_buf[64];
const char* value_buf_end = value_buf + DataTypeFormatString(value_buf, IM_ARRAYSIZE(value_buf), data_type, p_data, format);
ImGui::PushFont(c_menu::get().g_pMenuFont);
if (g.LogEnabled)
LogSetNextTextDecoration("{", "}");
window->DrawList->AddText(ImVec2(frame_bb.Max.x - 2 - CalcTextSize(value_buf).x, window->DC.CursorPos.y - 32), ImColor(255 / 255.f, 255 / 255.f, 255 / 255.f, 1 * GetStyle().Alpha), value_buf, value_buf_end);
if (label_size.x > 0.0f)
window->DrawList->AddText(ImVec2(window->DC.CursorPos.x + 8, window->DC.CursorPos.y - 32), ImColor(255 / 255.f, 255 / 255.f, 255 / 255.f, 1 * GetStyle().Alpha), label);
Spacing();
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.ItemFlags);
ImGui::PopFont();
return value_changed;
}
Пожалуйста, авторизуйтесь для просмотра ссылки.