2020-03-17 23:41:09 +00:00
|
|
|
#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"
|
2020-03-18 11:18:39 +00:00
|
|
|
#include "../common/common.h"
|
2020-05-02 00:41:43 +01:00
|
|
|
#include "../../hid/hid.h"
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-03-21 19:31:22 +00:00
|
|
|
int printerrors = true;
|
2020-03-17 23:41:09 +00:00
|
|
|
|
|
|
|
void gfx_clearscreen(){
|
|
|
|
int battery = 0;
|
|
|
|
max17050_get_property(MAX17050_RepSOC, &battery);
|
|
|
|
|
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
SWAPCOLOR(COLOR_DEFAULT);
|
|
|
|
SWAPBGCOLOR(COLOR_WHITE);
|
|
|
|
|
2020-04-30 22:40:26 +01:00
|
|
|
gfx_boxGrey(0, 703, 1279, 719, 0xFF);
|
|
|
|
gfx_boxGrey(0, 0, 1279, 15, 0xFF);
|
2020-03-17 23:41:09 +00:00
|
|
|
gfx_con_setpos(0, 0);
|
2020-05-02 00:41:43 +01:00
|
|
|
gfx_printf("Tegraexplorer v1.5.2 | Battery: %3d%%\n", battery >> 8);
|
2020-03-17 23:41:09 +00:00
|
|
|
|
|
|
|
RESETCOLOR;
|
|
|
|
}
|
|
|
|
|
2020-05-02 00:41:43 +01:00
|
|
|
u32 gfx_message(u32 color, const char* message, ...){
|
2020-03-17 23:41:09 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, message);
|
|
|
|
|
|
|
|
gfx_clearscreen();
|
|
|
|
SWAPCOLOR(color);
|
|
|
|
|
|
|
|
gfx_vprintf(message, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
2020-05-02 00:41:43 +01:00
|
|
|
return hidWait()->buttons;
|
2020-03-17 23:41:09 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 00:41:43 +01:00
|
|
|
u32 gfx_errDisplay(char *src_func, int err, int loc){
|
2020-03-21 19:31:22 +00:00
|
|
|
if (!printerrors)
|
|
|
|
return 0;
|
|
|
|
|
2020-03-17 23:41:09 +00:00
|
|
|
gfx_clearscreen();
|
|
|
|
SWAPCOLOR(COLOR_ORANGE);
|
|
|
|
gfx_printf("\nAn error occured:\n\n");
|
2020-03-18 11:18:39 +00:00
|
|
|
gfx_printf("Function: %s\nErrcode: %d\n", src_func, err);
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-03-18 11:18:39 +00:00
|
|
|
if (err < 15)
|
|
|
|
gfx_printf("Desc: %s\n", utils_err_codes[err]);
|
2020-04-28 19:54:17 +01:00
|
|
|
else if (err >= ERR_SAME_LOC && err <= ERR_NO_DESTINATION)
|
2020-03-18 22:58:32 +00:00
|
|
|
gfx_printf("Desc: %s\n", utils_err_codes_te[err - 50]);
|
2020-03-18 11:18:39 +00:00
|
|
|
|
|
|
|
if (loc)
|
|
|
|
gfx_printf("Loc: %d\n", loc);
|
2020-03-17 23:41:09 +00:00
|
|
|
|
|
|
|
gfx_printf("\nPress any button to return");
|
|
|
|
|
|
|
|
RESETCOLOR;
|
2020-04-01 22:44:28 +01:00
|
|
|
|
2020-05-02 00:41:43 +01:00
|
|
|
return hidWait()->buttons;
|
2020-03-17 23:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int gfx_makewaitmenu(char *hiddenmessage, int timer){
|
|
|
|
u32 start = get_tmr_s();
|
2020-05-02 00:41:43 +01:00
|
|
|
Inputs *input = NULL;
|
2020-03-17 23:41:09 +00:00
|
|
|
|
|
|
|
while(1){
|
2020-05-02 00:41:43 +01:00
|
|
|
input = hidRead();
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-05-02 00:41:43 +01:00
|
|
|
if (input->buttons & (KEY_VOLM | KEY_VOLP | KEY_B))
|
2020-03-17 23:41:09 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (start + timer > get_tmr_s())
|
|
|
|
gfx_printf("\r<Wait %d seconds> ", timer + start - get_tmr_s());
|
|
|
|
|
2020-05-02 00:41:43 +01:00
|
|
|
else if (input->a)
|
2020-03-17 23:41:09 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-05-01 23:50:08 +01:00
|
|
|
void gfx_printandclear(char *in, int length, int endX){
|
2020-03-17 23:41:09 +00:00
|
|
|
u32 x, y;
|
|
|
|
|
|
|
|
gfx_printlength(length, in);
|
|
|
|
gfx_con_getpos(&x, &y);
|
2020-03-18 22:58:32 +00:00
|
|
|
RESETCOLOR;
|
|
|
|
|
2020-04-23 13:40:55 +01:00
|
|
|
|
|
|
|
/*
|
2020-03-18 22:58:32 +00:00
|
|
|
for (int i = (703 - x) / 16; i > 0; i--)
|
|
|
|
gfx_printf(" ");
|
2020-04-23 13:40:55 +01:00
|
|
|
*/
|
|
|
|
|
2020-05-01 23:50:08 +01:00
|
|
|
gfx_boxGrey(x, y, endX, y + 15, 0x1B);
|
2020-03-18 22:58:32 +00:00
|
|
|
|
|
|
|
gfx_con_setpos(x, y);
|
2020-03-17 23:41:09 +00:00
|
|
|
|
2020-03-18 22:58:32 +00:00
|
|
|
//gfx_box(x, y, 719, y + 16, COLOR_DEFAULT);
|
|
|
|
/*
|
|
|
|
u8 color = 0x1B;
|
|
|
|
gfx_set_rect_grey(&color, 719 - x, 16, x, y);
|
|
|
|
*/
|
2020-03-17 23:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gfx_printfilesize(int size, char *type){
|
|
|
|
SWAPCOLOR(COLOR_VIOLET);
|
|
|
|
gfx_printf("\a%4d\e%s", size, type);
|
|
|
|
RESETCOLOR;
|
2020-04-28 19:54:17 +01:00
|
|
|
}
|
2020-05-02 12:05:06 +01:00
|
|
|
|
|
|
|
static u32 sideY = 0;
|
|
|
|
void _gfx_sideSetYAuto(){
|
|
|
|
u32 getX, getY;
|
|
|
|
gfx_con_getpos(&getX, &getY);
|
|
|
|
sideY = getY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfx_sideSetY(u32 setY){
|
|
|
|
sideY = setY;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 gfx_sideGetY(){
|
|
|
|
return sideY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfx_sideprintf(char* message, ...){
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, message);
|
|
|
|
|
|
|
|
gfx_con_setpos(800, sideY);
|
|
|
|
gfx_vprintf(message, ap);
|
|
|
|
_gfx_sideSetYAuto();
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfx_sideprintandclear(char* message, int length){
|
|
|
|
gfx_con_setpos(800, sideY);
|
|
|
|
gfx_printandclear(message, length, 1279);
|
|
|
|
gfx_putc('\n');
|
|
|
|
_gfx_sideSetYAuto();
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfx_drawScrollBar(int minView, int maxView, int count){
|
|
|
|
int curScrollCount = 1 + maxView - minView;
|
|
|
|
if (curScrollCount >= count)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int barSize = (703 * (curScrollCount * 100 / count)) / 100;
|
|
|
|
int offsetSize = (703 * (minView * 100/ count)) / 100;
|
|
|
|
|
|
|
|
gfx_boxGrey(740, 16, 755, 702, 0x1B);
|
|
|
|
if ((16 + barSize + offsetSize) > 702)
|
|
|
|
gfx_boxGrey(740, 16 + offsetSize, 755, 702, 0x66);
|
|
|
|
else
|
|
|
|
gfx_boxGrey(740, 16 + offsetSize, 755, 16 + barSize + offsetSize, 0x66);
|
2020-05-02 13:06:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int gfx_defaultWaitMenu(char *message, int time){
|
|
|
|
gfx_clearscreen();
|
|
|
|
SWAPCOLOR(COLOR_ORANGE);
|
|
|
|
gfx_printf("\n%s\n\nPress B to return\n", message);
|
|
|
|
SWAPCOLOR(COLOR_RED);
|
|
|
|
return gfx_makewaitmenu("Press A to continue", time);
|
2020-05-02 12:05:06 +01:00
|
|
|
}
|