mirror of https://github.com/mgba-emu/mgba.git
GUI: Menu backgrounds
This commit is contained in:
parent
d16c5e3a74
commit
d724d914c8
|
@ -18,9 +18,18 @@ enum {
|
|||
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 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
|
|||
*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 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
|
|||
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 @@ void GBAGUIRunloop(struct GBAGUIRunner* 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;
|
||||
|
|
|
@ -9,10 +9,18 @@
|
|||
#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*);
|
||||
void (*gameLoaded)(struct GBAGUIRunner*);
|
||||
|
|
|
@ -116,9 +116,7 @@ static void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
|
|||
}
|
||||
#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) {
|
||||
|
|
|
@ -228,8 +228,6 @@ void GBAPSP2Teardown(struct GBAGUIRunner* runner) {
|
|||
|
||||
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 @@ void GBAPSP2Draw(struct GBAGUIRunner* runner, bool faded) {
|
|||
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) {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#define PSP2_CONTEXT_H
|
||||
|
||||
#include "psp2-common.h"
|
||||
#include "util/gui.h"
|
||||
|
||||
struct GBAGUIRunner;
|
||||
void GBAPSP2Setup(struct GBAGUIRunner* runner);
|
||||
|
|
|
@ -370,8 +370,6 @@ void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
|
|||
}
|
||||
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 @@ void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
|
|||
GX_Color1u32(color);
|
||||
GX_TexCoord2s16(0, 0);
|
||||
GX_End();
|
||||
|
||||
_drawEnd();
|
||||
}
|
||||
|
||||
uint16_t _pollGameInput(struct GBAGUIRunner* runner) {
|
||||
|
|
|
@ -26,6 +26,10 @@ enum GUIInput {
|
|||
GUI_INPUT_MAX
|
||||
};
|
||||
|
||||
struct GUIBackground {
|
||||
void (*draw)(struct GUIBackground*);
|
||||
};
|
||||
|
||||
struct GUIParams {
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
|
|
|
@ -61,9 +61,16 @@ static bool _refreshDirectory(struct GUIParams* params, const char* currentPath,
|
|||
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);
|
||||
|
|
|
@ -63,6 +63,12 @@ enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* men
|
|||
}
|
||||
|
||||
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);
|
||||
|
@ -80,6 +86,9 @@ enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* men
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (params->guiFinish) {
|
||||
params->guiFinish();
|
||||
}
|
||||
y += GUIFontHeight(params->font) * 2;
|
||||
|
||||
params->drawEnd();
|
||||
|
|
|
@ -14,10 +14,13 @@ struct GUIMenuItem {
|
|||
};
|
||||
|
||||
DECLARE_VECTOR(GUIMenuItemList, struct GUIMenuItem);
|
||||
|
||||
struct GUIBackground;
|
||||
struct GUIMenu {
|
||||
const char* title;
|
||||
struct GUIMenuItemList items;
|
||||
size_t index;
|
||||
struct GUIBackground* background;
|
||||
};
|
||||
|
||||
enum GUIMenuExitReason {
|
||||
|
|
Loading…
Reference in New Issue