Start gfx rewrite & reorganize TE

This commit is contained in:
Such Meme, Many Skill
2020-03-18 00:41:09 +01:00
parent 761ceb7dbe
commit 6aed4ad7b3
16 changed files with 570 additions and 62 deletions

View File

@@ -0,0 +1,112 @@
#include "gfxutils.h"
#include <string.h>
#include <stdarg.h>
#include "menu.h"
#include "../../gfx/gfx.h"
#include "../../power/max17050.h"
#include "../../utils/btn.h"
#include "../../utils/util.h"
#include "../../mem/heap.h"
void gfx_clearscreen(){
int battery = 0;
max17050_get_property(MAX17050_RepSOC, &battery);
gfx_clear_grey(0x1B);
SWAPCOLOR(COLOR_DEFAULT);
SWAPBGCOLOR(COLOR_WHITE);
gfx_box(0, 1263, 719, 1279, COLOR_WHITE);
gfx_con_setpos(0, 1263);
gfx_printf("Move: Vol+/- | Select: Pow | Battery: %3d%%", battery >> 8);
gfx_box(0, 0, 719, 15, COLOR_WHITE);
gfx_con_setpos(0, 0);
gfx_printf("Tegraexplorer v1.3.3\n");
RESETCOLOR;
}
int gfx_message(u32 color, const char* message, ...){
va_list ap;
va_start(ap, message);
gfx_clearscreen();
SWAPCOLOR(color);
gfx_vprintf(message, ap);
va_end(ap);
return btn_wait();
}
int gfx_errprint(u32 color, int func, int err, int add){
gfx_clearscreen();
SWAPCOLOR(COLOR_ORANGE);
gfx_printf("\nAn error occured:\n\n");
gfx_printf("Function: %s\nErrcode: %d\nDesc: %s\n");
if (add)
gfx_printf("Additional info: %d");
gfx_printf("\nPress any button to return");
RESETCOLOR;
return btn_wait();
}
int gfx_makewaitmenu(char *hiddenmessage, int timer){
int res;
u32 start = get_tmr_s();
while (btn_read() != 0);
while(1){
res = btn_read();
if (res & BTN_VOL_DOWN || res & BTN_VOL_UP)
return 0;
if (start + timer > get_tmr_s())
gfx_printf("\r<Wait %d seconds> ", timer + start - get_tmr_s());
else if (res & BTN_POWER)
return 1;
else
gfx_printf("\r%s", hiddenmessage);
}
}
void gfx_printlength(int size, char *toprint){
char *temp;
temp = (char*) malloc (size + 1);
if (strlen(toprint) > size){
strlcpy(temp, toprint, size);
memset(temp + size - 3, '.', 3);
memset(temp + size, '\0', 1);
}
else
strcpy(temp, toprint);
gfx_printf("%s", temp);
free(temp);
}
void gfx_printandclear(char *in, int length){
u32 x, y;
gfx_printlength(length, in);
gfx_con_getpos(&x, &y);
gfx_box(x, y, 719, y + 16, COLOR_DEFAULT);
}
void gfx_printfilesize(int size, char *type){
SWAPCOLOR(COLOR_VIOLET);
gfx_printf("\a%4d\e%s", size, type);
RESETCOLOR;
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "../../gfx/gfx.h"
#include "../../utils/types.h"
#define SWAPCOLOR(color) gfx_printf("%k", color)
#define SWAPBGCOLOR(color) gfx_printf("%K", color)
#define RESETCOLOR gfx_printf("%k%K", COLOR_WHITE, COLOR_DEFAULT)
void gfx_clearscreen();
int gfx_message(u32 color, const char* message, ...);
int gfx_errprint(u32 color, int func, int err, int add);
int gfx_makewaitmenu(char *hiddenmessage, int timer);
void gfx_printlength(int size, char *toprint);
void gfx_printandclear(char *in, int length);
void gfx_printfilesize(int size, char *type);

View File

@@ -0,0 +1,123 @@
#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"
void _printentry(menu_entry entry, bool highlighted, bool refresh){
int size;
if (entry.property & ISMENU)
SWAPCOLOR(entry.storage);
else if (entry.property & ISDIR)
SWAPCOLOR(COLOR_WHITE);
else {
SWAPCOLOR(COLOR_VIOLET);
for (size = 4; size < 8; size++)
if ((entry.property & (1 << size)))
break;
}
if (highlighted){
SWAPBGCOLOR(COLOR_WHITE);
if ((entry.property & ISMENU) ? entry.storage == COLOR_WHITE : entry.property & ISDIR)
SWAPCOLOR(COLOR_DEFAULT);
}
else
SWAPBGCOLOR(COLOR_DEFAULT);
if (refresh)
gfx_printandclear(entry.name, 37);
else
gfx_printlength(37, entry.name);
if (entry.property & ISDIR || entry.property & ISMENU)
gfx_printf("\n");
else {
SWAPCOLOR(COLOR_BLUE);
gfx_printf("\a%d\e%s", entry.storage, gfx_file_size_names[size - 4]);
}
}
int menu_make(menu_entry *entries, int amount, char *toptext){
int currentpos = 0, i, res = 0, offset = 0, delay = 300;
u32 scrolltimer, timer;
bool refresh = false;
gfx_clearscreen();
gfx_con_setpos(512, 0);
SWAPCOLOR(COLOR_DEFAULT);
SWAPBGCOLOR(COLOR_WHITE);
gfx_printf("%3d entries\n", amount);
RESETCOLOR;
SWAPCOLOR(COLOR_GREEN);
gfx_printlength(42, toptext);
RESETCOLOR;
while (!(res & BTN_POWER)){
gfx_con_setpos(0, 47);
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--;
}
for (int i = 0 + offset; i < amount && i < 60 + offset; i++)
if (!(entries[i].property & ISHIDE))
_printentry(entries[i], (i == currentpos), refresh);
gfx_printf("\n%k%K %s %s\n\nTime taken for screen draw: %dms ", COLOR_BLUE, COLOR_DEFAULT, (offset + 60 < amount) ? "v" : " ", (offset > 0) ? "^" : " ", get_tmr_ms() - timer);
while (btn_read() & BTN_POWER);
res = 0;
while (!res){
res = btn_read();
if (!res)
delay = 300;
if (delay < 300){
scrolltimer = get_tmr_ms();
while (res){
if (scrolltimer + delay <= get_tmr_ms())
break;
res = btn_read();
}
}
if (delay > 46 && res)
delay -= 45;
}
if (res & BTN_VOL_UP && currentpos >= 1){
currentpos--;
while(entries[currentpos].property & (ISSKIP | ISHIDE) && currentpos >= 1)
currentpos--;
}
else if (res & BTN_VOL_DOWN && currentpos < amount - 1){
currentpos++;
while(entries[currentpos].property & (ISSKIP | ISHIDE) && currentpos < amount - 1)
currentpos++;
}
}
minerva_periodic_training();
//return (mode) ? currentpos : entries[currentpos].property;
return currentpos;
}

View File

@@ -0,0 +1,4 @@
#pragma once
#include "../common/types.h"
int menu_make(menu_entry *entries, int amount, char *toptext);