fixed highscore name input

This commit is contained in:
2025-11-30 10:54:01 +01:00
parent 5fd77fdaf0
commit e11a33e3e6

View File

@ -1788,12 +1788,37 @@ int main(int, char **)
SDL_SetRenderDrawColor(renderer, 255, 220, 0, 255); SDL_SetRenderDrawColor(renderer, 255, 220, 0, 255);
SDL_RenderRect(renderer, &inputRect); SDL_RenderRect(renderer, &inputRect);
// Player Name (with cursor) // Player Name (blink cursor without shifting text)
std::string display = playerName; const float nameScale = 1.2f;
if ((SDL_GetTicks() / 500) % 2 == 0) display += "_"; // Blink cursor const bool showCursor = ((SDL_GetTicks() / 500) % 2) == 0;
int nW=0, nH=0; pixelFont.measure(display, 1.2f, nW, nH); int metricsW = 0, metricsH = 0;
pixelFont.draw(renderer, inputX + (inputW - nW) * 0.5f + contentOffsetX, inputY + (inputH - nH) * 0.5f + contentOffsetY, display, 1.2f, {255, 255, 255, 255}); pixelFont.measure("A", nameScale, metricsW, metricsH);
if (metricsH == 0) metricsH = 24; // fallback height
int nameW = 0, nameH = 0;
if (!playerName.empty()) {
pixelFont.measure(playerName, nameScale, nameW, nameH);
} else {
nameH = metricsH;
}
float textX = inputX + (inputW - static_cast<float>(nameW)) * 0.5f + contentOffsetX;
float textY = inputY + (inputH - static_cast<float>(metricsH)) * 0.5f + contentOffsetY;
if (!playerName.empty()) {
pixelFont.draw(renderer, textX, textY, playerName, nameScale, {255, 255, 255, 255});
}
if (showCursor) {
int cursorW = 0, cursorH = 0;
pixelFont.measure("_", nameScale, cursorW, cursorH);
float cursorX = playerName.empty()
? inputX + (inputW - static_cast<float>(cursorW)) * 0.5f + contentOffsetX
: textX + static_cast<float>(nameW);
float cursorY = inputY + (inputH - static_cast<float>(cursorH)) * 0.5f + contentOffsetY;
pixelFont.draw(renderer, cursorX, cursorY, "_", nameScale, {255, 255, 255, 255});
}
// Hint // Hint
const char* hint = "PRESS ENTER TO SUBMIT"; const char* hint = "PRESS ENTER TO SUBMIT";