fixed progress bar

This commit is contained in:
2025-12-16 12:09:33 +01:00
parent ec086b2cd4
commit 81586aa768
7 changed files with 372 additions and 208 deletions

41
src/ui/MenuLayout.cpp Normal file
View File

@ -0,0 +1,41 @@
#include "ui/MenuLayout.h"
#include "ui/UIConstants.h"
#include <cmath>
#include <array>
namespace ui {
std::array<SDL_FRect, 5> computeMenuButtonRects(const MenuLayoutParams& p) {
const float LOGICAL_W = static_cast<float>(p.logicalW);
const float LOGICAL_H = static_cast<float>(p.logicalH);
bool isSmall = ((LOGICAL_W * p.logicalScale) < MENU_SMALL_THRESHOLD);
float btnW = isSmall ? (LOGICAL_W * MENU_BTN_WIDTH_SMALL_FACTOR) : MENU_BTN_WIDTH_LARGE;
float btnH = isSmall ? MENU_BTN_HEIGHT_SMALL : MENU_BTN_HEIGHT_LARGE;
float contentOffsetX = (p.winW - LOGICAL_W * p.logicalScale) * 0.5f / p.logicalScale;
float contentOffsetY = (p.winH - LOGICAL_H * p.logicalScale) * 0.5f / p.logicalScale;
float btnCX = LOGICAL_W * 0.5f + contentOffsetX;
float btnCY = LOGICAL_H * 0.86f + contentOffsetY + MENU_BTN_Y_OFFSET;
float spacing = isSmall ? btnW * MENU_BTN_SPACING_FACTOR_SMALL : btnW * MENU_BTN_SPACING_FACTOR_LARGE;
std::array<SDL_FRect, MENU_BTN_COUNT> rects{};
for (int i = 0; i < MENU_BTN_COUNT; ++i) {
float center = btnCX + (static_cast<float>(i) - MENU_BTN_CENTER) * spacing;
rects[i] = SDL_FRect{center - btnW / 2.0f, btnCY - btnH / 2.0f, btnW, btnH};
}
return rects;
}
int hitTestMenuButtons(const MenuLayoutParams& p, float localX, float localY) {
auto rects = computeMenuButtonRects(p);
for (int i = 0; i < MENU_BTN_COUNT; ++i) {
const auto &r = rects[i];
if (localX >= r.x && localX <= r.x + r.w && localY >= r.y && localY <= r.y + r.h)
return i;
}
return -1;
}
SDL_FRect settingsButtonRect(const MenuLayoutParams& p) {
return SDL_FRect{SETTINGS_BTN_X, SETTINGS_BTN_Y, SETTINGS_BTN_W, SETTINGS_BTN_H};
}
} // namespace ui

26
src/ui/MenuLayout.h Normal file
View File

@ -0,0 +1,26 @@
#pragma once
#include <array>
#include "ui/UIConstants.h"
#include <SDL3/SDL.h>
namespace ui {
struct MenuLayoutParams {
int logicalW;
int logicalH;
int winW;
int winH;
float logicalScale;
};
// Compute menu button rects in logical coordinates (content-local)
std::array<SDL_FRect, MENU_BTN_COUNT> computeMenuButtonRects(const MenuLayoutParams& p);
// Hit test a point given in logical content-local coordinates against menu buttons
// Returns index 0..4 or -1 if none
int hitTestMenuButtons(const MenuLayoutParams& p, float localX, float localY);
// Return settings button rect (logical coords)
SDL_FRect settingsButtonRect(const MenuLayoutParams& p);
} // namespace ui

18
src/ui/UIConstants.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
static constexpr int MENU_BTN_COUNT = 5;
static constexpr float MENU_SMALL_THRESHOLD = 700.0f;
static constexpr float MENU_BTN_WIDTH_LARGE = 300.0f;
static constexpr float MENU_BTN_WIDTH_SMALL_FACTOR = 0.4f; // multiplied by LOGICAL_W
static constexpr float MENU_BTN_HEIGHT_LARGE = 70.0f;
static constexpr float MENU_BTN_HEIGHT_SMALL = 60.0f;
static constexpr float MENU_BTN_Y_OFFSET = 40.0f; // matches MenuState offset
static constexpr float MENU_BTN_SPACING_FACTOR_SMALL = 1.15f;
static constexpr float MENU_BTN_SPACING_FACTOR_LARGE = 1.05f;
static constexpr float MENU_BTN_CENTER = (MENU_BTN_COUNT - 1) / 2.0f;
// Settings button metrics
static constexpr float SETTINGS_BTN_OFFSET_X = 60.0f;
static constexpr float SETTINGS_BTN_X = 1200 - SETTINGS_BTN_OFFSET_X; // LOGICAL_W is 1200
static constexpr float SETTINGS_BTN_Y = 10.0f;
static constexpr float SETTINGS_BTN_W = 50.0f;
static constexpr float SETTINGS_BTN_H = 30.0f;