all repos — mgba @ d724d914c89304c339d738d924bed5a929d8a891

mGBA Game Boy Advance Emulator

GUI: Menu backgrounds
Jeffrey Pfau jeffrey@endrift.com
Tue, 01 Sep 2015 21:51:14 -0700
commit

d724d914c89304c339d738d924bed5a929d8a891

parent

d16c5e3a74b9a30568f7299409f2949fd150fc42

M src/gba/gui/gui-runner.csrc/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.hsrc/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.csrc/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.csrc/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.hsrc/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.csrc/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.hsrc/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.csrc/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);
M src/util/gui/menu.csrc/util/gui/menu.c

@@ -63,6 +63,12 @@ return GUI_MENU_EXIT_BACK;

} params->drawStart(); + if (menu->background) { + menu->background->draw(menu->background); + } + if (params->guiPrepare) { + params->guiPrepare(); + } unsigned y = GUIFontHeight(params->font); GUIFontPrint(params->font, 0, y, GUI_TEXT_LEFT, 0xFFFFFFFF, menu->title); y += 2 * GUIFontHeight(params->font);

@@ -79,6 +85,9 @@ y += GUIFontHeight(params->font);

if (y + GUIFontHeight(params->font) > params->height) { break; } + } + if (params->guiFinish) { + params->guiFinish(); } y += GUIFontHeight(params->font) * 2;
M src/util/gui/menu.hsrc/util/gui/menu.h

@@ -14,10 +14,13 @@ void* data;

}; DECLARE_VECTOR(GUIMenuItemList, struct GUIMenuItem); + +struct GUIBackground; struct GUIMenu { const char* title; struct GUIMenuItemList items; size_t index; + struct GUIBackground* background; }; enum GUIMenuExitReason {