fixed highscore name input
This commit is contained in:
35
src/main.cpp
35
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
|
||||
// Player Name (blink cursor without shifting text)
|
||||
const float nameScale = 1.2f;
|
||||
const bool showCursor = ((SDL_GetTicks() / 500) % 2) == 0;
|
||||
|
||||
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});
|
||||
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<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
|
||||
const char* hint = "PRESS ENTER TO SUBMIT";
|
||||
|
||||
Reference in New Issue
Block a user