2019-08-15 21:16:48 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "../gfx/di.h"
|
|
|
|
#include "../gfx/gfx.h"
|
|
|
|
#include "../utils/btn.h"
|
|
|
|
#include "../utils/util.h"
|
|
|
|
#include "graphics.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
int _copystring(char *out, const char *in, int copynumb){
|
|
|
|
strncpy(out, in, copynumb - 1);
|
|
|
|
int strlength = strlen(in);
|
|
|
|
if (strlength > copynumb + 1) strlength = copynumb;
|
|
|
|
memset(out + strlength, '\0', 1);
|
|
|
|
int ret = copynumb - strlength;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-08-16 15:13:58 +01:00
|
|
|
int messagebox(char *message){
|
|
|
|
int ret = -1;
|
|
|
|
meme_clearscreen();
|
|
|
|
gfx_printf("%s", message);
|
|
|
|
u8 res = btn_wait();
|
|
|
|
if (res & BTN_POWER) ret = 0;
|
|
|
|
else ret = 1;
|
|
|
|
meme_clearscreen();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int gfx_menulist(int ypos, char *list[], int length){
|
|
|
|
int i = 0;
|
|
|
|
int highlight = 1;
|
|
|
|
while(1){
|
|
|
|
gfx_con_setpos(0, ypos);
|
|
|
|
while(i < length){
|
|
|
|
if (i == highlight - 1) gfx_printf("%k%p%s%k%p\n", COLOR_DEFAULT, COLOR_WHITE, list[i], COLOR_WHITE, COLOR_DEFAULT);
|
|
|
|
else gfx_printf("%s\n", list[i]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
i = 0;
|
|
|
|
u8 res = btn_wait();
|
|
|
|
if (res & BTN_VOL_UP) highlight--;
|
|
|
|
else if (res & BTN_VOL_DOWN) highlight++;
|
|
|
|
else if (res & BTN_POWER) break;
|
|
|
|
if (highlight < 1) highlight = 1;
|
|
|
|
if (highlight > length) highlight = length;
|
|
|
|
}
|
|
|
|
return highlight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void meme_clearscreen(){
|
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
|
|
|
gfx_box(0, 0, 719, 15, COLOR_WHITE);
|
|
|
|
gfx_printf("%k%pTegraExplorer, by SuchMemeManySkill\n%k%p", COLOR_DEFAULT, COLOR_WHITE, COLOR_WHITE, COLOR_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2019-08-15 21:16:48 +01:00
|
|
|
void _printwithhighlight(int offset, int folderamount, char *items[], int highlight, unsigned int *muhbits){
|
|
|
|
char temp[39];
|
|
|
|
int i = 0;
|
2019-08-16 15:21:02 +01:00
|
|
|
int ret = 0;
|
2019-08-15 21:16:48 +01:00
|
|
|
gfx_con_setpos(0, 32);
|
|
|
|
while(i < folderamount && i < 76){
|
|
|
|
ret = _copystring(temp, items[i + offset], 39);
|
2019-08-15 21:23:56 +01:00
|
|
|
if(i == highlight - 1) gfx_printf("\n%k%p%s%k%p", COLOR_DEFAULT, COLOR_WHITE, temp, COLOR_WHITE, COLOR_DEFAULT);
|
2019-08-16 15:13:58 +01:00
|
|
|
else if ((i == 0 || i == 1) && offset == 0) gfx_printf("%k\n%s%k", COLOR_ORANGE, temp, COLOR_WHITE);
|
2019-08-16 15:21:02 +01:00
|
|
|
else if (muhbits[i+offset] & OPTION1) gfx_printf("\n%s", temp);
|
2019-08-16 17:40:09 +01:00
|
|
|
else gfx_printf("%k\n%s%k", COLOR_VIOLET, temp, COLOR_WHITE);
|
2019-08-15 21:23:56 +01:00
|
|
|
|
2019-08-15 21:16:48 +01:00
|
|
|
while(ret >= 0){
|
|
|
|
gfx_printf(" ");
|
|
|
|
ret = ret - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx_con.x = 720 - (16 * 6);
|
|
|
|
if (muhbits[i + offset] & OPTION1) gfx_printf("DIR");
|
|
|
|
else gfx_printf("FILE");
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int fileexplorergui(char *items[], unsigned int *muhbits, const char path[], int folderamount){
|
|
|
|
bool change = true;
|
|
|
|
int select = 1;
|
|
|
|
int sleepvalue = 300;
|
|
|
|
int offset = 0;
|
|
|
|
char temp[43];
|
|
|
|
gfx_con_setpos(0, 16);
|
|
|
|
_copystring(temp, path, 43);
|
2019-08-15 21:23:56 +01:00
|
|
|
gfx_printf("%k%s\n%k", COLOR_GREEN, temp, COLOR_WHITE);
|
2019-08-15 21:16:48 +01:00
|
|
|
while(1){
|
|
|
|
if (change){
|
|
|
|
_printwithhighlight(offset, folderamount, items, select, muhbits);
|
|
|
|
change = false;
|
|
|
|
msleep(sleepvalue);
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 res = btn_read();
|
|
|
|
if (res & BTN_VOL_UP){
|
|
|
|
select = select - 1, change = true;
|
|
|
|
sleepvalue = sleepvalue - 75;
|
|
|
|
}
|
|
|
|
else if (res & BTN_VOL_DOWN){
|
|
|
|
select++, change = true;
|
|
|
|
sleepvalue = sleepvalue - 75;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sleepvalue = 300;
|
|
|
|
}
|
|
|
|
if (res & BTN_POWER) break;
|
|
|
|
if (select < 1){
|
|
|
|
select = 1;
|
|
|
|
if (offset > 0) offset = offset - 1;
|
|
|
|
}
|
|
|
|
if (select > folderamount) select = folderamount;
|
|
|
|
if (select > 76){
|
|
|
|
select = 76;
|
|
|
|
if (76 + offset < folderamount) offset++;
|
|
|
|
}
|
|
|
|
if (sleepvalue < 30) sleepvalue = 30;
|
|
|
|
}
|
|
|
|
int ret = select + offset;
|
|
|
|
return ret;
|
|
|
|
}
|