Код:
const std::string currentDateTime()
{
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%X", &tstruct);
return buf;
}
void Render::Watermark()
{
int screen_w, screen_h;
g_EngineClient->GetScreenSize(screen_w, screen_h);
float m_Framerate = 0.f;
m_Framerate = 0.9 * m_Framerate + (1.0 - 0.9) * g_GlobalVars->absoluteframetime;
if (m_Framerate <= 0.f)
m_Framerate = 1.f;
m_Framerate = (int)(1.0f / m_Framerate) / 10;
float m_AvgLatency = 0.f;
auto netchannel = g_EngineClient->GetNetChannelInfo();
if (netchannel)
{
m_AvgLatency = netchannel->GetAvgLatency(FLOW_OUTGOING);
}
float flAdjust = 0.0f;
if (g_CVar->FindVar("cl_updaterate")->GetFloat() > 0.001f)
{
flAdjust = -0.5f / g_CVar->FindVar("cl_updaterate")->GetFloat();
m_AvgLatency += flAdjust;
}
m_AvgLatency = max(0.f, m_AvgLatency);
flAdjust *= 1000.0f;
if (g_EngineClient->IsPlayingDemo())
m_AvgLatency = 0.0f;
float velocity = 0.f;
if (g_LocalPlayer && g_LocalPlayer->IsAlive())
{
velocity = g_LocalPlayer->m_vecVelocity().Length2D();
}
int tickbase = g_CVar->FindVar("cl_updaterate")->GetInt();
RenderBoxFilled(screen_w - 42, 7, screen_w - 7, 42, Color(0, 0, 60, 220));
RenderBox(screen_w - 42, 7, screen_w - 7, 42, Color(0, 0, 0, 220));
RenderText("F", ImVec2(screen_w - 28, 9), 26.f, Color(235, 5, 90));
RenderBoxFilled(screen_w - 182, 7, screen_w - 47, 42, Color(0, 0, 60, 220));
RenderBox(screen_w - 182, 7, screen_w - 47, 42, Color(0, 0, 0, 220));
ImVec2 fps_value_size = g_WatermarkFont->CalcTextSizeA(14.f, FLT_MAX, 0.0f, std::to_string((int)m_Framerate).c_str());
ImVec2 fps_text_size = g_WatermarkFont->CalcTextSizeA(12.f, FLT_MAX, 0.0f, "fps");
RenderText(std::to_string((int)m_Framerate), ImVec2(screen_w - 167 + fps_text_size.x / 2 - fps_value_size.x / 2, 12), 14.f, Color(147, 176, 58));
RenderText("fps", ImVec2(screen_w - 167, 26), 12.f, Color(235, 235, 235));
ImVec2 ping_value_size = g_WatermarkFont->CalcTextSizeA(14.f, FLT_MAX, 0.0f, std::to_string((int)m_AvgLatency).c_str());
ImVec2 ping_text_size = g_WatermarkFont->CalcTextSizeA(12.f, FLT_MAX, 0.0f, "ping");
RenderText(std::to_string((int)m_AvgLatency).c_str(), ImVec2(screen_w - 144 + ping_text_size.x / 2 - ping_value_size.x / 2, 12), 14.f, Color(147, 176, 58));
RenderText("ping", ImVec2(screen_w - 144, 26), 12.f, Color(235, 235, 235));
ImVec2 speed_value_size = g_WatermarkFont->CalcTextSizeA(14.f, FLT_MAX, 0.0f, std::to_string((int)velocity).c_str());
ImVec2 speed_text_size = g_WatermarkFont->CalcTextSizeA(12.f, FLT_MAX, 0.0f, "speed");
RenderText(std::to_string((int)velocity), ImVec2(screen_w - 112 + speed_text_size.x / 2 - speed_value_size.x / 2, 12), 14.f, Color(147, 176, 58));
RenderText("speed", ImVec2(screen_w - 112, 26), 12.f, Color(235, 235, 235));
ImVec2 tick_value_size = g_WatermarkFont->CalcTextSizeA(14.f, FLT_MAX, 0.0f, std::to_string(tickbase).c_str());
ImVec2 tick_text_size = g_WatermarkFont->CalcTextSizeA(12.f, FLT_MAX, 0.0f, "tick");
RenderText(std::to_string(tickbase), ImVec2(screen_w - 74 + tick_text_size.x / 2 - tick_value_size.x / 2, 12), 14.f, Color(147, 176, 58));
RenderText("tick", ImVec2(screen_w - 74, 26), 12.f, Color(235, 235, 235));
RenderBoxFilled(screen_w - 266, 7, screen_w - 186, 42, Color(0, 0, 60, 220));
RenderBox(screen_w - 266, 7, screen_w - 186, 42, Color(0, 0, 0, 220));
ImVec2 time_value_size = g_WatermarkFont->CalcTextSizeA(14.f, FLT_MAX, 0.0f, currentDateTime().c_str());
ImVec2 time_text_size = g_WatermarkFont->CalcTextSizeA(12.f, FLT_MAX, 0.0f, "current time");
RenderText(currentDateTime(), ImVec2(screen_w - 255 + time_text_size.x / 2 - time_value_size.x / 2, 12), 14.f, Color(147, 176, 58));
RenderText("current time", ImVec2(screen_w - 255, 26), 12.f, Color(235, 235, 235));
}