2020-05-01 23:50:08 +01:00
|
|
|
#include <string.h>
|
2020-03-17 23:41:09 +00:00
|
|
|
#include "menu.h"
|
|
|
|
#include "gfxutils.h"
|
|
|
|
#include "../common/types.h"
|
|
|
|
#include "../../utils/btn.h"
|
|
|
|
#include "../common/common.h"
|
|
|
|
#include "../../utils/util.h"
|
|
|
|
#include "../../mem/minerva.h"
|
2020-03-22 21:56:36 +00:00
|
|
|
#include "../../soc/gpio.h"
|
2020-05-01 21:42:49 +01:00
|
|
|
#include "../../hid/hid.h"
|
2020-05-02 12:05:06 +01:00
|
|
|
#include "../fs/fsutils.h"
|
2020-05-04 12:55:26 +01:00
|
|
|
#include "../utils/menuUtils.h"
|
2020-03-22 21:56:36 +00:00
|
|
|
|
|
|
|
extern void sd_unmount();
|
|
|
|
extern bool sd_inited;
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-05-04 12:55:26 +01:00
|
|
|
#pragma GCC push_options
|
|
|
|
#pragma GCC optimize ("O2")
|
2020-05-02 12:05:06 +01:00
|
|
|
|
2020-05-04 12:55:26 +01:00
|
|
|
void _printentry(menu_entry *entry, bool highlighted, bool refresh, const char *path){
|
|
|
|
u32 color = (entry->isMenu) ? entry->storage : ((entry->isDir) ? COLOR_WHITE : COLOR_VIOLET);
|
2020-05-02 12:05:06 +01:00
|
|
|
|
2020-05-04 12:55:26 +01:00
|
|
|
SWAPALLCOLOR((highlighted) ? COLOR_DEFAULT : color, (highlighted) ? color : COLOR_DEFAULT);
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-05-04 12:55:26 +01:00
|
|
|
if (!(entry->isMenu))
|
|
|
|
gfx_printf("%c ", (entry->isDir) ? 30 : 31);
|
2020-03-17 23:41:09 +00:00
|
|
|
|
|
|
|
if (refresh)
|
2020-05-02 12:05:06 +01:00
|
|
|
gfx_printandclear(entry->name, 37, 720);
|
2020-03-17 23:41:09 +00:00
|
|
|
else
|
2020-05-02 12:05:06 +01:00
|
|
|
gfx_printlength(37, entry->name);
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-05-04 12:55:26 +01:00
|
|
|
if (entry->property & (ISMENU | ISDIR))
|
2020-03-17 23:41:09 +00:00
|
|
|
gfx_printf("\n");
|
|
|
|
else {
|
2020-05-04 12:55:26 +01:00
|
|
|
if (entry->isNull){
|
|
|
|
u64 totalSize;
|
|
|
|
u32 sizeType = 0;
|
|
|
|
totalSize = fsutil_getfilesize(fsutil_getnextloc(path, entry->name));
|
|
|
|
|
|
|
|
while (totalSize > 1024){
|
|
|
|
totalSize /= 1024;
|
|
|
|
sizeType++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sizeType > 3)
|
|
|
|
sizeType = 3;
|
|
|
|
|
|
|
|
entry->size = sizeType;
|
|
|
|
entry->storage = totalSize;
|
|
|
|
SETBIT(entry->property, ISNULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SWAPALLCOLOR(COLOR_BLUE, COLOR_DEFAULT);
|
2020-05-02 12:05:06 +01:00
|
|
|
gfx_printf("\a%4d", entry->storage);
|
2020-04-23 13:40:55 +01:00
|
|
|
gfx_con.fntsz = 8;
|
2020-05-04 12:55:26 +01:00
|
|
|
gfx_printf("\n\e%s\n", gfx_file_size_names[entry->size]);
|
2020-04-23 13:40:55 +01:00
|
|
|
gfx_con.fntsz = 16;
|
2020-03-17 23:41:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-01 23:50:08 +01:00
|
|
|
|
2020-05-01 21:42:49 +01:00
|
|
|
bool disableB = false;
|
2020-05-04 12:55:26 +01:00
|
|
|
int menu_make(menu_entry *entries, int amount, const char *toptext){
|
2020-05-01 23:50:08 +01:00
|
|
|
int currentpos = 0, offset = 0, delay = 300, minscreen = 0, maxscreen = 39, calculatedamount = 0;
|
2020-05-02 12:05:06 +01:00
|
|
|
u32 scrolltimer, timer, sideY;
|
|
|
|
bool refresh = true;
|
2020-05-01 21:42:49 +01:00
|
|
|
Inputs *input = hidRead();
|
|
|
|
input->buttons = 0;
|
2020-03-17 23:41:09 +00:00
|
|
|
|
|
|
|
gfx_clearscreen();
|
|
|
|
|
2020-05-04 19:48:23 +01:00
|
|
|
calculatedamount = mu_countObjects(entries, amount, ISMENU);
|
2020-03-22 21:56:36 +00:00
|
|
|
|
2020-05-01 23:50:08 +01:00
|
|
|
gfx_con_setpos(0, 16);
|
2020-03-17 23:41:09 +00:00
|
|
|
|
|
|
|
SWAPCOLOR(COLOR_GREEN);
|
|
|
|
gfx_printlength(42, toptext);
|
|
|
|
RESETCOLOR;
|
|
|
|
|
2020-05-02 12:05:06 +01:00
|
|
|
gfx_sideSetY(48);
|
|
|
|
|
2020-05-01 23:50:08 +01:00
|
|
|
char *currentfolder = strrchr(toptext, '/');
|
|
|
|
if (currentfolder != NULL){
|
|
|
|
if (calculatedamount)
|
2020-05-02 12:05:06 +01:00
|
|
|
gfx_sideprintf("%d items in current dir\n\n", calculatedamount);
|
|
|
|
|
|
|
|
gfx_sideprintf("Current directory:\n");
|
|
|
|
|
2020-05-01 23:50:08 +01:00
|
|
|
if (*(currentfolder + 1) != 0)
|
|
|
|
currentfolder++;
|
|
|
|
SWAPCOLOR(COLOR_GREEN);
|
2020-05-02 12:05:06 +01:00
|
|
|
gfx_sideprintandclear(currentfolder, 28);
|
|
|
|
|
|
|
|
gfx_sideprintf("\n\n\n");
|
2020-05-01 23:50:08 +01:00
|
|
|
}
|
|
|
|
|
2020-05-02 12:05:06 +01:00
|
|
|
gfx_drawScrollBar(minscreen, maxscreen, amount);
|
|
|
|
|
2020-05-01 21:42:49 +01:00
|
|
|
while (!(input->a)){
|
2020-05-01 23:50:08 +01:00
|
|
|
gfx_con_setpos(0, 48);
|
2020-03-17 23:41:09 +00:00
|
|
|
timer = get_tmr_ms();
|
|
|
|
|
|
|
|
if (!currentpos){
|
|
|
|
while (currentpos < amount && entries[currentpos].property & (ISSKIP | ISHIDE))
|
|
|
|
currentpos++;
|
|
|
|
}
|
|
|
|
if (currentpos == amount - 1){
|
|
|
|
while (currentpos >= 1 && entries[currentpos].property & (ISSKIP | ISHIDE))
|
|
|
|
currentpos--;
|
|
|
|
}
|
|
|
|
|
2020-03-18 22:58:32 +00:00
|
|
|
if (currentpos > maxscreen){
|
|
|
|
offset += currentpos - maxscreen;
|
|
|
|
minscreen += currentpos - maxscreen;
|
|
|
|
maxscreen += currentpos - maxscreen;
|
|
|
|
refresh = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentpos < minscreen){
|
|
|
|
offset -= minscreen - currentpos;
|
|
|
|
maxscreen -= minscreen - currentpos;
|
|
|
|
minscreen -= minscreen - currentpos;
|
|
|
|
refresh = true;
|
|
|
|
}
|
|
|
|
|
2020-05-02 13:20:55 +01:00
|
|
|
if (refresh || currentfolder == NULL || !calculatedamount){
|
2020-05-02 12:05:06 +01:00
|
|
|
for (int i = 0 + offset; i < amount && i < 40 + offset; i++)
|
2020-05-04 12:55:26 +01:00
|
|
|
if (!(entries[i].isHide))
|
2020-05-02 12:05:06 +01:00
|
|
|
_printentry(&entries[i], (i == currentpos), refresh, toptext);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (currentpos - minscreen > 0){
|
|
|
|
gfx_con_setpos(0, 32 + (currentpos - minscreen) * 16);
|
|
|
|
_printentry(&entries[currentpos - 1], false, false, toptext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gfx_con_setpos(0, 48 + (currentpos - minscreen) * 16);
|
|
|
|
|
|
|
|
_printentry(&entries[currentpos], true, false, toptext);
|
|
|
|
|
|
|
|
if (currentpos < amount - 1 && currentpos < maxscreen)
|
|
|
|
_printentry(&entries[currentpos + 1], false, false, toptext);
|
|
|
|
}
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-05-01 23:50:08 +01:00
|
|
|
RESETCOLOR;
|
|
|
|
|
2020-05-02 12:05:06 +01:00
|
|
|
sideY = gfx_sideGetY();
|
2020-05-04 12:55:26 +01:00
|
|
|
if (!(entries[currentpos].isMenu)){
|
2020-05-02 12:05:06 +01:00
|
|
|
gfx_sideprintf("Current selection:\n");
|
2020-05-01 23:50:08 +01:00
|
|
|
SWAPCOLOR(COLOR_YELLOW);
|
2020-05-02 12:05:06 +01:00
|
|
|
gfx_sideprintandclear(entries[currentpos].name, 28);
|
2020-05-01 23:50:08 +01:00
|
|
|
RESETCOLOR;
|
2020-05-04 12:55:26 +01:00
|
|
|
gfx_sideprintf("Type: %s", (entries[currentpos].isDir) ? "Dir " : "File");
|
2020-05-02 12:05:06 +01:00
|
|
|
gfx_sideSetY(sideY);
|
2020-05-01 23:50:08 +01:00
|
|
|
}
|
|
|
|
else
|
2020-05-02 12:05:06 +01:00
|
|
|
gfx_boxGrey(800, sideY, 1279, sideY + 48, 0x1B);
|
2020-05-01 23:50:08 +01:00
|
|
|
|
|
|
|
gfx_con_setpos(0, 703);
|
|
|
|
SWAPCOLOR(COLOR_DEFAULT);
|
|
|
|
SWAPBGCOLOR(COLOR_WHITE);
|
2020-05-02 12:05:06 +01:00
|
|
|
gfx_printf("Time taken for screen draw: %dms ", get_tmr_ms() - timer);
|
|
|
|
|
|
|
|
if (refresh)
|
|
|
|
gfx_drawScrollBar(minscreen, maxscreen, amount);
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-05-02 15:40:40 +01:00
|
|
|
while (hidRead()->buttons & (KEY_B | KEY_A));
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-05-10 10:41:16 +01:00
|
|
|
scrolltimer = get_tmr_ms();
|
|
|
|
while (1){
|
2020-04-12 19:31:32 +01:00
|
|
|
if (sd_inited && !!gpio_read(GPIO_PORT_Z, GPIO_PIN_1)){
|
|
|
|
gfx_errDisplay("menu", ERR_SD_EJECTED, 0);
|
|
|
|
sd_unmount();
|
|
|
|
return -1;
|
2020-03-22 21:56:36 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 21:42:49 +01:00
|
|
|
input = hidRead();
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-05-10 10:41:16 +01:00
|
|
|
if (!(input->buttons & (KEY_A | KEY_LDOWN | KEY_LUP | KEY_B | KEY_RUP | KEY_RDOWN))){
|
2020-03-17 23:41:09 +00:00
|
|
|
delay = 300;
|
2020-05-10 10:41:16 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (input->buttons & (KEY_RDOWN | KEY_RUP)){
|
|
|
|
delay = 1;
|
|
|
|
input->Lup = input->Rup;
|
|
|
|
input->Ldown = input->Rdown;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (delay < 300){
|
|
|
|
if (scrolltimer + delay < get_tmr_ms()){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
2020-03-17 23:41:09 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 10:41:16 +01:00
|
|
|
if (delay > 46)
|
|
|
|
delay -= 45;
|
|
|
|
|
|
|
|
if (input->Lup && currentpos >= 1){
|
2020-03-17 23:41:09 +00:00
|
|
|
currentpos--;
|
|
|
|
while(entries[currentpos].property & (ISSKIP | ISHIDE) && currentpos >= 1)
|
|
|
|
currentpos--;
|
|
|
|
}
|
|
|
|
|
2020-05-10 10:41:16 +01:00
|
|
|
else if (input->Ldown && currentpos < amount - 1){
|
2020-03-17 23:41:09 +00:00
|
|
|
currentpos++;
|
|
|
|
while(entries[currentpos].property & (ISSKIP | ISHIDE) && currentpos < amount - 1)
|
|
|
|
currentpos++;
|
|
|
|
}
|
|
|
|
|
2020-05-01 21:42:49 +01:00
|
|
|
else if (input->b && !disableB){
|
|
|
|
currentpos = 0;
|
|
|
|
break;
|
|
|
|
}
|
2020-05-02 12:05:06 +01:00
|
|
|
|
|
|
|
refresh = false;
|
2020-03-17 23:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
minerva_periodic_training();
|
|
|
|
//return (mode) ? currentpos : entries[currentpos].property;
|
|
|
|
return currentpos;
|
2020-05-04 12:55:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma GCC pop_options
|