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,
|
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) {
|
void GBAGUIInit(struct GBAGUIRunner* runner, const char* port) {
|
||||||
GUIInit(&runner->params);
|
GUIInit(&runner->params);
|
||||||
GBAContextInit(&runner->context, port);
|
GBAContextInit(&runner->context, port);
|
||||||
|
runner->background.d.draw = _drawBackground;
|
||||||
|
runner->background.p = runner;
|
||||||
if (runner->setup) {
|
if (runner->setup) {
|
||||||
runner->setup(runner);
|
runner->setup(runner);
|
||||||
}
|
}
|
||||||
|
@ -37,6 +46,7 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
|
||||||
struct GUIMenu pauseMenu = {
|
struct GUIMenu pauseMenu = {
|
||||||
.title = "Game Paused",
|
.title = "Game Paused",
|
||||||
.index = 0,
|
.index = 0,
|
||||||
|
.background = &runner->background.d
|
||||||
};
|
};
|
||||||
GUIMenuItemListInit(&pauseMenu.items, 0);
|
GUIMenuItemListInit(&pauseMenu.items, 0);
|
||||||
*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Unpause", .data = (void*) RUNNER_CONTINUE };
|
*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 };
|
*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Exit game", .data = (void*) RUNNER_EXIT };
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (runner->params.guiPrepare) {
|
|
||||||
runner->params.guiPrepare();
|
|
||||||
}
|
|
||||||
char path[256];
|
char path[256];
|
||||||
if (!GUISelectFile(&runner->params, path, sizeof(path), GBAIsROM)) {
|
if (!GUISelectFile(&runner->params, path, sizeof(path), GBAIsROM)) {
|
||||||
if (runner->params.guiFinish) {
|
if (runner->params.guiFinish) {
|
||||||
|
@ -60,6 +67,9 @@ void GBAGUIRunloop(struct GBAGUIRunner* runner) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (runner->params.guiPrepare) {
|
||||||
|
runner->params.guiPrepare();
|
||||||
|
}
|
||||||
// TODO: Message box API
|
// TODO: Message box API
|
||||||
runner->params.drawStart();
|
runner->params.drawStart();
|
||||||
GUIFontPrint(runner->params.font, runner->params.width / 2, (GUIFontHeight(runner->params.font) + runner->params.height) / 2, GUI_TEXT_CENTER, 0xFFFFFFFF, "Loading...");
|
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);
|
GBAContextFrame(&runner->context, keys);
|
||||||
if (runner->drawFrame) {
|
if (runner->drawFrame) {
|
||||||
|
runner->params.drawStart();
|
||||||
runner->drawFrame(runner, false);
|
runner->drawFrame(runner, false);
|
||||||
|
runner->params.drawEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runner->params.guiPrepare) {
|
|
||||||
runner->params.guiPrepare();
|
|
||||||
}
|
|
||||||
GUIInvalidateKeys(&runner->params);
|
GUIInvalidateKeys(&runner->params);
|
||||||
int keys = -1; // Huge hack to avoid an extra variable!
|
int keys = -1; // Huge hack to avoid an extra variable!
|
||||||
struct GUIMenuItem item;
|
struct GUIMenuItem item;
|
||||||
|
|
|
@ -9,10 +9,18 @@
|
||||||
#include "gba/context/context.h"
|
#include "gba/context/context.h"
|
||||||
#include "util/gui.h"
|
#include "util/gui.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct GBAGUIBackground {
|
||||||
|
struct GUIBackground d;
|
||||||
|
struct GBAGUIRunner* p;
|
||||||
|
};
|
||||||
|
|
||||||
struct GBAGUIRunner {
|
struct GBAGUIRunner {
|
||||||
struct GBAContext context;
|
struct GBAContext context;
|
||||||
struct GUIParams params;
|
struct GUIParams params;
|
||||||
|
|
||||||
|
struct GBAGUIBackground background;
|
||||||
|
|
||||||
void (*setup)(struct GBAGUIRunner*);
|
void (*setup)(struct GBAGUIRunner*);
|
||||||
void (*teardown)(struct GBAGUIRunner*);
|
void (*teardown)(struct GBAGUIRunner*);
|
||||||
void (*gameLoaded)(struct GBAGUIRunner*);
|
void (*gameLoaded)(struct GBAGUIRunner*);
|
||||||
|
|
|
@ -116,9 +116,7 @@ static void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
gspWaitForPPF();
|
gspWaitForPPF();
|
||||||
_drawStart();
|
|
||||||
sf2d_draw_texture_scale_blend(tex, 40, 296, 1, -1, 0xFFFFFF3F | (faded ? 0 : 0xC0));
|
sf2d_draw_texture_scale_blend(tex, 40, 296, 1, -1, 0xFFFFFF3F | (faded ? 0 : 0xC0));
|
||||||
_drawEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t _pollGameInput(struct GBAGUIRunner* runner) {
|
static uint16_t _pollGameInput(struct GBAGUIRunner* runner) {
|
||||||
|
|
|
@ -228,8 +228,6 @@ void GBAPSP2Teardown(struct GBAGUIRunner* runner) {
|
||||||
|
|
||||||
void GBAPSP2Draw(struct GBAGUIRunner* runner, bool faded) {
|
void GBAPSP2Draw(struct GBAGUIRunner* runner, bool faded) {
|
||||||
UNUSED(runner);
|
UNUSED(runner);
|
||||||
vita2d_start_drawing();
|
|
||||||
vita2d_clear_screen();
|
|
||||||
switch (screenMode) {
|
switch (screenMode) {
|
||||||
case SM_BACKDROP:
|
case SM_BACKDROP:
|
||||||
vita2d_draw_texture_tint(backdrop, 0, 0, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF);
|
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);
|
vita2d_draw_texture_tint_scale(tex, 0, 0, 960.0f / 240.0f, 544.0f / 160.0f, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vita2d_end_drawing();
|
|
||||||
vita2d_swap_buffers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((noreturn, weak)) void __assert_func(const char* file, int line, const char* func, const char* expr) {
|
__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
|
#define PSP2_CONTEXT_H
|
||||||
|
|
||||||
#include "psp2-common.h"
|
#include "psp2-common.h"
|
||||||
|
#include "util/gui.h"
|
||||||
|
|
||||||
struct GBAGUIRunner;
|
struct GBAGUIRunner;
|
||||||
void GBAPSP2Setup(struct GBAGUIRunner* runner);
|
void GBAPSP2Setup(struct GBAGUIRunner* runner);
|
||||||
|
|
|
@ -370,8 +370,6 @@ void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
|
||||||
}
|
}
|
||||||
DCFlushRange(texdest, 256 * 256 * BYTES_PER_PIXEL);
|
DCFlushRange(texdest, 256 * 256 * BYTES_PER_PIXEL);
|
||||||
|
|
||||||
_drawStart();
|
|
||||||
|
|
||||||
if (faded) {
|
if (faded) {
|
||||||
GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_NOOP);
|
GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_NOOP);
|
||||||
} else {
|
} else {
|
||||||
|
@ -399,8 +397,6 @@ void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
|
||||||
GX_Color1u32(color);
|
GX_Color1u32(color);
|
||||||
GX_TexCoord2s16(0, 0);
|
GX_TexCoord2s16(0, 0);
|
||||||
GX_End();
|
GX_End();
|
||||||
|
|
||||||
_drawEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t _pollGameInput(struct GBAGUIRunner* runner) {
|
uint16_t _pollGameInput(struct GBAGUIRunner* runner) {
|
||||||
|
|
|
@ -26,6 +26,10 @@ enum GUIInput {
|
||||||
GUI_INPUT_MAX
|
GUI_INPUT_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct GUIBackground {
|
||||||
|
void (*draw)(struct GUIBackground*);
|
||||||
|
};
|
||||||
|
|
||||||
struct GUIParams {
|
struct GUIParams {
|
||||||
unsigned width;
|
unsigned width;
|
||||||
unsigned height;
|
unsigned height;
|
||||||
|
|
|
@ -61,9 +61,16 @@ static bool _refreshDirectory(struct GUIParams* params, const char* currentPath,
|
||||||
if (input & (1 << GUI_INPUT_CANCEL)) {
|
if (input & (1 << GUI_INPUT_CANCEL)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
params->drawStart();
|
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), GUI_TEXT_LEFT, 0xFFFFFFFF, "%s", currentPath);
|
||||||
GUIFontPrintf(params->font, 0, GUIFontHeight(params->font) * 2, GUI_TEXT_LEFT, 0xFFFFFFFF, "(scanning item %lu)", i);
|
GUIFontPrintf(params->font, 0, GUIFontHeight(params->font) * 2, GUI_TEXT_LEFT, 0xFFFFFFFF, "(scanning item %lu)", i);
|
||||||
|
if (params->guiFinish) {
|
||||||
|
params->guiFinish();
|
||||||
|
}
|
||||||
params->drawEnd();
|
params->drawEnd();
|
||||||
}
|
}
|
||||||
const char* name = de->name(de);
|
const char* name = de->name(de);
|
||||||
|
|
|
@ -63,6 +63,12 @@ enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* men
|
||||||
}
|
}
|
||||||
|
|
||||||
params->drawStart();
|
params->drawStart();
|
||||||
|
if (menu->background) {
|
||||||
|
menu->background->draw(menu->background);
|
||||||
|
}
|
||||||
|
if (params->guiPrepare) {
|
||||||
|
params->guiPrepare();
|
||||||
|
}
|
||||||
unsigned y = GUIFontHeight(params->font);
|
unsigned y = GUIFontHeight(params->font);
|
||||||
GUIFontPrint(params->font, 0, y, GUI_TEXT_LEFT, 0xFFFFFFFF, menu->title);
|
GUIFontPrint(params->font, 0, y, GUI_TEXT_LEFT, 0xFFFFFFFF, menu->title);
|
||||||
y += 2 * GUIFontHeight(params->font);
|
y += 2 * GUIFontHeight(params->font);
|
||||||
|
@ -80,6 +86,9 @@ enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* men
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (params->guiFinish) {
|
||||||
|
params->guiFinish();
|
||||||
|
}
|
||||||
y += GUIFontHeight(params->font) * 2;
|
y += GUIFontHeight(params->font) * 2;
|
||||||
|
|
||||||
params->drawEnd();
|
params->drawEnd();
|
||||||
|
|
|
@ -14,10 +14,13 @@ struct GUIMenuItem {
|
||||||
};
|
};
|
||||||
|
|
||||||
DECLARE_VECTOR(GUIMenuItemList, struct GUIMenuItem);
|
DECLARE_VECTOR(GUIMenuItemList, struct GUIMenuItem);
|
||||||
|
|
||||||
|
struct GUIBackground;
|
||||||
struct GUIMenu {
|
struct GUIMenu {
|
||||||
const char* title;
|
const char* title;
|
||||||
struct GUIMenuItemList items;
|
struct GUIMenuItemList items;
|
||||||
size_t index;
|
size_t index;
|
||||||
|
struct GUIBackground* background;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum GUIMenuExitReason {
|
enum GUIMenuExitReason {
|
||||||
|
|
Loading…
Reference in New Issue