MCPcopy Create free account
hub / github.com/ddnet/ddnet / RenderTime

Method RenderTime

src/game/client/ui.cpp:1568–1621  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1566}
1567
1568void CUi::RenderTime(CUIRect TimeRect, float FontSize, int Seconds, bool NotFinished, int Millis, bool TrueMilliseconds) const
1569{
1570 if(NotFinished)
1571 return;
1572
1573 char aBuf[128];
1574
1575 str_time(((int64_t)absolute(Seconds)) * 100, TIME_HOURS, aBuf, sizeof(aBuf));
1576
1577 // align in vertical middle
1578 vec2 Cursor = TimeRect.TopLeft();
1579 float TextHeight = 0.0f;
1580 float SecondsMaxHeight = 0.0f;
1581 STextSizeProperties TextSizeProps{};
1582 TextSizeProps.m_pMaxCharacterHeightInLine = &SecondsMaxHeight;
1583 TextSizeProps.m_pHeight = &TextHeight;
1584
1585 float SecondsWidth = std::min(TextRender()->TextWidth(FontSize, aBuf, -1, -1.0f, 0, TextSizeProps), TimeRect.w);
1586 Cursor.x += TimeRect.w - SecondsWidth; // align right
1587 Cursor.y += ((TimeRect.h - SecondsMaxHeight) / 2.0f - (FontSize - SecondsMaxHeight));
1588
1589 // show milliseconds or centiseconds if we are under an hour
1590 if(Millis >= 0 && Seconds < 60 * 60)
1591 {
1592 constexpr float GoldenRatio = 0.61803398875f;
1593 const float CentisecondFontSize = FontSize * GoldenRatio;
1594
1595 // format 2 or 3 digits
1596 char aMillis[4];
1597 Millis %= 1000;
1598 if(!TrueMilliseconds)
1599 str_format(aMillis, sizeof(aMillis), "%02d", (int)std::round(Millis / 10));
1600 else
1601 str_format(aMillis, sizeof(aMillis), "%03d", Millis);
1602
1603 float MillisWidth = TextRender()->TextWidth(CentisecondFontSize, aMillis, -1, -1.0f, 0, TextSizeProps);
1604
1605 // make space for millis, but put them 1/6th of a char tighter together
1606 Cursor.x -= MillisWidth - (TrueMilliseconds ? MillisWidth / (3 * 6) : MillisWidth / (2 * 6));
1607
1608 vec2 CursorMillis = TimeRect.TopLeft();
1609 CursorMillis.x += TimeRect.w - MillisWidth; // align right
1610 CursorMillis.y += ((TimeRect.h - SecondsMaxHeight) / 2.0f - (CentisecondFontSize - SecondsMaxHeight));
1611 CursorMillis.y -= (CursorMillis.y - Cursor.y) * GoldenRatio;
1612
1613 TextRender()->Text(Cursor.x, Cursor.y, FontSize, aBuf);
1614 TextRender()->Text(CursorMillis.x, CursorMillis.y, CentisecondFontSize, aMillis);
1615 }
1616 else
1617 {
1618 str_time(((int64_t)absolute(Seconds)) * 100, TIME_HOURS, aBuf, sizeof(aBuf));
1619 TextRender()->Text(Cursor.x, Cursor.y, FontSize, aBuf);
1620 }
1621}
1622
1623void CUi::RenderProgressSpinner(vec2 Center, float OuterRadius, const SProgressSpinnerProperties &Props) const
1624{

Callers 2

RenderTitleScoreMethod · 0.80
RenderScoreboardMethod · 0.80

Calls 7

str_timeFunction · 0.85
absoluteFunction · 0.85
TextRenderFunction · 0.85
str_formatFunction · 0.85
TopLeftMethod · 0.80
TextWidthMethod · 0.80
TextMethod · 0.80

Tested by

no test coverage detected