diff --git a/source/fs/menus/explorer.c b/source/fs/menus/explorer.c index 8b0d6a4..0a533f9 100644 --- a/source/fs/menus/explorer.c +++ b/source/fs/menus/explorer.c @@ -11,8 +11,8 @@ MenuEntry_t topEntries[] = { {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Back"}, - {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Option2"}, - {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Option3"} + {.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "Clipboard -> Current folder"}, + {.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "Current folder options"} }; MenuEntry_t MakeMenuOutFSEntry(FSEntry_t entry){ @@ -25,17 +25,6 @@ MenuEntry_t MakeMenuOutFSEntry(FSEntry_t entry){ #define maxYOnScreen 35 -void ExpandFileList(Vector_t *vec, void* data){ - Vector_t *fileVec = (Vector_t*)data; - vecPDefArray(FSEntry_t*, fsEntries, fileVec); - - int start = vec->count - 3; - for (int i = start; i < MIN(fileVec->count, start + maxYOnScreen); i++){ - MenuEntry_t a = MakeMenuOutFSEntry(fsEntries[i]); - vecAddElem(vec, a); - } -} - void clearFileVector(Vector_t *v){ vecPDefArray(FSEntry_t*, entries, v); for (int i = 0; i < v->count; i++) @@ -63,8 +52,7 @@ void FileExplorer(char *path){ vecAddElem(&entries, a); } - // ExpandFileList was first in NULL, but now we don't need it as we aren't loading the file size dynamically - res = newMenu(&entries, res, 50, maxYOnScreen, NULL, &fileVec, true, fileVec.count); + res = newMenu(&entries, res, 50, maxYOnScreen, ENABLEB | ENABLEPAGECOUNT, (int)fileVec.count); if (res < 3) { if (!strcmp(storedPath, path)){ diff --git a/source/gfx/gfx.c b/source/gfx/gfx.c index 1415d56..d12d3b8 100644 --- a/source/gfx/gfx.c +++ b/source/gfx/gfx.c @@ -315,13 +315,9 @@ void gfx_puts(const char *s) } void gfx_puts_small(const char *s){ - if (!s || gfx_con.mute) - return; - gfx_con.fntsz = 8; - for (; *s; s++) - gfx_putc(*s); + gfx_puts(s); gfx_con.fntsz = 16; } @@ -352,7 +348,7 @@ static void _gfx_putn(u32 v, int base, char fill, int fcnt) if (base > 36) return; - bool minus = (base == 10 && v & 80000000); + bool minus = (base == 10 && v & 0x80000000); if (minus) v = (v ^ 0xFFFFFFFF) + 1; diff --git a/source/gfx/gfxutils.h b/source/gfx/gfxutils.h index 0b063ca..84d22a7 100644 --- a/source/gfx/gfxutils.h +++ b/source/gfx/gfxutils.h @@ -3,6 +3,7 @@ #define COLOR_WHITE 0xFFFFFFFF #define COLOR_DEFAULT 0xFF1B1B1B +#define COLOR_GREY 0xFF888888 #define COLORTORGB(color) (color & 0x00FFFFFF) #define SETCOLOR(fg, bg) gfx_con_setcol(fg, 1, bg) diff --git a/source/gfx/menu.c b/source/gfx/menu.c index 8601c42..2480e82 100644 --- a/source/gfx/menu.c +++ b/source/gfx/menu.c @@ -14,35 +14,40 @@ const char *sizeDefs[] = { }; void _printEntry(MenuEntry_t entry, u32 maxLen, u8 highlighted){ + if (entry.hide) + return; + (highlighted) ? SETCOLOR(COLOR_DEFAULT, FromRGBtoU32(entry.R, entry.G, entry.B)) : SETCOLOR(FromRGBtoU32(entry.R, entry.G, entry.B), COLOR_DEFAULT); if (entry.icon){ gfx_putc(entry.icon); - maxLen--; + gfx_putc(' '); + maxLen -= 2; } u32 curX = 0, curY = 0; gfx_con_getpos(&curX, &curY); gfx_puts_limit(entry.name, maxLen - 8); if (entry.showSize){ + SETCOLOR(COLOR_BLUE, COLOR_DEFAULT); gfx_con_setpos(curX + (maxLen - 6) * 16, curY); - gfx_printf("%d", entry.size); + gfx_printf("%4d", entry.size); gfx_puts_small(sizeDefs[entry.sizeDef]); } gfx_putc('\n'); } -void FunctionMenuHandler(MenuEntry_t *entries, int entryCount, menuPaths *paths, bool enableB){ +void FunctionMenuHandler(MenuEntry_t *entries, int entryCount, menuPaths *paths, u8 options){ Vector_t ent = vecFromArray(entries, entryCount, sizeof(MenuEntry_t)); gfx_clearscreen(); gfx_putc('\n'); - int res = newMenu(&ent, 0, 79, 30, NULL, NULL, enableB, entryCount); + int res = newMenu(&ent, 0, 79, 30, options, entryCount); if (paths[res] != NULL) paths[res](); } -int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, menuEntriesGatherer gatherer, void *ctx, bool enableB, int totalEntries) { +int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, u8 options, int entryCount) { vecPDefArray(MenuEntry_t*, entries, vec); u32 selected = startIndex; @@ -52,78 +57,76 @@ int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, menuE u32 lastIndex = selected; u32 startX = 0, startY = 0; gfx_con_getpos(&startX, &startY); - if (totalEntries > screenLenY) - startY += 16; - bool redrawScreen = true; + if (options & ENABLEPAGECOUNT){ + screenLenY -= 2; + startY += 32; + } + + bool redrawScreen = true; Input_t *input = hidRead(); // Maybe add a check here so you don't read OOB by providing a too high startindex? - //u32 lastPress = 0xFFFF3FFF; - //u32 holdTimer = 500; + u32 lastPress = 0x666 + get_tmr_ms(); + u32 holdTimer = 300; while(1) { - if (redrawScreen){ - if (totalEntries > screenLenY){ - gfx_con_setpos(startX, startY - 16); + u32 lastDraw = get_tmr_ms(); + if (redrawScreen || options & ALWAYSREDRAW){ + if (options & ENABLEPAGECOUNT){ + gfx_con_setpos(startX, startY - 32); RESETCOLOR; - gfx_printf("Page %d / %d ", (selected / screenLenY) + 1, (totalEntries / screenLenY) + 1); + gfx_printf("Page %d / %d | Total %d entries\n", (selected / screenLenY) + 1, (vec->count / screenLenY) + 1, entryCount); } + gfx_con_setpos(startX, startY); - gfx_boxGrey(startX, startY, startX + screenLenX * 16, startY + screenLenY * 16, 0x1B); + + if (redrawScreen) + gfx_boxGrey(startX, startY, startX + screenLenX * 16, startY + screenLenY * 16, 0x1B); + int start = selected / screenLenY * screenLenY; for (int i = start; i < MIN(vec->count, start + screenLenY); i++) _printEntry(entries[i], screenLenX, (i == selected)); } else if (lastIndex != selected) { u32 minLastCur = MIN(lastIndex, selected); + u32 maxLastCur = MAX(lastIndex, selected); gfx_con_setpos(startX, startY + ((minLastCur % screenLenY) * 16)); _printEntry(entries[minLastCur], screenLenX, (minLastCur == selected)); - _printEntry(entries[minLastCur + 1], screenLenX, (minLastCur != selected)); + gfx_con_setpos(startX, startY + ((maxLastCur % screenLenY) * 16)); + _printEntry(entries[maxLastCur], screenLenX, (minLastCur != selected)); } lastIndex = selected; - /* - // i don't know what fuckery goes on here but this doesn't work. Will fix this later - while (1){ - hidRead(); - - if (!(input->buttons & WAITBUTTONS)){ - lastPress = 0; - holdTimer = 500; - break; - } - - - - if ((lastPress + holdTimer) < get_tmr_ms()){ - lastPress = get_tmr_ms(); - //if (holdTimer > 50) - // holdTimer -= 50; - break; - } - - } - */ + SETCOLOR(COLOR_DEFAULT, COLOR_WHITE); + gfx_con_setpos(0, 704); + gfx_printf("Time taken for screen draw: %dms ", get_tmr_ms() - lastDraw); + while(hidRead()){ + if (!(input->buttons)){ + holdTimer = 300; + break; + } + if (input->buttons & (JoyRUp | JoyRDown)) + holdTimer = 40; + + if ((lastPress + holdTimer) < get_tmr_ms()){ + if (holdTimer > 50) + holdTimer -= 50; + break; + } + } - while (hidRead()->buttons & WAITBUTTONS); while (1){ if (hidRead()->a) return selected; - else if (input->b && enableB) + else if (input->b && options & ENABLEB) return 0; else if (input->down || input->rDown || input->right){ //Rdown should probs not trigger a page change. Same for RUp u32 temp = (input->right) ? screenLenY : 1; - if (vec->count <= selected + temp){ - if (gatherer != NULL){ - gatherer(vec, ctx); - entries = vecPGetArray(MenuEntry_t*, vec); - } - } if (vec->count > selected + temp){ selected += temp; @@ -141,8 +144,12 @@ int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, menuE break; } } + else + holdTimer = 300; } + lastPress = get_tmr_ms(); + int m = (selected > lastIndex) ? 1 : -1; while (selected > 0 && selected < vec->count - 1 && entries[selected].optionUnion & SKIPHIDEBITS) selected += m; diff --git a/source/gfx/menu.h b/source/gfx/menu.h index 93f2b6d..fd1dece 100644 --- a/source/gfx/menu.h +++ b/source/gfx/menu.h @@ -31,5 +31,12 @@ typedef struct _menuEntry { #define SKIPHIDEBITS 0x3000000 #define RGBCOLOR(r, g, b) (b << 16 | g << 8 | r) -int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, menuEntriesGatherer gatherer, void *ctx, bool enableB, int totalEntries); -void FunctionMenuHandler(MenuEntry_t *entries, int entryCount, menuPaths *paths, bool enableB); \ No newline at end of file +#define SKIPBIT BIT(24) +#define HIDEBIT BIT(25) + +#define ENABLEB BIT(0) +#define ENABLEPAGECOUNT BIT(1) +#define ALWAYSREDRAW BIT(2) + +int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, u8 options, int entryCount); +void FunctionMenuHandler(MenuEntry_t *entries, int entryCount, menuPaths *paths, u8 options); \ No newline at end of file diff --git a/source/main.c b/source/main.c index 80847ec..eb7cdaf 100644 --- a/source/main.c +++ b/source/main.c @@ -45,7 +45,7 @@ #include "gfx/menu.h" #include "utils/vector.h" #include "gfx/gfxutils.h" -#include "tegraexplorer/mainMenu.h" +#include "tegraexplorer/mainmenu.h" hekate_config h_cfg; diff --git a/source/tegraexplorer/mainmenu.c b/source/tegraexplorer/mainmenu.c index 3927399..b06aabf 100644 --- a/source/tegraexplorer/mainmenu.c +++ b/source/tegraexplorer/mainmenu.c @@ -1,4 +1,4 @@ -#include "mainMenu.h" +#include "mainmenu.h" #include "../gfx/gfx.h" #include "../gfx/gfxutils.h" #include "../gfx/menu.h" @@ -34,7 +34,7 @@ menuPaths mainMenuPaths[] = { void EnterMainMenu(){ while (1){ - FunctionMenuHandler(mainMenuEntries, 4, mainMenuPaths, false); + FunctionMenuHandler(mainMenuEntries, 4, mainMenuPaths, 0); } }