new background image

This commit is contained in:
2025-12-18 07:20:20 +01:00
parent 0ab7121c5b
commit 989b98002c
11 changed files with 233 additions and 27 deletions

View File

@ -25,7 +25,8 @@ BottomMenu buildBottomMenu(const MenuLayoutParams& params, int startLevel) {
menu.buttons[1] = Button{ BottomMenuItem::Level, rects[1], levelBtnText, true };
menu.buttons[2] = Button{ BottomMenuItem::Options, rects[2], "OPTIONS", true };
menu.buttons[3] = Button{ BottomMenuItem::Help, rects[3], "HELP", true };
menu.buttons[4] = Button{ BottomMenuItem::Exit, rects[4], "EXIT", true };
menu.buttons[4] = Button{ BottomMenuItem::About, rects[4], "ABOUT", true };
menu.buttons[5] = Button{ BottomMenuItem::Exit, rects[5], "EXIT", true };
return menu;
}
@ -73,15 +74,17 @@ void renderBottomMenu(SDL_Renderer* renderer,
}
}
// '+' separators between the bottom HUD buttons (indices 1..4)
// '+' separators between the bottom HUD buttons (indices 1..last)
{
SDL_BlendMode prevBlend = SDL_BLENDMODE_NONE;
SDL_GetRenderDrawBlendMode(renderer, &prevBlend);
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer, 120, 220, 255, static_cast<Uint8>(std::round(180.0 * baseMul)));
float y = menu.buttons[1].rect.y + menu.buttons[1].rect.h * 0.5f;
for (int i = 1; i < 4; ++i) {
const int firstSmall = 1;
const int lastSmall = MENU_BTN_COUNT - 1;
float y = menu.buttons[firstSmall].rect.y + menu.buttons[firstSmall].rect.h * 0.5f;
for (int i = firstSmall; i < lastSmall; ++i) {
float x = (menu.buttons[i].rect.x + menu.buttons[i].rect.w + menu.buttons[i + 1].rect.x) * 0.5f;
SDL_RenderLine(renderer, x - 4.0f, y, x + 4.0f, y);
SDL_RenderLine(renderer, x, y - 4.0f, x, y + 4.0f);

View File

@ -18,7 +18,8 @@ enum class BottomMenuItem : int {
Level = 1,
Options = 2,
Help = 3,
Exit = 4,
About = 4,
Exit = 5,
};
struct Button {
@ -35,8 +36,8 @@ struct BottomMenu {
BottomMenu buildBottomMenu(const MenuLayoutParams& params, int startLevel);
// Draws the cockpit HUD menu (PLAY + 4 bottom items) using existing UIRenderer primitives.
// hoveredIndex: -1..4
// selectedIndex: 0..4 (keyboard selection)
// hoveredIndex: -1..5
// selectedIndex: 0..5 (keyboard selection)
// alphaMul: 0..1 (overall group alpha)
void renderBottomMenu(SDL_Renderer* renderer,
FontAtlas* font,

View File

@ -5,7 +5,7 @@
namespace ui {
std::array<SDL_FRect, 5> computeMenuButtonRects(const MenuLayoutParams& p) {
std::array<SDL_FRect, MENU_BTN_COUNT> computeMenuButtonRects(const MenuLayoutParams& p) {
const float LOGICAL_W = static_cast<float>(p.logicalW);
const float LOGICAL_H = static_cast<float>(p.logicalH);
float contentOffsetX = (p.winW - LOGICAL_W * p.logicalScale) * 0.5f / p.logicalScale;
@ -13,7 +13,7 @@ std::array<SDL_FRect, 5> computeMenuButtonRects(const MenuLayoutParams& p) {
// Cockpit HUD layout (matches main_screen art):
// - A big centered PLAY button
// - A second row of 4 smaller buttons: LEVEL / OPTIONS / HELP / EXIT
// - A second row of 5 smaller buttons: LEVEL / OPTIONS / HELP / ABOUT / EXIT
const float marginX = std::max(24.0f, LOGICAL_W * 0.03f);
const float marginBottom = std::max(26.0f, LOGICAL_H * 0.03f);
const float availableW = std::max(120.0f, LOGICAL_W - marginX * 2.0f);
@ -25,7 +25,8 @@ std::array<SDL_FRect, 5> computeMenuButtonRects(const MenuLayoutParams& p) {
float smallSpacing = 28.0f;
// Scale down for narrow windows so nothing goes offscreen.
float smallTotal = smallW * 4.0f + smallSpacing * 3.0f;
const int smallCount = MENU_BTN_COUNT - 1;
float smallTotal = smallW * static_cast<float>(smallCount) + smallSpacing * static_cast<float>(smallCount - 1);
if (smallTotal > availableW) {
float s = availableW / smallTotal;
smallW *= s;
@ -45,14 +46,14 @@ std::array<SDL_FRect, 5> computeMenuButtonRects(const MenuLayoutParams& p) {
std::array<SDL_FRect, MENU_BTN_COUNT> rects{};
rects[0] = SDL_FRect{ centerX - playW * 0.5f, playCY - playH * 0.5f, playW, playH };
float rowW = smallW * 4.0f + smallSpacing * 3.0f;
float rowW = smallW * static_cast<float>(smallCount) + smallSpacing * static_cast<float>(smallCount - 1);
float left = centerX - rowW * 0.5f;
float minLeft = contentOffsetX + marginX;
float maxRight = contentOffsetX + LOGICAL_W - marginX;
if (left < minLeft) left = minLeft;
if (left + rowW > maxRight) left = std::max(minLeft, maxRight - rowW);
for (int i = 0; i < 4; ++i) {
for (int i = 0; i < smallCount; ++i) {
float x = left + i * (smallW + smallSpacing);
rects[i + 1] = SDL_FRect{ x, smallCY - smallH * 0.5f, smallW, smallH };
}

View File

@ -1,6 +1,6 @@
#pragma once
static constexpr int MENU_BTN_COUNT = 5;
static constexpr int MENU_BTN_COUNT = 6;
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