minor fix

This commit is contained in:
2025-11-22 10:59:47 +01:00
parent ec2bb1bb1e
commit 0ffd801743
8 changed files with 105 additions and 32 deletions

View File

@ -193,6 +193,8 @@ void LevelSelectorState::handleEvent(const SDL_Event& e) {
// convert mouse to logical coords (viewport is already centered)
float lx = (float(e.button.x) - float(lastLogicalVP.x)) / (lastLogicalScale > 0.f ? lastLogicalScale : 1.f);
float ly = (float(e.button.y) - float(lastLogicalVP.y)) / (lastLogicalScale > 0.f ? lastLogicalScale : 1.f);
// Use same panel calculation as render (centered)
SDL_FRect panel = DrawPanel(nullptr, LOGICAL_W, LOGICAL_H, /*draw=*/false, 0.f, 0.f);
Grid g = MakeGrid(panel);
int hit = HitTest(g, int(lx), int(ly));
@ -210,6 +212,8 @@ void LevelSelectorState::handleEvent(const SDL_Event& e) {
// convert mouse to logical coords (viewport is already centered)
float lx = (float(e.motion.x) - float(lastLogicalVP.x)) / (lastLogicalScale > 0.f ? lastLogicalScale : 1.f);
float ly = (float(e.motion.y) - float(lastLogicalVP.y)) / (lastLogicalScale > 0.f ? lastLogicalScale : 1.f);
// Use same panel calculation as render (centered)
SDL_FRect panel = DrawPanel(nullptr, LOGICAL_W, LOGICAL_H, /*draw=*/false, 0.f, 0.f);
Grid g = MakeGrid(panel);
hoveredLevel = HitTest(g, int(lx), int(ly));
@ -225,28 +229,30 @@ void LevelSelectorState::render(SDL_Renderer* renderer, float logicalScale, SDL_
// Cache for input conversion
lastLogicalScale = logicalScale;
lastLogicalVP = logicalVP;
drawLevelSelectionPopup(renderer);
drawLevelSelectionPopup(renderer, logicalScale, logicalVP);
}
void LevelSelectorState::drawLevelSelectionPopup(SDL_Renderer* renderer) {
void LevelSelectorState::drawLevelSelectionPopup(SDL_Renderer* renderer, float logicalScale, SDL_Rect logicalVP) {
if (!renderer) return;
// Get dynamic logical dimensions
const int LOGICAL_W = GlobalState::instance().getLogicalWidth();
const int LOGICAL_H = GlobalState::instance().getLogicalHeight();
// Use fixed logical dimensions to match main.cpp and ensure consistent layout
const float LOGICAL_W = 1200.f;
const float LOGICAL_H = 1000.f;
// Compute content offsets (same approach as MenuState for proper centering)
float winW = (float)logicalVP.w;
float winH = (float)logicalVP.h;
float contentW = LOGICAL_W * logicalScale;
float contentH = LOGICAL_H * logicalScale;
float contentOffsetX = (winW - contentW) * 0.5f / logicalScale;
float contentOffsetY = (winH - contentH) * 0.5f / logicalScale;
// Since ApplicationManager sets up a centered viewport, we draw directly in logical coordinates
// The viewport (LOGICAL_W x LOGICAL_H) is already centered within the window
float vw = float(LOGICAL_W);
float vh = float(LOGICAL_H);
float offX = 0.f; // No offset needed since viewport is centered
// Panel and title strip (in logical space)
SDL_FRect panel = DrawPanel(renderer, vw, vh-140.0f, /*draw=*/true, offX, 0.f);
// Panel and title strip (in logical space) - centered properly with offsets
SDL_FRect panel = DrawPanel(renderer, LOGICAL_W, LOGICAL_H, /*draw=*/true, contentOffsetX, contentOffsetY);
// Title text - prefer pixelFont for a blocky title if available, fallback to regular font
FontAtlas* titleFont = ctx.pixelFont ? ctx.pixelFont : ctx.font;
DrawText(renderer, titleFont, "SELECT STARTING LEVEL", vw / 2.f + offX, panel.y + 20.f, 1.2f, COL_TITLE, true, true);
DrawText(renderer, titleFont, "SELECT STARTING LEVEL", LOGICAL_W / 2.f + contentOffsetX, panel.y + 20.f, 1.2f, COL_TITLE, true, true);
// Grid of levels
Grid g = MakeGrid(panel);
@ -256,10 +262,10 @@ void LevelSelectorState::drawLevelSelectionPopup(SDL_Renderer* renderer) {
DrawCell(renderer, rc, i, hoveredLevel == i, selectedLevel == i);
}
// Footer/instructions - use regular TTF font for readability
// Footer/instructions - use regular TTF font for readability, centered and higher
FontAtlas* footerFont = ctx.pixelFont ? ctx.pixelFont : ctx.font;
DrawText(renderer, footerFont, "CLICK A LEVEL TO SELECT \u2022 ESC = CANCEL",
vw / 2.f + offX, vh - 56.f, 1.0f, COL_FOOTER, true, true);
DrawText(renderer, footerFont, "CLICK A LEVEL TO SELECT ESC = CANCEL",
LOGICAL_W / 2.f + contentOffsetX, panel.y + panel.h + 30.f, 1.0f, COL_FOOTER, true, true);
}
bool LevelSelectorState::isMouseInPopup(float mouseX, float mouseY, float& popupX, float& popupY, float& popupW, float& popupH) {