mirror of https://github.com/mgba-emu/mgba.git
GUI: Add message box API
This commit is contained in:
parent
5aec67a0f7
commit
956f63bba3
|
@ -261,7 +261,6 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) {
|
|||
*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Reset game", .data = (void*) RUNNER_RESET };
|
||||
*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Exit game", .data = (void*) RUNNER_EXIT };
|
||||
|
||||
// TODO: Message box API
|
||||
runner->params.drawStart();
|
||||
if (runner->params.guiPrepare) {
|
||||
runner->params.guiPrepare();
|
||||
|
@ -288,18 +287,7 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) {
|
|||
|
||||
if (!found) {
|
||||
mLOG(GUI_RUNNER, WARN, "Failed to find core for %s!", path);
|
||||
int i;
|
||||
for (i = 0; i < 240; ++i) {
|
||||
runner->params.drawStart();
|
||||
if (runner->params.guiPrepare) {
|
||||
runner->params.guiPrepare();
|
||||
}
|
||||
GUIFontPrint(runner->params.font, runner->params.width / 2, (GUIFontHeight(runner->params.font) + runner->params.height) / 2, GUI_ALIGN_HCENTER, 0xFFFFFFFF, "Load failed!");
|
||||
if (runner->params.guiFinish) {
|
||||
runner->params.guiFinish();
|
||||
}
|
||||
runner->params.drawEnd();
|
||||
}
|
||||
GUIShowMessageBox(&runner->params, GUI_MESSAGE_BOX_OK, 240, "Load failed!");
|
||||
return;
|
||||
}
|
||||
if (runner->core->platform(runner->core) == PLATFORM_GBA) {
|
||||
|
|
|
@ -30,3 +30,40 @@ void GUIPollInput(struct GUIParams* params, uint32_t* newInputOut, uint32_t* hel
|
|||
*heldInput = input;
|
||||
}
|
||||
}
|
||||
|
||||
enum GUICursorState GUIPollCursor(struct GUIParams* params, unsigned* x, unsigned* y) {
|
||||
if (!params->pollCursor) {
|
||||
return GUI_CURSOR_NOT_PRESENT;
|
||||
}
|
||||
enum GUICursorState state = params->pollCursor(x, y);
|
||||
if (params->cursorState == GUI_CURSOR_DOWN) {
|
||||
int dragX = *x - params->cx;
|
||||
int dragY = *y - params->cy;
|
||||
if (dragX * dragX + dragY * dragY > 25) {
|
||||
params->cursorState = GUI_CURSOR_DRAGGING;
|
||||
return GUI_CURSOR_DRAGGING;
|
||||
}
|
||||
if (state == GUI_CURSOR_UP || state == GUI_CURSOR_NOT_PRESENT) {
|
||||
params->cursorState = GUI_CURSOR_UP;
|
||||
return GUI_CURSOR_CLICKED;
|
||||
}
|
||||
} else {
|
||||
params->cx = *x;
|
||||
params->cy = *y;
|
||||
}
|
||||
if (params->cursorState == GUI_CURSOR_DRAGGING) {
|
||||
if (state == GUI_CURSOR_UP || state == GUI_CURSOR_NOT_PRESENT) {
|
||||
params->cursorState = GUI_CURSOR_UP;
|
||||
return GUI_CURSOR_UP;
|
||||
}
|
||||
return GUI_CURSOR_DRAGGING;
|
||||
}
|
||||
params->cursorState = state;
|
||||
return params->cursorState;
|
||||
}
|
||||
|
||||
void GUIInvalidateKeys(struct GUIParams* params) {
|
||||
for (int i = 0; i < GUI_INPUT_MAX; ++i) {
|
||||
params->inputHistory[i] = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -193,41 +193,60 @@ enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* men
|
|||
return GUI_MENU_EXIT_CANCEL;
|
||||
}
|
||||
|
||||
enum GUICursorState GUIPollCursor(struct GUIParams* params, unsigned* x, unsigned* y) {
|
||||
if (!params->pollCursor) {
|
||||
return GUI_CURSOR_NOT_PRESENT;
|
||||
}
|
||||
enum GUICursorState state = params->pollCursor(x, y);
|
||||
if (params->cursorState == GUI_CURSOR_DOWN) {
|
||||
int dragX = *x - params->cx;
|
||||
int dragY = *y - params->cy;
|
||||
if (dragX * dragX + dragY * dragY > 25) {
|
||||
params->cursorState = GUI_CURSOR_DRAGGING;
|
||||
return GUI_CURSOR_DRAGGING;
|
||||
}
|
||||
if (state == GUI_CURSOR_UP || state == GUI_CURSOR_NOT_PRESENT) {
|
||||
params->cursorState = GUI_CURSOR_UP;
|
||||
return GUI_CURSOR_CLICKED;
|
||||
}
|
||||
} else {
|
||||
params->cx = *x;
|
||||
params->cy = *y;
|
||||
}
|
||||
if (params->cursorState == GUI_CURSOR_DRAGGING) {
|
||||
if (state == GUI_CURSOR_UP || state == GUI_CURSOR_NOT_PRESENT) {
|
||||
params->cursorState = GUI_CURSOR_UP;
|
||||
return GUI_CURSOR_UP;
|
||||
}
|
||||
return GUI_CURSOR_DRAGGING;
|
||||
}
|
||||
params->cursorState = state;
|
||||
return params->cursorState;
|
||||
}
|
||||
enum GUIMenuExitReason GUIShowMessageBox(struct GUIParams* params, int buttons, int frames, const char* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
char message[256] = {0};
|
||||
vsnprintf(message, sizeof(message) - 1, format, args);
|
||||
va_end(args);
|
||||
|
||||
void GUIInvalidateKeys(struct GUIParams* params) {
|
||||
for (int i = 0; i < GUI_INPUT_MAX; ++i) {
|
||||
params->inputHistory[i] = 0;
|
||||
while (true) {
|
||||
if (frames) {
|
||||
--frames;
|
||||
if (!frames) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
params->drawStart();
|
||||
if (params->guiPrepare) {
|
||||
params->guiPrepare();
|
||||
}
|
||||
GUIFontPrint(params->font, params->width / 2, (GUIFontHeight(params->font) + params->height) / 2, GUI_ALIGN_HCENTER, 0xFFFFFFFF, message);
|
||||
if (params->guiFinish) {
|
||||
params->guiFinish();
|
||||
}
|
||||
params->drawEnd();
|
||||
|
||||
uint32_t input = 0;
|
||||
GUIPollInput(params, &input, 0);
|
||||
if (input) {
|
||||
if (input & (1 << GUI_INPUT_SELECT)) {
|
||||
if (buttons & GUI_MESSAGE_BOX_OK) {
|
||||
return GUI_MENU_EXIT_ACCEPT;
|
||||
}
|
||||
if (buttons & GUI_MESSAGE_BOX_CANCEL) {
|
||||
return GUI_MENU_EXIT_CANCEL;
|
||||
}
|
||||
}
|
||||
if (input & (1 << GUI_INPUT_BACK)) {
|
||||
if (buttons & GUI_MESSAGE_BOX_CANCEL) {
|
||||
return GUI_MENU_EXIT_BACK;
|
||||
}
|
||||
if (buttons & GUI_MESSAGE_BOX_OK) {
|
||||
return GUI_MENU_EXIT_ACCEPT;
|
||||
}
|
||||
}
|
||||
if (input & (1 << GUI_INPUT_CANCEL)) {
|
||||
if (buttons & GUI_MESSAGE_BOX_CANCEL) {
|
||||
return GUI_MENU_EXIT_CANCEL;
|
||||
}
|
||||
if (buttons & GUI_MESSAGE_BOX_OK) {
|
||||
return GUI_MENU_EXIT_ACCEPT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return GUI_MENU_EXIT_CANCEL;
|
||||
}
|
||||
|
||||
void GUIDrawBattery(struct GUIParams* params) {
|
||||
|
|
|
@ -35,9 +35,17 @@ enum GUIMenuExitReason {
|
|||
GUI_MENU_EXIT_CANCEL,
|
||||
};
|
||||
|
||||
enum GUIMessageBoxButtons {
|
||||
GUI_MESSAGE_BOX_OK = 1,
|
||||
GUI_MESSAGE_BOX_CANCEL = 2
|
||||
};
|
||||
|
||||
struct GUIParams;
|
||||
enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* menu, struct GUIMenuItem** item);
|
||||
|
||||
ATTRIBUTE_FORMAT(printf, 4, 5)
|
||||
enum GUIMenuExitReason GUIShowMessageBox(struct GUIParams* params, int buttons, int frames, const char* format, ...);
|
||||
|
||||
void GUIDrawBattery(struct GUIParams* params);
|
||||
void GUIDrawClock(struct GUIParams* params);
|
||||
|
||||
|
|
Loading…
Reference in New Issue