diff --git a/src/main.cpp b/src/main.cpp index a79d599..5c38567 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1788,12 +1788,37 @@ int main(int, char **) SDL_SetRenderDrawColor(renderer, 255, 220, 0, 255); SDL_RenderRect(renderer, &inputRect); - // Player Name (with cursor) - std::string display = playerName; - if ((SDL_GetTicks() / 500) % 2 == 0) display += "_"; // Blink cursor - - int nW=0, nH=0; pixelFont.measure(display, 1.2f, nW, nH); - pixelFont.draw(renderer, inputX + (inputW - nW) * 0.5f + contentOffsetX, inputY + (inputH - nH) * 0.5f + contentOffsetY, display, 1.2f, {255, 255, 255, 255}); + // Player Name (blink cursor without shifting text) + const float nameScale = 1.2f; + const bool showCursor = ((SDL_GetTicks() / 500) % 2) == 0; + + int metricsW = 0, metricsH = 0; + 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(nameW)) * 0.5f + contentOffsetX; + float textY = inputY + (inputH - static_cast(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(cursorW)) * 0.5f + contentOffsetX + : textX + static_cast(nameW); + float cursorY = inputY + (inputH - static_cast(cursorH)) * 0.5f + contentOffsetY; + pixelFont.draw(renderer, cursorX, cursorY, "_", nameScale, {255, 255, 255, 255}); + } // Hint const char* hint = "PRESS ENTER TO SUBMIT";