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

Method RenderSwitchOverlay

src/game/map/render_map.cpp:898–954  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

896}
897
898void CRenderMap::RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float Scale, int OverlayRenderFlag, float Alpha)
899{
900 if(!(OverlayRenderFlag & OVERLAYRENDERFLAG_TEXT))
901 return;
902
903 float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
904 Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
905
906 int StartY = (int)(ScreenY0 / Scale) - 1;
907 int StartX = (int)(ScreenX0 / Scale) - 1;
908 int EndY = (int)(ScreenY1 / Scale) + 1;
909 int EndX = (int)(ScreenX1 / Scale) + 1;
910
911 if(EndX - StartX > Graphics()->ScreenWidth() / g_Config.m_GfxTextOverlay || EndY - StartY > Graphics()->ScreenHeight() / g_Config.m_GfxTextOverlay)
912 return; // its useless to render text at this distance
913
914 float Size = g_Config.m_ClTextEntitiesSize / 100.f;
915 float ToCenterOffset = (1 - Size) / 2.f;
916 char aBuf[16];
917
918 TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
919 for(int y = StartY; y < EndY; y++)
920 {
921 for(int x = StartX; x < EndX; x++)
922 {
923 int mx = x;
924 int my = y;
925
926 if(mx < 0)
927 continue; // mx = 0;
928 if(mx >= w)
929 continue; // mx = w-1;
930 if(my < 0)
931 continue; // my = 0;
932 if(my >= h)
933 continue; // my = h-1;
934
935 int c = mx + my * w;
936
937 unsigned char Index = pSwitch[c].m_Number;
938 if(Index && IsSwitchTileNumberUsed(pSwitch[c].m_Type))
939 {
940 str_format(aBuf, sizeof(aBuf), "%d", Index);
941 TextRender()->Text(mx * Scale, (my + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf);
942 }
943
944 unsigned char Delay = pSwitch[c].m_Delay;
945 if(Delay && IsSwitchTileDelayUsed(pSwitch[c].m_Type))
946 {
947 str_format(aBuf, sizeof(aBuf), "%d", Delay);
948 TextRender()->Text(mx * Scale, (my + 0.5f + ToCenterOffset / 2) * Scale, Size * Scale / 2.f, aBuf);
949 }
950 }
951 }
952 TextRender()->TextColor(TextRender()->DefaultTextColor());
953 Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
954}
955

Callers 2

RenderMethod · 0.80

Calls 12

GraphicsFunction · 0.85
TextRenderFunction · 0.85
IsSwitchTileNumberUsedFunction · 0.85
str_formatFunction · 0.85
IsSwitchTileDelayUsedFunction · 0.85
GetScreenMethod · 0.80
ScreenWidthMethod · 0.80
ScreenHeightMethod · 0.80
TextColorMethod · 0.80
TextMethod · 0.80
DefaultTextColorMethod · 0.80
MapScreenMethod · 0.45

Tested by

no test coverage detected