1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-22 11:56:42 +00:00

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

@ -11,8 +11,8 @@
MenuEntry_t topEntries[] = { MenuEntry_t topEntries[] = {
{.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Back"}, {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Back"},
{.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Option2"}, {.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "Clipboard -> Current folder"},
{.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Option3"} {.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "Current folder options"}
}; };
MenuEntry_t MakeMenuOutFSEntry(FSEntry_t entry){ MenuEntry_t MakeMenuOutFSEntry(FSEntry_t entry){
@ -25,17 +25,6 @@ MenuEntry_t MakeMenuOutFSEntry(FSEntry_t entry){
#define maxYOnScreen 35 #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){ void clearFileVector(Vector_t *v){
vecPDefArray(FSEntry_t*, entries, v); vecPDefArray(FSEntry_t*, entries, v);
for (int i = 0; i < v->count; i++) for (int i = 0; i < v->count; i++)
@ -63,8 +52,7 @@ void FileExplorer(char *path){
vecAddElem(&entries, a); 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, ENABLEB | ENABLEPAGECOUNT, (int)fileVec.count);
res = newMenu(&entries, res, 50, maxYOnScreen, NULL, &fileVec, true, fileVec.count);
if (res < 3) { if (res < 3) {
if (!strcmp(storedPath, path)){ if (!strcmp(storedPath, path)){

View file

@ -315,13 +315,9 @@ void gfx_puts(const char *s)
} }
void gfx_puts_small(const char *s){ void gfx_puts_small(const char *s){
if (!s || gfx_con.mute)
return;
gfx_con.fntsz = 8; gfx_con.fntsz = 8;
for (; *s; s++) gfx_puts(s);
gfx_putc(*s);
gfx_con.fntsz = 16; gfx_con.fntsz = 16;
} }
@ -352,7 +348,7 @@ static void _gfx_putn(u32 v, int base, char fill, int fcnt)
if (base > 36) if (base > 36)
return; return;
bool minus = (base == 10 && v & 80000000); bool minus = (base == 10 && v & 0x80000000);
if (minus) if (minus)
v = (v ^ 0xFFFFFFFF) + 1; v = (v ^ 0xFFFFFFFF) + 1;

View file

@ -3,6 +3,7 @@
#define COLOR_WHITE 0xFFFFFFFF #define COLOR_WHITE 0xFFFFFFFF
#define COLOR_DEFAULT 0xFF1B1B1B #define COLOR_DEFAULT 0xFF1B1B1B
#define COLOR_GREY 0xFF888888
#define COLORTORGB(color) (color & 0x00FFFFFF) #define COLORTORGB(color) (color & 0x00FFFFFF)
#define SETCOLOR(fg, bg) gfx_con_setcol(fg, 1, bg) #define SETCOLOR(fg, bg) gfx_con_setcol(fg, 1, bg)

View file

@ -14,35 +14,40 @@ const char *sizeDefs[] = {
}; };
void _printEntry(MenuEntry_t entry, u32 maxLen, u8 highlighted){ 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); (highlighted) ? SETCOLOR(COLOR_DEFAULT, FromRGBtoU32(entry.R, entry.G, entry.B)) : SETCOLOR(FromRGBtoU32(entry.R, entry.G, entry.B), COLOR_DEFAULT);
if (entry.icon){ if (entry.icon){
gfx_putc(entry.icon); gfx_putc(entry.icon);
maxLen--; gfx_putc(' ');
maxLen -= 2;
} }
u32 curX = 0, curY = 0; u32 curX = 0, curY = 0;
gfx_con_getpos(&curX, &curY); gfx_con_getpos(&curX, &curY);
gfx_puts_limit(entry.name, maxLen - 8); gfx_puts_limit(entry.name, maxLen - 8);
if (entry.showSize){ if (entry.showSize){
SETCOLOR(COLOR_BLUE, COLOR_DEFAULT);
gfx_con_setpos(curX + (maxLen - 6) * 16, curY); 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_puts_small(sizeDefs[entry.sizeDef]);
} }
gfx_putc('\n'); 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)); Vector_t ent = vecFromArray(entries, entryCount, sizeof(MenuEntry_t));
gfx_clearscreen(); gfx_clearscreen();
gfx_putc('\n'); 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) if (paths[res] != NULL)
paths[res](); 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); vecPDefArray(MenuEntry_t*, entries, vec);
u32 selected = startIndex; u32 selected = startIndex;
@ -52,78 +57,76 @@ int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, menuE
u32 lastIndex = selected; u32 lastIndex = selected;
u32 startX = 0, startY = 0; u32 startX = 0, startY = 0;
gfx_con_getpos(&startX, &startY); 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(); Input_t *input = hidRead();
// Maybe add a check here so you don't read OOB by providing a too high startindex? // Maybe add a check here so you don't read OOB by providing a too high startindex?
//u32 lastPress = 0xFFFF3FFF; u32 lastPress = 0x666 + get_tmr_ms();
//u32 holdTimer = 500; u32 holdTimer = 300;
while(1) { while(1) {
if (redrawScreen){ u32 lastDraw = get_tmr_ms();
if (totalEntries > screenLenY){ if (redrawScreen || options & ALWAYSREDRAW){
gfx_con_setpos(startX, startY - 16); if (options & ENABLEPAGECOUNT){
gfx_con_setpos(startX, startY - 32);
RESETCOLOR; 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_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; int start = selected / screenLenY * screenLenY;
for (int i = start; i < MIN(vec->count, start + screenLenY); i++) for (int i = start; i < MIN(vec->count, start + screenLenY); i++)
_printEntry(entries[i], screenLenX, (i == selected)); _printEntry(entries[i], screenLenX, (i == selected));
} }
else if (lastIndex != selected) { else if (lastIndex != selected) {
u32 minLastCur = MIN(lastIndex, selected); u32 minLastCur = MIN(lastIndex, selected);
u32 maxLastCur = MAX(lastIndex, selected);
gfx_con_setpos(startX, startY + ((minLastCur % screenLenY) * 16)); gfx_con_setpos(startX, startY + ((minLastCur % screenLenY) * 16));
_printEntry(entries[minLastCur], screenLenX, (minLastCur == selected)); _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; lastIndex = selected;
/* SETCOLOR(COLOR_DEFAULT, COLOR_WHITE);
// i don't know what fuckery goes on here but this doesn't work. Will fix this later gfx_con_setpos(0, 704);
while (1){ gfx_printf("Time taken for screen draw: %dms ", get_tmr_ms() - lastDraw);
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;
}
}
*/
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){ while (1){
if (hidRead()->a) if (hidRead()->a)
return selected; return selected;
else if (input->b && enableB) else if (input->b && options & ENABLEB)
return 0; return 0;
else if (input->down || input->rDown || input->right){ //Rdown should probs not trigger a page change. Same for RUp 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; 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){ if (vec->count > selected + temp){
selected += temp; selected += temp;
@ -141,8 +144,12 @@ int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, menuE
break; break;
} }
} }
else
holdTimer = 300;
} }
lastPress = get_tmr_ms();
int m = (selected > lastIndex) ? 1 : -1; int m = (selected > lastIndex) ? 1 : -1;
while (selected > 0 && selected < vec->count - 1 && entries[selected].optionUnion & SKIPHIDEBITS) while (selected > 0 && selected < vec->count - 1 && entries[selected].optionUnion & SKIPHIDEBITS)
selected += m; selected += m;

View file

@ -31,5 +31,12 @@ typedef struct _menuEntry {
#define SKIPHIDEBITS 0x3000000 #define SKIPHIDEBITS 0x3000000
#define RGBCOLOR(r, g, b) (b << 16 | g << 8 | r) #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); #define SKIPBIT BIT(24)
void FunctionMenuHandler(MenuEntry_t *entries, int entryCount, menuPaths *paths, bool enableB); #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);

View file

@ -45,7 +45,7 @@
#include "gfx/menu.h" #include "gfx/menu.h"
#include "utils/vector.h" #include "utils/vector.h"
#include "gfx/gfxutils.h" #include "gfx/gfxutils.h"
#include "tegraexplorer/mainMenu.h" #include "tegraexplorer/mainmenu.h"
hekate_config h_cfg; hekate_config h_cfg;

View file

@ -1,4 +1,4 @@
#include "mainMenu.h" #include "mainmenu.h"
#include "../gfx/gfx.h" #include "../gfx/gfx.h"
#include "../gfx/gfxutils.h" #include "../gfx/gfxutils.h"
#include "../gfx/menu.h" #include "../gfx/menu.h"
@ -34,7 +34,7 @@ menuPaths mainMenuPaths[] = {
void EnterMainMenu(){ void EnterMainMenu(){
while (1){ while (1){
FunctionMenuHandler(mainMenuEntries, 4, mainMenuPaths, false); FunctionMenuHandler(mainMenuEntries, 4, mainMenuPaths, 0);
} }
} }