1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-13 23:46:42 +00:00
TegraExplorer/source/meme/graphics.c

143 lines
4.3 KiB
C
Raw Normal View History

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;
}
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);
}
void _printwithhighlight(int offset, int folderamount, char *items[], int highlight, unsigned int *muhbits, int *filesizes){
2019-08-15 21:16:48 +01:00
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);
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);
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);
2019-08-16 20:40:04 +01:00
if (!(muhbits[i + offset] & OPTION1)) { //should change later
char temp[6];
return_readable_byte_amounts(filesizes[i + offset], temp);
2019-08-16 20:40:04 +01:00
gfx_printf("%s", temp);
}
2019-08-15 21:16:48 +01:00
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];
int *filesizes;
int i = 0;
filesizes = (int*) calloc(500, sizeof(int));
gfx_con_setpos(0, 48);
for (i = 0; i < folderamount; i++){
if(!(muhbits[i] & OPTION1)){
char temppath[PATHSIZE];
strcpy(temppath, path);
strcat(temppath, "/");
strcat(temppath, items[i]);
filesizes[i] = getfilesize(temppath);
gfx_printf("Calcing filesizes: %d / %d\r", i, folderamount - 2);
}
}
2019-08-15 21:16:48 +01:00
_copystring(temp, path, 43);
gfx_con_setpos(0, 16);
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, filesizes);
2019-08-15 21:16:48 +01:00
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;
free(filesizes);
2019-08-15 21:16:48 +01:00
return ret;
}