1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-08 13:11:54 +00:00

Fix some bugs in the keyboard

This commit is contained in:
suchmememanyskill 2020-12-29 19:20:33 +01:00
parent 48ddc6ea60
commit 45d86a31b1

View file

@ -42,121 +42,6 @@ void WaitFor(u32 ms){
while (a + ms > get_tmr_ms());
}
/*
MenuEntry_t KeyboardHeader[] = {
{.optionUnion = COLORTORGB(COLOR_GREEN), .name = "Cancel"},
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Save"},
{.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Remove last char"},
{.optionUnion = COLORTORGB(COLOR_VIOLET), .name = "Add a char"},
{.optionUnion = COLORTORGB(COLOR_WHITE), .name = "Edit"}
};
char *ShowKeyboard(const char *in){
u32 len = strlen(in);
Vector_t menuEntries = newVec(sizeof(MenuEntry_t), len + 1);
MenuEntry_t a = {.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "<- Back "};
vecAddElem(&menuEntries, a);
for (int i = 0; i < len; i++){
MenuEntry_t b = {.optionUnion = COLORTORGB(COLOR_WHITE)};
b.name = calloc(2,1);
b.name[0] = in[i];
vecAddElem(&menuEntries, b);
}
MenuEntry_t *characters = calloc(sizeof(MenuEntry_t), 126 - 32 + 2);
characters[0].name = CpyStr("Cancel");
characters[0].optionUnion = COLORTORGB(COLOR_ORANGE);
characters[1].name = CpyStr("Space");
characters[1].optionUnion = COLORTORGB(COLOR_WHITE);
for (int i = 34; i <= 127; i++){
characters[i - 32].name = calloc(2,1);
characters[i - 32].name[0] = i - 1;
characters[i - 32].optionUnion = COLORTORGB(COLOR_WHITE);
}
Vector_t temp = vecFromArray(characters, 126 - 32 + 2, sizeof(MenuEntry_t));
u32 x, y;
gfx_con_getpos(&x, &y);
int res = 0;
while (1){
gfx_con_setpos(x,y);
RESETCOLOR;
gfx_boxGrey(x, y, YLEFT, y + 16, 0x1B);
vecDefArray(MenuEntry_t*, entries , menuEntries);
for (int i = 1; i < menuEntries.count; i++){
gfx_putc(entries[i].name[0]);
}
gfx_putc('\n');
res = MakeHorizontalMenu(KeyboardHeader, ARR_LEN(KeyboardHeader), 2, COLOR_DEFAULT, res);
if (res <= 1){
break;
}
else if (res == 2){
if (menuEntries.count > 1)
menuEntries.count--;
}
else if (res == 3){
if (menuEntries.count <= 64){
MenuEntry_t b = {.optionUnion = COLORTORGB(COLOR_WHITE), .name = CpyStr("a")};
vecAddElem(&menuEntries, b);
}
}
else if (res == 4){
int newRes = 0;
while (1){
gfx_con_setpos(x,y);
RESETCOLOR;
gfx_boxGrey(x, y, YLEFT, y + 32, 0x1B);
newRes = MakeHorizontalMenu(entries, menuEntries.count, 0, COLOR_DEFAULT, newRes);
if (newRes == 0)
break;
else {
gfx_printf("\n\nCharacter select: ");
int selectedChar = newMenu(&temp, entries[newRes].name[0] - 31, 8, 10, ENABLEB, temp.count);
if (selectedChar)
entries[newRes].name[0] = selectedChar + 31;
gfx_boxGrey(x, y, YLEFT, y + 16 * 14, 0x1B);
}
}
for (int i = 1; i < menuEntries.count; i++){
if (strchr("\\/:*\"<>|", entries[i].name[0]) != NULL){
entries[i].name[0] = '_';
}
}
}
}
char *reconstruct = calloc(menuEntries.count, 1);
vecDefArray(MenuEntry_t*, entries, menuEntries);
for (int i = 1; i < menuEntries.count; i++){
reconstruct[i - 1] = entries[i].name[0];
free(entries[i].name);
}
vecFree(menuEntries);
for (int i = 0; i < 126 - 32 + 2; i++){
free(characters[i].name);
}
free(characters);
if (!res){
free(reconstruct);
return NULL;
}
return reconstruct;
}
*/
char *lines[] = {
"1234567890*", // 0 - 10
"qwertyuiop~", // 11 - 21
@ -199,7 +84,15 @@ char *ShowKeyboard(const char *toEdit, u8 alwaysRet){
Input_t *input = hidWait();
if (input->buttons & (JoyA | JoyLB | JoyRB)){
if (pos == 10){
if (pos == 42 || input->l){
if (posOnWord > 0)
posOnWord--;
}
else if (pos == 43 || input->r){
if (strlen(ret) - 1 > posOnWord)
posOnWord++;
}
else if (pos == 10){
break;
}
else if (pos == 21){
@ -216,6 +109,9 @@ char *ShowKeyboard(const char *toEdit, u8 alwaysRet){
}
else if (pos == 32){
u32 wordLen = strlen(ret);
if (wordLen >= 79)
continue;
char *copy = calloc(wordLen + 2, 1);
memcpy(copy, ret, wordLen);
copy[wordLen] = 'a';
@ -225,19 +121,14 @@ char *ShowKeyboard(const char *toEdit, u8 alwaysRet){
else if (pos == 33){
shift = !shift;
}
else if (pos == 42 || input->l){
if (posOnWord > 0)
posOnWord--;
}
else if (pos == 43 || input->r){
if (strlen(ret) - 1 > posOnWord)
posOnWord++;
}
else {
char toPut = lines[pos / 11][pos % 11];
if (shift)
toPut &= ~BIT(5);
ret[posOnWord] = toPut;
if (strlen(ret) - 1 > posOnWord)
posOnWord++;
}
}
int val = (input->up || input->down) ? 11 : 1;