GUI: Menu backgrounds
Jeffrey Pfau jeffrey@endrift.com
Tue, 01 Sep 2015 21:51:14 -0700
10 files changed,
47 insertions(+),
16 deletions(-)
M
src/gba/gui/gui-runner.c
→
src/gba/gui/gui-runner.c
@@ -18,9 +18,18 @@ RUNNER_SAVE_STATE,
RUNNER_LOAD_STATE, }; +static void _drawBackground(struct GUIBackground* background) { + struct GBAGUIBackground* gbaBackground = (struct GBAGUIBackground*) background; + if (gbaBackground->p->drawFrame) { + gbaBackground->p->drawFrame(gbaBackground->p, true); + } +} + void GBAGUIInit(struct GBAGUIRunner* runner, const char* port) { GUIInit(&runner->params); GBAContextInit(&runner->context, port); + runner->background.d.draw = _drawBackground; + runner->background.p = runner; if (runner->setup) { runner->setup(runner); }@@ -37,6 +46,7 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
struct GUIMenu pauseMenu = { .title = "Game Paused", .index = 0, + .background = &runner->background.d }; GUIMenuItemListInit(&pauseMenu.items, 0); *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Unpause", .data = (void*) RUNNER_CONTINUE };@@ -48,9 +58,6 @@ #endif
*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Exit game", .data = (void*) RUNNER_EXIT }; while (true) { - if (runner->params.guiPrepare) { - runner->params.guiPrepare(); - } char path[256]; if (!GUISelectFile(&runner->params, path, sizeof(path), GBAIsROM)) { if (runner->params.guiFinish) {@@ -60,6 +67,9 @@ GUIMenuItemListDeinit(&pauseMenu.items);
return; } + if (runner->params.guiPrepare) { + runner->params.guiPrepare(); + } // TODO: Message box API runner->params.drawStart(); GUIFontPrint(runner->params.font, runner->params.width / 2, (GUIFontHeight(runner->params.font) + runner->params.height) / 2, GUI_TEXT_CENTER, 0xFFFFFFFF, "Loading...");@@ -96,13 +106,12 @@ runner->prepareForFrame(runner);
} GBAContextFrame(&runner->context, keys); if (runner->drawFrame) { + runner->params.drawStart(); runner->drawFrame(runner, false); + runner->params.drawEnd(); } } - if (runner->params.guiPrepare) { - runner->params.guiPrepare(); - } GUIInvalidateKeys(&runner->params); int keys = -1; // Huge hack to avoid an extra variable! struct GUIMenuItem item;
M
src/gba/gui/gui-runner.h
→
src/gba/gui/gui-runner.h
@@ -9,9 +9,17 @@
#include "gba/context/context.h" #include "util/gui.h" + +struct GBAGUIBackground { + struct GUIBackground d; + struct GBAGUIRunner* p; +}; + struct GBAGUIRunner { struct GBAContext context; struct GUIParams params; + + struct GBAGUIBackground background; void (*setup)(struct GBAGUIRunner*); void (*teardown)(struct GBAGUIRunner*);
M
src/platform/3ds/main.c
→
src/platform/3ds/main.c
@@ -116,9 +116,7 @@ blip_clear(runner->context.gba->audio.right);
} #endif gspWaitForPPF(); - _drawStart(); sf2d_draw_texture_scale_blend(tex, 40, 296, 1, -1, 0xFFFFFF3F | (faded ? 0 : 0xC0)); - _drawEnd(); } static uint16_t _pollGameInput(struct GBAGUIRunner* runner) {
M
src/platform/psp2/psp2-context.c
→
src/platform/psp2/psp2-context.c
@@ -228,8 +228,6 @@ }
void GBAPSP2Draw(struct GBAGUIRunner* runner, bool faded) { UNUSED(runner); - vita2d_start_drawing(); - vita2d_clear_screen(); switch (screenMode) { case SM_BACKDROP: vita2d_draw_texture_tint(backdrop, 0, 0, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF);@@ -241,8 +239,6 @@ case SM_FULL:
vita2d_draw_texture_tint_scale(tex, 0, 0, 960.0f / 240.0f, 544.0f / 160.0f, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF); break; } - vita2d_end_drawing(); - vita2d_swap_buffers(); } __attribute__((noreturn, weak)) void __assert_func(const char* file, int line, const char* func, const char* expr) {
M
src/platform/psp2/psp2-context.h
→
src/platform/psp2/psp2-context.h
@@ -7,6 +7,7 @@ #ifndef PSP2_CONTEXT_H
#define PSP2_CONTEXT_H #include "psp2-common.h" +#include "util/gui.h" struct GBAGUIRunner; void GBAPSP2Setup(struct GBAGUIRunner* runner);
M
src/platform/wii/main.c
→
src/platform/wii/main.c
@@ -370,8 +370,6 @@ }
} DCFlushRange(texdest, 256 * 256 * BYTES_PER_PIXEL); - _drawStart(); - if (faded) { GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_NOOP); } else {@@ -399,8 +397,6 @@ GX_Position2s16(0, 0);
GX_Color1u32(color); GX_TexCoord2s16(0, 0); GX_End(); - - _drawEnd(); } uint16_t _pollGameInput(struct GBAGUIRunner* runner) {
M
src/util/gui.h
→
src/util/gui.h
@@ -26,6 +26,10 @@
GUI_INPUT_MAX }; +struct GUIBackground { + void (*draw)(struct GUIBackground*); +}; + struct GUIParams { unsigned width; unsigned height;
M
src/util/gui/file-select.c
→
src/util/gui/file-select.c
@@ -61,9 +61,16 @@ GUIPollInput(params, &input, 0);
if (input & (1 << GUI_INPUT_CANCEL)) { return false; } + params->drawStart(); + if (params->guiPrepare) { + params->guiPrepare(); + } GUIFontPrintf(params->font, 0, GUIFontHeight(params->font), GUI_TEXT_LEFT, 0xFFFFFFFF, "%s", currentPath); GUIFontPrintf(params->font, 0, GUIFontHeight(params->font) * 2, GUI_TEXT_LEFT, 0xFFFFFFFF, "(scanning item %lu)", i); + if (params->guiFinish) { + params->guiFinish(); + } params->drawEnd(); } const char* name = de->name(de);