| 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 | } |
no test coverage detected