GUI: Add message box API
Jeffrey Pfau jeffrey@endrift.com
Mon, 22 Aug 2016 17:30:56 -0700
4 files changed,
95 insertions(+),
43 deletions(-)
M
src/feature/gui/gui-runner.c
→
src/feature/gui/gui-runner.c
@@ -261,7 +261,6 @@ *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Configure", .data = (void*) RUNNER_CONFIG };
*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 @@ }
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) {
M
src/util/gui.c
→
src/util/gui.c
@@ -30,3 +30,40 @@ if (heldInput) {
*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; + } +}