diff options
Diffstat (limited to 'source/gui.c')
-rw-r--r-- | source/gui.c | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/source/gui.c b/source/gui.c index eee82f4..bbea23c 100644 --- a/source/gui.c +++ b/source/gui.c @@ -917,3 +917,156 @@ int GUI_InputName(const char *prompt, const char *ext, char name[], int maxlen) return accept; } + +int GUI_Input(const char *prompt, char text[], int maxlen) +{ + struct + { + SoftKey key; + int ascii; + int shift; + } keymap[] = + { + {SK_1, '1', '!'}, + {SK_2, '2', '@'}, + {SK_3, '3', '#'}, + {SK_4, '4', '$'}, + {SK_5, '5', '%'}, + {SK_6, '6', '&'}, + {SK_7, '7', '\''}, + {SK_8, '8', '('}, + {SK_9, '9', ')'}, + {SK_0, '0', '_'}, + {SK_A, 'A', '~'}, + {SK_B, 'B', '*'}, + {SK_C, 'C', '?'}, + {SK_D, 'D', '\\'}, + {SK_E, 'E', 0}, + {SK_F, 'F', '{'}, + {SK_G, 'G', '}'}, + {SK_H, 'H', '^'}, + {SK_I, 'I', 0}, + {SK_J, 'J', '-'}, + {SK_K, 'K', '+'}, + {SK_L, 'L', '='}, + {SK_M, 'M', '.'}, + {SK_N, 'N', ','}, + {SK_O, 'O', ';'}, + {SK_P, 'P', '"'}, + {SK_Q, 'Q', 0}, + {SK_R, 'R', '<'}, + {SK_S, 'S', '|'}, + {SK_T, 'T', '>'}, + {SK_U, 'U', ']'}, + {SK_V, 'V', '/'}, + {SK_W, 'W', 0}, + {SK_X, 'X', 0}, + {SK_Y, 'Y', '['}, + {SK_Z, 'Z', ':'}, + {0, 0, 0} + }; + + SoftKeyEvent ev; + int done = FALSE; + int accept = FALSE; + int shifted; + Framebuffer upper; + + text[0] = 0; + shifted = SK_KeyPressed(SK_SHIFT); + + while(!done) + { + FB_StartFrame(&upper, NULL); + + FB_Clear(&upper, COL_WHITE); + SK_DisplayKeyboard(); + + FB_printf(&upper, 0, 16, COL_BLACK, COL_TRANSPARENT, "%s", prompt); + FB_printf(&upper, 0, 8, COL_BLACK, COL_TRANSPARENT, "\"%s\001L\001\"", + text); + + FB_Print(&upper, "PRESS ENTER TO ACCEPT", 0, 32, + COL_BLACK, COL_TRANSPARENT); + FB_Print(&upper, "PRESS SPACE/BREAK TO CANCEL", 0, 40, + COL_BLACK, COL_TRANSPARENT); + + FB_EndFrame(); + + while(SK_GetBareEvent(&ev)) + { + if (ev.pressed) + { + switch(ev.key) + { + case SK_SHIFT: + shifted = TRUE; + break; + default: + break; + } + } + + if (!ev.pressed) + { + size_t l; + int f; + int ascii; + + l = strlen(text); + + switch(ev.key) + { + case SK_SHIFT: + shifted = FALSE; + break; + + case SK_SPACE: + done = TRUE; + accept = FALSE; + break; + + case SK_NEWLINE: + done = TRUE; + accept = TRUE; + break; + + default: + if (l < maxlen) + { + f = 0; + ascii = 0; + + while(!ascii && keymap[f].ascii) + { + if (ev.key == keymap[f].key) + { + if (shifted) + { + ascii = keymap[f].shift; + } + else + { + ascii = keymap[f].ascii; + } + } + + f++; + } + + if (ascii) + { + text[l++] = ascii; + text[l] = 0; + } + } + break; + } + } + } + } + + return accept; +} + + |