misc fixes. Add Page/Count view.

This commit is contained in:
SuchMemeManySkill
2020-12-24 00:31:17 +01:00
parent d6c4204027
commit 0c0ccac855
7 changed files with 71 additions and 72 deletions

View File

@@ -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;