Files
spacetris/src/ui/MenuWrappers.cpp

89 lines
4.3 KiB
C++

// MenuWrappers.cpp - implementations of menu helper wrappers used by MenuState
#include "MenuWrappers.h"
#include "../core/GlobalState.h"
#include "../graphics/Font.h"
#include "app/Fireworks.h"
#include <SDL3/SDL.h>
using namespace Globals;
static void drawRect(SDL_Renderer* renderer, float x, float y, float w, float h, SDL_Color c) {
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, c.a);
SDL_FRect fr{ x, y, w, h };
SDL_RenderFillRect(renderer, &fr);
}
void menu_drawFireworks(SDL_Renderer* renderer, SDL_Texture* blocksTex) {
AppFireworks::draw(renderer, blocksTex);
}
void menu_updateFireworks(double frameMs) {
AppFireworks::update(frameMs);
}
double menu_getLogoAnimCounter() {
return AppFireworks::getLogoAnimCounter();
}
int menu_getHoveredButton() {
return AppFireworks::getHoveredButton();
}
void menu_drawEnhancedButton(SDL_Renderer* renderer, FontAtlas& font, float cx, float cy, float w, float h,
const std::string& label, bool isHovered, bool isSelected) {
// Simple wrapper delegating to a basic draw implementation
SDL_Color bgColor = isSelected ? SDL_Color{100,190,255,255} : (isHovered ? SDL_Color{120,150,240,255} : SDL_Color{80,110,200,255});
float x = cx - w/2; float y = cy - h/2;
drawRect(renderer, x-2, y-2, w+4, h+4, SDL_Color{60,80,140,255});
drawRect(renderer, x, y, w, h, bgColor);
float textScale = 1.5f;
float textX = x + (w - label.length() * 12 * textScale) / 2;
float textY = y + (h - 20 * textScale) / 2;
font.draw(renderer, textX+2, textY+2, label, textScale, SDL_Color{0,0,0,180});
font.draw(renderer, textX, textY, label, textScale, SDL_Color{255,255,255,255});
}
void menu_drawMenuButton(SDL_Renderer* renderer, FontAtlas& font, float cx, float cy, float w, float h,
const std::string& label, SDL_Color bgColor, SDL_Color borderColor) {
float x = cx - w/2; float y = cy - h/2;
drawRect(renderer, x-6, y-6, w+12, h+12, borderColor);
drawRect(renderer, x-4, y-4, w+8, h+8, SDL_Color{255,255,255,255});
drawRect(renderer, x, y, w, h, bgColor);
float textScale = 1.6f;
float approxCharW = 12.0f * textScale;
float textW = label.length() * approxCharW;
float tx = x + (w - textW) / 2.0f;
float ty = y + (h - 20.0f * textScale) / 2.0f;
font.draw(renderer, tx+2, ty+2, label, textScale, SDL_Color{0,0,0,180});
font.draw(renderer, tx, ty, label, textScale, SDL_Color{255,255,255,255});
}
void menu_drawLevelSelectionPopup(SDL_Renderer* renderer, FontAtlas& font, SDL_Texture* bgTex, int selectedLevel) {
(void)renderer; (void)font; (void)bgTex; (void)selectedLevel; // Not implemented here
}
void menu_drawSettingsPopup(SDL_Renderer* renderer, FontAtlas& font, bool musicEnabled) {
// Copy of main.cpp's drawSettingsPopup behavior adapted here
float popupW = 350, popupH = 260;
float popupX = (1200 - popupW) / 2;
float popupY = (1000 - popupH) / 2;
// Overlay
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 128);
SDL_FRect overlay{0,0,1200,1000};
SDL_RenderFillRect(renderer, &overlay);
drawRect(renderer, popupX-4, popupY-4, popupW+8, popupH+8, SDL_Color{100,120,160,255});
drawRect(renderer, popupX, popupY, popupW, popupH, SDL_Color{40,50,70,255});
font.draw(renderer, popupX + 20, popupY + 20, "SETTINGS", 2.0f, SDL_Color{255,220,0,255});
font.draw(renderer, popupX + 20, popupY + 70, "MUSIC:", 1.5f, SDL_Color{255,255,255,255});
const char* musicStatus = musicEnabled ? "ON" : "OFF";
SDL_Color musicColor = musicEnabled ? SDL_Color{0,255,0,255} : SDL_Color{255,0,0,255};
font.draw(renderer, popupX + 120, popupY + 70, musicStatus, 1.5f, musicColor);
font.draw(renderer, popupX + 20, popupY + 100, "SOUND FX:", 1.5f, SDL_Color{255,255,255,255});
// Sound effect manager may be initialized elsewhere; show placeholder status for now
bool sfxOn = true;
font.draw(renderer, popupX + 140, popupY + 100, sfxOn ? "ON" : "OFF", 1.5f, sfxOn ? SDL_Color{0,255,0,255} : SDL_Color{255,0,0,255});
font.draw(renderer, popupX + 20, popupY + 150, "M = TOGGLE MUSIC", 1.0f, SDL_Color{200,200,220,255});
font.draw(renderer, popupX + 20, popupY + 170, "K = TOGGLE SOUND FX", 1.0f, SDL_Color{200,200,220,255});
font.draw(renderer, popupX + 20, popupY + 190, "ESC = CLOSE", 1.0f, SDL_Color{200,200,220,255});
}