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-03-22 21:56:36 +00:00
|
|
|
|
|
|
|
extern void sd_unmount();
|
|
|
|
extern bool sd_inited;
|
2020-03-17 23:41:09 +00:00
|
|
|
|
|
|
|
void _printentry(menu_entry entry, bool highlighted, bool refresh){
|
|
|
|
int size;
|
2020-03-19 12:00:42 +00:00
|
|
|
u32 color = (entry.property & ISMENU) ? entry.storage : ((entry.property & ISDIR) ? COLOR_WHITE : COLOR_VIOLET);
|
|
|
|
/*
|
2020-03-17 23:41:09 +00:00
|
|
|
if (entry.property & ISMENU)
|
|
|
|
SWAPCOLOR(entry.storage);
|
|
|
|
else if (entry.property & ISDIR)
|
|
|
|
SWAPCOLOR(COLOR_WHITE);
|
|
|
|
else {
|
|
|
|
SWAPCOLOR(COLOR_VIOLET);
|
2020-03-19 12:00:42 +00:00
|
|
|
}
|
|
|
|
*/
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-03-19 12:00:42 +00:00
|
|
|
if (!(entry.property & ISMENU && entry.property & ISDIR)){
|
2020-03-17 23:41:09 +00:00
|
|
|
for (size = 4; size < 8; size++)
|
|
|
|
if ((entry.property & (1 << size)))
|
|
|
|
break;
|
2020-03-19 12:00:42 +00:00
|
|
|
}
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-03-19 12:00:42 +00:00
|
|
|
|
|
|
|
/*
|
2020-03-17 23:41:09 +00:00
|
|
|
if (highlighted){
|
|
|
|
SWAPBGCOLOR(COLOR_WHITE);
|
|
|
|
if ((entry.property & ISMENU) ? entry.storage == COLOR_WHITE : entry.property & ISDIR)
|
|
|
|
SWAPCOLOR(COLOR_DEFAULT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SWAPBGCOLOR(COLOR_DEFAULT);
|
2020-03-19 12:00:42 +00:00
|
|
|
*/
|
|
|
|
SWAPCOLOR((highlighted) ? COLOR_DEFAULT : color);
|
|
|
|
SWAPBGCOLOR((highlighted) ? color : COLOR_DEFAULT);
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-05-01 23:50:08 +01:00
|
|
|
if (!(entry.property & ISMENU))
|
|
|
|
gfx_printf("%c ", (entry.property & ISDIR) ? 30 : 31);
|
2020-03-17 23:41:09 +00:00
|
|
|
|
|
|
|
if (refresh)
|
2020-05-01 23:50:08 +01:00
|
|
|
gfx_printandclear(entry.name, 37, 720);
|
2020-03-17 23:41:09 +00:00
|
|
|
else
|
|
|
|
gfx_printlength(37, entry.name);
|
|
|
|
|
|
|
|
if (entry.property & ISDIR || entry.property & ISMENU)
|
|
|
|
gfx_printf("\n");
|
|
|
|
else {
|
|
|
|
SWAPCOLOR(COLOR_BLUE);
|
2020-03-18 22:58:32 +00:00
|
|
|
SWAPBGCOLOR(COLOR_DEFAULT);
|
2020-04-23 13:40:55 +01:00
|
|
|
gfx_printf("\a%4d", entry.storage);
|
|
|
|
gfx_con.fntsz = 8;
|
|
|
|
gfx_printf("\n\e%s\n", gfx_file_size_names[size - 4]);
|
|
|
|
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-03-17 23:41:09 +00:00
|
|
|
int menu_make(menu_entry *entries, int amount, char *toptext){
|
2020-05-01 23:50:08 +01:00
|
|
|
int currentpos = 0, offset = 0, delay = 300, minscreen = 0, maxscreen = 39, calculatedamount = 0;
|
2020-03-17 23:41:09 +00:00
|
|
|
u32 scrolltimer, timer;
|
|
|
|
bool refresh = false;
|
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-03-22 21:56:36 +00:00
|
|
|
for (int i = 0; i < amount; i++)
|
|
|
|
if (!(entries[i].property & ISMENU))
|
|
|
|
calculatedamount++;
|
|
|
|
|
2020-05-01 23:50:08 +01:00
|
|
|
gfx_con_setpos(0, 16);
|
|
|
|
/*
|
2020-03-22 21:56:36 +00:00
|
|
|
if (calculatedamount){
|
|
|
|
SWAPCOLOR(COLOR_DEFAULT);
|
|
|
|
SWAPBGCOLOR(COLOR_WHITE);
|
2020-03-30 23:16:46 +01:00
|
|
|
gfx_printf("%3d entries\n", calculatedamount);
|
2020-03-22 21:56:36 +00:00
|
|
|
RESETCOLOR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gfx_printf("\n");
|
2020-05-01 23:50:08 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-03-17 23:41:09 +00:00
|
|
|
|
|
|
|
SWAPCOLOR(COLOR_GREEN);
|
|
|
|
gfx_printlength(42, toptext);
|
|
|
|
RESETCOLOR;
|
|
|
|
|
2020-05-01 23:50:08 +01:00
|
|
|
char *currentfolder = strrchr(toptext, '/');
|
|
|
|
if (currentfolder != NULL){
|
|
|
|
gfx_con_setpos(800, 48);
|
|
|
|
if (calculatedamount)
|
|
|
|
gfx_printf("%d items in curr. folder\n%j", calculatedamount, 800);
|
|
|
|
gfx_printf("Current directory:\n%j", 800);
|
|
|
|
if (*(currentfolder + 1) != 0)
|
|
|
|
currentfolder++;
|
|
|
|
SWAPCOLOR(COLOR_GREEN);
|
|
|
|
gfx_printlength(28, currentfolder);
|
|
|
|
}
|
|
|
|
|
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();
|
2020-03-18 22:58:32 +00:00
|
|
|
refresh = false;
|
2020-03-17 23:41:09 +00:00
|
|
|
|
|
|
|
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-01 23:50:08 +01:00
|
|
|
for (int i = 0 + offset; i < amount && i < 40 + offset; i++)
|
2020-03-17 23:41:09 +00:00
|
|
|
if (!(entries[i].property & ISHIDE))
|
|
|
|
_printentry(entries[i], (i == currentpos), refresh);
|
|
|
|
|
2020-05-01 23:50:08 +01:00
|
|
|
RESETCOLOR;
|
|
|
|
|
|
|
|
if (!(entries[currentpos].property & ISMENU)){
|
|
|
|
gfx_con_setpos(800, 144);
|
|
|
|
gfx_printf("Current selection:\n%j", 800);
|
|
|
|
SWAPCOLOR(COLOR_YELLOW);
|
|
|
|
gfx_printandclear(entries[currentpos].name, 28, 1279);
|
|
|
|
RESETCOLOR;
|
|
|
|
gfx_con_setpos(800, 175);
|
|
|
|
gfx_printf("Type: %s", (entries[currentpos].property & ISDIR) ? "Dir " : "File");
|
|
|
|
}
|
|
|
|
else
|
2020-05-02 00:41:43 +01:00
|
|
|
gfx_boxGrey(800, 144, 1279, 190, 0x1B);
|
2020-05-01 23:50:08 +01:00
|
|
|
|
|
|
|
gfx_con_setpos(0, 703);
|
|
|
|
SWAPCOLOR(COLOR_DEFAULT);
|
|
|
|
SWAPBGCOLOR(COLOR_WHITE);
|
|
|
|
gfx_printf("%s %s | Time taken for screen draw: %dms ", (offset + 40 < amount) ? "v" : " ", (offset > 0) ? "^" : " ", get_tmr_ms() - timer);
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-05-01 21:42:49 +01:00
|
|
|
while ((input = hidRead())->buttons & (KEY_B | KEY_A));
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-05-01 21:42:49 +01:00
|
|
|
input->buttons = 0;
|
|
|
|
while (!(input->buttons & (KEY_A | KEY_LDOWN | KEY_LUP | KEY_B | KEY_RUP | KEY_RDOWN))){
|
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-01 21:42:49 +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;
|
|
|
|
|
|
|
|
if (delay < 300){
|
|
|
|
scrolltimer = get_tmr_ms();
|
2020-05-01 21:42:49 +01:00
|
|
|
while (input->buttons & (KEY_A | KEY_LDOWN | KEY_LUP | KEY_B | KEY_RUP | KEY_RDOWN)){
|
2020-03-17 23:41:09 +00:00
|
|
|
if (scrolltimer + delay <= get_tmr_ms())
|
|
|
|
break;
|
|
|
|
|
2020-05-01 21:42:49 +01:00
|
|
|
input = hidRead();
|
2020-03-17 23:41:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-01 21:42:49 +01:00
|
|
|
if (delay > 46 && input->buttons & (KEY_A | KEY_LDOWN | KEY_LUP | KEY_B | KEY_RUP | KEY_RDOWN))
|
2020-03-17 23:41:09 +00:00
|
|
|
delay -= 45;
|
2020-05-01 21:42:49 +01:00
|
|
|
|
|
|
|
if (input->buttons & (KEY_RUP | KEY_RDOWN))
|
|
|
|
delay = 1;
|
2020-03-17 23:41:09 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 21:42:49 +01:00
|
|
|
if (input->buttons & (KEY_LUP | KEY_RUP) && currentpos >= 1){
|
2020-03-17 23:41:09 +00:00
|
|
|
currentpos--;
|
|
|
|
while(entries[currentpos].property & (ISSKIP | ISHIDE) && currentpos >= 1)
|
|
|
|
currentpos--;
|
|
|
|
}
|
|
|
|
|
2020-05-01 21:42:49 +01:00
|
|
|
else if (input->buttons & (KEY_LDOWN | KEY_RDOWN) && 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-03-17 23:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
minerva_periodic_training();
|
|
|
|
//return (mode) ? currentpos : entries[currentpos].property;
|
|
|
|
return currentpos;
|
|
|
|
}
|