some problems fixed

This commit is contained in:
2025-08-17 21:13:58 +02:00
parent d75bfcf4d0
commit b5ef9172b3
18 changed files with 1139 additions and 231 deletions

View File

@ -3,6 +3,7 @@
#include "persistence/Scores.h"
#include "graphics/Font.h"
#include "../core/GlobalState.h"
#include "../audio/Audio.h"
#include <SDL3/SDL.h>
#include <cstdio>
#include <algorithm>
@ -42,14 +43,10 @@ void MenuState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logi
{
FILE* f = fopen("tetris_trace.log", "a"); if (f) { fprintf(f, "MenuState::render entry\n"); fclose(f); }
}
// Compute content offset using the same math as main
float winW = float(logicalVP.w);
float winH = float(logicalVP.h);
float contentScale = logicalScale;
float contentW = LOGICAL_W * contentScale;
float contentH = LOGICAL_H * contentScale;
float contentOffsetX = (winW - contentW) * 0.5f / contentScale;
float contentOffsetY = (winH - contentH) * 0.5f / contentScale;
// Since ApplicationManager sets up a centered viewport, we draw directly in logical coordinates
// No additional content offset is needed - the viewport itself handles centering
float contentOffsetX = 0.0f;
float contentOffsetY = 0.0f;
// Background is drawn by main (stretched to the full window) to avoid double-draw.
@ -119,16 +116,17 @@ void MenuState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logi
useFont->draw(renderer, colX[4], scoresStartY - 28, "LEVEL", 1.1f, SDL_Color{200,200,220,255});
useFont->draw(renderer, colX[5], scoresStartY - 28, "TIME", 1.1f, SDL_Color{200,200,220,255});
}
// Center columns around mid X, wider
float cx = LOGICAL_W * 0.5f + contentOffsetX;
float colX[] = { cx - 280, cx - 180, cx - 20, cx + 90, cx + 200, cx + 300 };
for (size_t i = 0; i < maxDisplay; ++i)
{
float baseY = scoresStartY + i * 25;
float wave = std::sin((float)GlobalState::instance().logoAnimCounter * 0.006f + i * 0.25f) * 6.0f; // subtle wave
float y = baseY + wave;
// Center columns around mid X, wider
float cx = LOGICAL_W * 0.5f + contentOffsetX;
float colX[] = { cx - 280, cx - 180, cx - 20, cx + 90, cx + 200, cx + 300 };
char rankStr[8];
std::snprintf(rankStr, sizeof(rankStr), "%zu.", i + 1);
if (useFont) useFont->draw(renderer, colX[0], y, rankStr, 1.0f, SDL_Color{220, 220, 230, 255});
@ -150,6 +148,8 @@ void MenuState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logi
}
// Draw bottom action buttons with responsive sizing (reduced to match main mouse hit-test)
// Since we removed content offsets, calculate contentW directly from the scale and logical size
float contentW = LOGICAL_W * logicalScale;
bool isSmall = (contentW < 700.0f);
float btnW = isSmall ? (LOGICAL_W * 0.4f) : 300.0f;
float btnH = isSmall ? 60.0f : 70.0f;