summaryrefslogtreecommitdiff
path: root/source/gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/gui.c')
-rw-r--r--source/gui.c151
1 files changed, 116 insertions, 35 deletions
diff --git a/source/gui.c b/source/gui.c
index c3b402d..5e31ac5 100644
--- a/source/gui.c
+++ b/source/gui.c
@@ -802,41 +802,13 @@ int GUI_InputName(const char *prompt, const char *ext, char name[], int maxlen)
int ascii;
} 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'},
- {SK_F, 'F'},
- {SK_G, 'G'},
- {SK_H, 'H'},
- {SK_I, 'I'},
- {SK_J, 'J'},
- {SK_K, 'K'},
- {SK_L, 'L'},
- {SK_M, 'M'},
- {SK_N, 'N'},
- {SK_O, 'O'},
- {SK_P, 'P'},
- {SK_Q, 'Q'},
- {SK_R, 'R'},
- {SK_S, 'S'},
- {SK_T, 'T'},
- {SK_U, 'U'},
- {SK_V, 'V'},
- {SK_W, 'W'},
- {SK_X, 'X'},
- {SK_Y, 'Y'},
+ {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'},
+ {SK_F, 'F'}, {SK_G, 'G'}, {SK_H, 'H'}, {SK_I, 'I'}, {SK_J, 'J'},
+ {SK_K, 'K'}, {SK_L, 'L'}, {SK_M, 'M'}, {SK_N, 'N'}, {SK_O, 'O'},
+ {SK_P, 'P'}, {SK_Q, 'Q'}, {SK_R, 'R'}, {SK_S, 'S'}, {SK_T, 'T'},
+ {SK_U, 'U'}, {SK_V, 'V'}, {SK_W, 'W'}, {SK_X, 'X'}, {SK_Y, 'Y'},
{SK_Z, 'Z'},
{0, 0}
};
@@ -928,3 +900,112 @@ 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;
+ } 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'},
+ {SK_F, 'F'}, {SK_G, 'G'}, {SK_H, 'H'}, {SK_I, 'I'}, {SK_J, 'J'},
+ {SK_K, 'K'}, {SK_L, 'L'}, {SK_M, 'M'}, {SK_N, 'N'}, {SK_O, 'O'},
+ {SK_P, 'P'}, {SK_Q, 'Q'}, {SK_R, 'R'}, {SK_S, 'S'}, {SK_T, 'T'},
+ {SK_U, 'U'}, {SK_V, 'V'}, {SK_W, 'W'}, {SK_X, 'X'}, {SK_Y, 'Y'},
+ {SK_Z, 'Z'}, {SK_SHIFT, '.'},
+ {0, 0}
+ };
+
+ SoftKeyEvent ev;
+ int done = FALSE;
+ int accept = FALSE;
+ Framebuffer upper;
+
+ text[0] = 0;
+
+ 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 SYMBOL SHIFT TO BACKSPACE", 0, 40,
+ COL_BLACK, COL_TRANSPARENT);
+ FB_Print(&upper, "PRESS CAPS SHIFT FOR PERIOD", 0, 48,
+ COL_BLACK, COL_TRANSPARENT);
+ FB_Print(&upper, "PRESS SPACE/BREAK TO CANCEL", 0, 56,
+ COL_BLACK, COL_TRANSPARENT);
+
+ FB_EndFrame();
+
+ while(SK_GetBareEvent(&ev))
+ {
+ if (!ev.pressed)
+ {
+ size_t l;
+ int f;
+ int ascii;
+
+ l = strlen(text);
+
+ switch(ev.key)
+ {
+ case SK_SYMBOL:
+ if (l)
+ {
+ text[--l] = 0;
+ }
+ 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)
+ {
+ ascii = keymap[f].ascii;
+ }
+
+ f++;
+ }
+
+ if (ascii)
+ {
+ text[l++] = ascii;
+ text[l] = 0;
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ return accept;
+}
+