Add exit-confirm modal (fullscreen dim, centered P2 text) and keyboard shortcuts

Add an in-game exit confirmation modal for Playing state: ESC opens modal and pauses the game; YES resets and returns to Menu; NO hides modal and resumes.
Draw a full-window translucent dim background (reset viewport) so overlay covers any window size / fullscreen.
Use PressStart2P (pixel P2) font for all modal text and center title/body/button labels using measured text widths.
Add FontAtlas::measure(...) to accurately measure text sizes (used for proper centering).
Ensure popup rendering and mouse hit-testing use the same logical/content-local coordinate math so visuals and clicks align.
Add keyboard shortcuts for modal (Enter = confirm, Esc = cancel) and suppress other gameplay input while modal is active.
Add helper scripts for debug build+run: build-debug-and-run.ps1 and build-debug-and-run.bat.
Minor fixes to related rendering & state wiring; verified Debug build completes and modal behavior in runtime.
This commit is contained in:
2025-08-16 19:40:23 +02:00
parent 2afaea7fd3
commit 6d4f3c54ed
5 changed files with 167 additions and 3 deletions

View File

@ -19,3 +19,18 @@ void FontAtlas::draw(SDL_Renderer* r, float x, float y, const std::string& text,
if (tex) { SDL_FRect dst{ x, y, (float)surf->w, (float)surf->h }; SDL_RenderTexture(r, tex, nullptr, &dst); SDL_DestroyTexture(tex); }
SDL_DestroySurface(surf);
}
void FontAtlas::measure(const std::string& text, float scale, int& outW, int& outH) {
outW = 0; outH = 0;
if (scale <= 0) return;
int pt = int(baseSize * scale);
if (pt < 1) pt = 1;
TTF_Font* f = getSized(pt);
if (!f) return;
// Use render-to-surface measurement to avoid dependency on specific TTF_* measurement API variants
SDL_Color dummy = {255,255,255,255};
SDL_Surface* surf = TTF_RenderText_Blended(f, text.c_str(), text.length(), dummy);
if (!surf) return;
outW = surf->w; outH = surf->h;
SDL_DestroySurface(surf);
}

View File

@ -10,6 +10,8 @@ public:
bool init(const std::string& path, int basePt);
void shutdown();
void draw(SDL_Renderer* r, float x, float y, const std::string& text, float scale, SDL_Color color);
// Measure rendered text size in pixels for a given scale
void measure(const std::string& text, float scale, int& outW, int& outH);
private:
std::string fontPath;
int baseSize{24};