MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / drawFPS

Function drawFPS

src/OpenLoco/src/Graphics/FPSCounter.cpp:37–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35 }
36
37 void drawFPS(DrawingContext& drawingCtx)
38 {
39 auto tr = Gfx::TextRenderer(drawingCtx);
40
41 // Measure FPS
42 const float fps = measureFPS();
43
44 // Format string
45 char buffer[64];
46 buffer[0] = ControlCodes::Font::bold;
47 buffer[1] = ControlCodes::Font::outline;
48 buffer[2] = ControlCodes::Colour::white;
49
50 const char* formatString = (_currentFPS >= 10.0f ? "%.0f" : "%.1f");
51 snprintf(&buffer[3], std::size(buffer) - 3, formatString, fps);
52
53 // Draw text
54 const int stringWidth = tr.getStringWidth(buffer);
55 auto point = Ui::Point(Ui::width() / 2 - (stringWidth / 2), 2);
56 tr.drawString(point, Colour::black, buffer);
57
58 // Make area dirty so the text doesn't get drawn over the last
59 invalidateRegion(point.x, point.y, point.x + stringWidth, point.y + 16);
60 }
61}

Callers 1

renderMethod · 0.85

Calls 6

TextRendererClass · 0.85
measureFPSFunction · 0.85
widthFunction · 0.85
invalidateRegionFunction · 0.85
getStringWidthMethod · 0.80
drawStringMethod · 0.80

Tested by

no test coverage detected