2020-12-23 16:39:22 +00:00
|
|
|
#include "menu.h"
|
|
|
|
#include "../utils/vector.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "gfxutils.h"
|
|
|
|
#include "../hid/hid.h"
|
|
|
|
#include <utils/util.h>
|
|
|
|
#include <utils/btn.h>
|
2020-12-25 20:16:24 +00:00
|
|
|
#include <utils/sprintf.h>
|
|
|
|
#include <string.h>
|
2020-12-26 21:24:41 +00:00
|
|
|
#include <mem/minerva.h>
|
2020-12-23 16:39:22 +00:00
|
|
|
|
|
|
|
const char *sizeDefs[] = {
|
|
|
|
"B ",
|
|
|
|
"KB",
|
|
|
|
"MB",
|
|
|
|
"GB"
|
|
|
|
};
|
|
|
|
|
2020-12-25 20:16:24 +00:00
|
|
|
void _printEntry(MenuEntry_t entry, u32 maxLen, u8 highlighted, u32 bg){
|
2020-12-23 23:31:17 +00:00
|
|
|
if (entry.hide)
|
|
|
|
return;
|
|
|
|
|
2020-12-25 22:10:23 +00:00
|
|
|
(highlighted) ? SETCOLOR(bg, RGBUnionToU32(entry.optionUnion)) : SETCOLOR(RGBUnionToU32(entry.optionUnion), bg);
|
2020-12-23 16:39:22 +00:00
|
|
|
|
|
|
|
if (entry.icon){
|
|
|
|
gfx_putc(entry.icon);
|
2020-12-23 23:31:17 +00:00
|
|
|
gfx_putc(' ');
|
|
|
|
maxLen -= 2;
|
2020-12-23 16:39:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 curX = 0, curY = 0;
|
|
|
|
gfx_con_getpos(&curX, &curY);
|
2020-12-24 16:06:21 +00:00
|
|
|
gfx_puts_limit(entry.name, maxLen - ((entry.showSize) ? 8 : 0));
|
2020-12-23 16:39:22 +00:00
|
|
|
if (entry.showSize){
|
2020-12-25 20:16:24 +00:00
|
|
|
(highlighted) ? SETCOLOR(bg, COLOR_BLUE) : SETCOLOR(COLOR_BLUE, bg);
|
2020-12-23 16:39:22 +00:00
|
|
|
gfx_con_setpos(curX + (maxLen - 6) * 16, curY);
|
2020-12-23 23:31:17 +00:00
|
|
|
gfx_printf("%4d", entry.size);
|
2020-12-23 16:39:22 +00:00
|
|
|
gfx_puts_small(sizeDefs[entry.sizeDef]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx_putc('\n');
|
|
|
|
}
|
|
|
|
|
2020-12-23 23:31:17 +00:00
|
|
|
void FunctionMenuHandler(MenuEntry_t *entries, int entryCount, menuPaths *paths, u8 options){
|
2020-12-23 16:39:22 +00:00
|
|
|
Vector_t ent = vecFromArray(entries, entryCount, sizeof(MenuEntry_t));
|
|
|
|
gfx_clearscreen();
|
|
|
|
gfx_putc('\n');
|
2020-12-23 23:31:17 +00:00
|
|
|
int res = newMenu(&ent, 0, 79, 30, options, entryCount);
|
2020-12-23 16:39:22 +00:00
|
|
|
if (paths[res] != NULL)
|
|
|
|
paths[res]();
|
|
|
|
}
|
|
|
|
|
2020-12-23 23:31:17 +00:00
|
|
|
int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, u8 options, int entryCount) {
|
2020-12-23 16:39:22 +00:00
|
|
|
vecPDefArray(MenuEntry_t*, entries, vec);
|
|
|
|
u32 selected = startIndex;
|
|
|
|
|
|
|
|
while (entries[selected].skip || entries[selected].hide)
|
|
|
|
selected++;
|
|
|
|
|
|
|
|
u32 lastIndex = selected;
|
|
|
|
u32 startX = 0, startY = 0;
|
|
|
|
gfx_con_getpos(&startX, &startY);
|
|
|
|
|
2020-12-25 20:16:24 +00:00
|
|
|
u32 bgColor = (options & USELIGHTGREY) ? COLOR_DARKGREY : COLOR_DEFAULT;
|
|
|
|
|
|
|
|
/*
|
2020-12-23 23:31:17 +00:00
|
|
|
if (options & ENABLEPAGECOUNT){
|
|
|
|
screenLenY -= 2;
|
|
|
|
startY += 32;
|
|
|
|
}
|
2020-12-25 20:16:24 +00:00
|
|
|
*/
|
2020-12-23 23:31:17 +00:00
|
|
|
|
|
|
|
bool redrawScreen = true;
|
2020-12-23 16:39:22 +00:00
|
|
|
Input_t *input = hidRead();
|
|
|
|
|
|
|
|
// Maybe add a check here so you don't read OOB by providing a too high startindex?
|
|
|
|
|
2020-12-23 23:31:17 +00:00
|
|
|
u32 lastPress = 0x666 + get_tmr_ms();
|
|
|
|
u32 holdTimer = 300;
|
2020-12-23 16:39:22 +00:00
|
|
|
|
|
|
|
while(1) {
|
2020-12-23 23:31:17 +00:00
|
|
|
u32 lastDraw = get_tmr_ms();
|
|
|
|
if (redrawScreen || options & ALWAYSREDRAW){
|
|
|
|
if (options & ENABLEPAGECOUNT){
|
2020-12-25 20:16:24 +00:00
|
|
|
SETCOLOR(COLOR_DEFAULT, COLOR_WHITE);
|
|
|
|
char temp[40] = "";
|
2020-12-29 01:21:23 +00:00
|
|
|
sprintf(temp, " Page %d / %d | Total %d entries", (selected / screenLenY) + 1, ((vec->count - 1) / screenLenY) + 1, entryCount);
|
2020-12-25 20:16:24 +00:00
|
|
|
gfx_con_setpos(YLEFT - strlen(temp) * 18, 0);
|
|
|
|
gfx_printf(temp);
|
2020-12-23 16:39:22 +00:00
|
|
|
}
|
2020-12-23 23:31:17 +00:00
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
gfx_con_setpos(startX, startY);
|
2020-12-23 23:31:17 +00:00
|
|
|
|
2020-12-26 21:24:41 +00:00
|
|
|
if (redrawScreen){
|
|
|
|
minerva_periodic_training();
|
2020-12-25 20:16:24 +00:00
|
|
|
gfx_boxGrey(startX, startY, startX + screenLenX * 16, startY + screenLenY * 16, (options & USELIGHTGREY) ? 0x33 : 0x1B);
|
2020-12-26 21:24:41 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 23:31:17 +00:00
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
int start = selected / screenLenY * screenLenY;
|
2020-12-26 21:24:41 +00:00
|
|
|
gfx_con_setpos(startX, startY);
|
|
|
|
gfx_printf("%b", startX);
|
2020-12-24 16:06:21 +00:00
|
|
|
for (int i = start; i < MIN(vec->count, start + screenLenY); i++){
|
2020-12-25 20:16:24 +00:00
|
|
|
_printEntry(entries[i], screenLenX, (i == selected), bgColor);
|
2020-12-24 16:06:21 +00:00
|
|
|
}
|
2020-12-26 21:24:41 +00:00
|
|
|
gfx_printf("%b", 0);
|
2020-12-23 16:39:22 +00:00
|
|
|
}
|
|
|
|
else if (lastIndex != selected) {
|
|
|
|
u32 minLastCur = MIN(lastIndex, selected);
|
2020-12-23 23:31:17 +00:00
|
|
|
u32 maxLastCur = MAX(lastIndex, selected);
|
2020-12-23 16:39:22 +00:00
|
|
|
gfx_con_setpos(startX, startY + ((minLastCur % screenLenY) * 16));
|
2020-12-25 20:16:24 +00:00
|
|
|
_printEntry(entries[minLastCur], screenLenX, (minLastCur == selected), bgColor);
|
2020-12-23 23:31:17 +00:00
|
|
|
gfx_con_setpos(startX, startY + ((maxLastCur % screenLenY) * 16));
|
2020-12-25 20:16:24 +00:00
|
|
|
_printEntry(entries[maxLastCur], screenLenX, (minLastCur != selected), bgColor);
|
2020-12-23 16:39:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lastIndex = selected;
|
|
|
|
|
2020-12-23 23:31:17 +00:00
|
|
|
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;
|
2020-12-23 16:39:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-12-23 23:31:17 +00:00
|
|
|
if (input->buttons & (JoyRUp | JoyRDown))
|
|
|
|
holdTimer = 40;
|
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
if ((lastPress + holdTimer) < get_tmr_ms()){
|
2020-12-23 23:31:17 +00:00
|
|
|
if (holdTimer > 50)
|
|
|
|
holdTimer -= 50;
|
2020-12-23 16:39:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1){
|
|
|
|
if (hidRead()->a)
|
|
|
|
return selected;
|
2020-12-23 23:31:17 +00:00
|
|
|
else if (input->b && options & ENABLEB)
|
2020-12-23 16:39:22 +00:00
|
|
|
return 0;
|
|
|
|
else if (input->down || input->rDown || input->right){ //Rdown should probs not trigger a page change. Same for RUp
|
2020-12-24 23:20:30 +00:00
|
|
|
u32 temp = (input->right && !(input->down || input->rDown)) ? screenLenY : 1;
|
2020-12-23 16:39:22 +00:00
|
|
|
|
|
|
|
if (vec->count > selected + temp){
|
|
|
|
selected += temp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (input->right && (selected / screenLenY != (vec->count - 1) / screenLenY)){
|
|
|
|
selected = vec->count - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (input->up || input->rUp || input->left){
|
2020-12-24 23:20:30 +00:00
|
|
|
u32 temp = (input->left && !(input->up || input->rUp)) ? screenLenY : 1;
|
2020-12-23 16:39:22 +00:00
|
|
|
if (selected >= temp){
|
|
|
|
selected -= temp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-12-23 23:31:17 +00:00
|
|
|
else
|
|
|
|
holdTimer = 300;
|
2020-12-23 16:39:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 23:31:17 +00:00
|
|
|
lastPress = get_tmr_ms();
|
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
int m = (selected > lastIndex) ? 1 : -1;
|
|
|
|
while (selected > 0 && selected < vec->count - 1 && entries[selected].optionUnion & SKIPHIDEBITS)
|
|
|
|
selected += m;
|
|
|
|
|
|
|
|
if (entries[selected].optionUnion & SKIPHIDEBITS)
|
|
|
|
selected = lastIndex;
|
|
|
|
|
|
|
|
redrawScreen = (selected / screenLenY != lastIndex / screenLenY);
|
|
|
|
}
|
|
|
|
}
|