GUI: Header with time and battery level
Jeffrey Pfau jeffrey@endrift.com
Sat, 19 Sep 2015 00:32:49 -0700
8 files changed,
135 insertions(+),
41 deletions(-)
M
src/platform/3ds/main.c
→
src/platform/3ds/main.c
@@ -85,6 +85,21 @@ gfxSwapBuffersGpu();
gspWaitForEvent(GSPEVENT_VBlank0, false); } +static int _batteryState(void) { + u8 charge; + u8 adapter; + PTMU_GetBatteryLevel(0, &charge); + PTMU_GetBatteryChargeState(0, &adapter); + int state = 0; + if (adapter) { + state |= BATTERY_CHARGING; + } + if (charge > 0) { + --charge; + } + return state | charge; +} + static void _guiPrepare(void) { guiDrawn = GUI_ACTIVE | GUI_THIS_FRAME; int screen = screenMode < SM_PA_TOP ? GFX_BOTTOM : GFX_TOP;@@ -385,6 +400,7 @@ }
} int main() { + ptmInit(); hasSound = !csndInit(); rotation.d.sample = _sampleRotation;@@ -444,12 +460,13 @@ 320, 240,
font, "/", _drawStart, _drawEnd, _pollInput, _pollCursor, + _batteryState, _guiPrepare, _guiFinish, GUI_PARAMS_TRAIL }, .configExtra = (struct GUIMenuItem[]) { - { + { .title = "Screen mode", .data = "screenMode", .submenu = 0,@@ -496,5 +513,6 @@ linearFree(audioLeft);
linearFree(audioRight); } csndExit(); + ptmExit(); return 0; }
M
src/platform/psp2/main.c
→
src/platform/psp2/main.c
@@ -85,6 +85,7 @@ .params = {
PSP2_HORIZONTAL_PIXELS, PSP2_VERTICAL_PIXELS, font, "cache0:", _drawStart, _drawEnd, _pollInput, _pollCursor, + 0, 0, 0, GUI_PARAMS_TRAIL
M
src/platform/wii/main.c
→
src/platform/wii/main.c
@@ -158,6 +158,7 @@ 352, 230,
font, "/", _drawStart, _drawEnd, _pollInput, _pollCursor, + 0, _guiPrepare, _guiFinish, GUI_PARAMS_TRAIL
M
src/util/gui.c
→
src/util/gui.c
@@ -30,40 +30,3 @@ if (heldInput) {
*heldInput = input; } } - -enum GUICursorState GUIPollCursor(struct GUIParams* params, int* x, int* 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; - } -}
M
src/util/gui.h
→
src/util/gui.h
@@ -36,6 +36,16 @@ GUI_CURSOR_CLICKED,
GUI_CURSOR_DRAGGING }; +enum { + BATTERY_EMPTY = 0, + BATTERY_LOW = 1, + BATTERY_HALF = 2, + BATTERY_HIGH = 3, + BATTERY_FULL = 4, + + BATTERY_CHARGING = 8 +}; + struct GUIBackground { void (*draw)(struct GUIBackground*, void* context); };@@ -50,6 +60,7 @@ void (*drawStart)(void);
void (*drawEnd)(void); uint32_t (*pollInput)(void); enum GUICursorState (*pollCursor)(int* x, int* y); + int (*batteryState)(void); void (*guiPrepare)(void); void (*guiFinish)(void);
M
src/util/gui/file-select.c
→
src/util/gui/file-select.c
@@ -103,8 +103,8 @@ 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 %zu of %zu)", i, items); + GUIFontPrintf(params->font, 0, GUIFontHeight(params->font), GUI_TEXT_LEFT, 0xFFFFFFFF, "(scanning item %zu of %zu)", i, items); + GUIFontPrintf(params->font, 0, GUIFontHeight(params->font) * 2, GUI_TEXT_LEFT, 0xFFFFFFFF, "%s", currentPath); if (params->guiFinish) { params->guiFinish(); }@@ -130,7 +130,8 @@ }
bool GUISelectFile(struct GUIParams* params, char* outPath, size_t outLen, bool (*filter)(struct VFile*)) { struct GUIMenu menu = { - .title = params->currentPath, + .title = "Select file", + .subtitle = params->currentPath, .index = params->fileIndex, }; GUIMenuItemListInit(&menu.items, 0);