summaryrefslogtreecommitdiff
path: root/source/gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/gui.c')
-rw-r--r--source/gui.c142
1 files changed, 142 insertions, 0 deletions
diff --git a/source/gui.c b/source/gui.c
index ed30706..0400197 100644
--- a/source/gui.c
+++ b/source/gui.c
@@ -28,6 +28,8 @@
#include <sys/dir.h>
#include "framebuffer.h"
+#include "zx81.h"
+#include "keyboard.h"
#include "config.h"
@@ -712,3 +714,143 @@ int GUI_FileSelect(char pwd[], char selected_file[], const char *filter)
return ret;
}
+
+
+int GUI_InputName(char name[], 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'},
+ {0, 0}
+ };
+
+ SoftKeyEvent ev;
+ char text[1024];
+ int done = FALSE;
+ int accept = FALSE;
+ int update = TRUE;
+
+ SK_DisplayKeyboard();
+ ZX81SuspendDisplay();
+
+ name[0] = 0;
+
+ while(!done)
+ {
+ if (update)
+ {
+ sprintf(text, "enter the snapshot name:\n"
+ "\"%s%%l%%\""
+ "\n\n\npress enter to accept.\n"
+ "press period to backspace.\n"
+ "press space/break to cancel\n",
+ name);
+
+ ZX81DisplayString(text);
+
+ update = FALSE;
+ }
+
+ while(SK_GetBareEvent(&ev))
+ {
+ if (!ev.pressed)
+ {
+ size_t l;
+ int f;
+ int ascii;
+
+ l = strlen(name);
+
+ switch(ev.key)
+ {
+ case SK_PERIOD:
+ if (l)
+ {
+ name[--l] = 0;
+ update = TRUE;
+ }
+ 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)
+ {
+ name[l++] = ascii;
+ name[l] = 0;
+ update = TRUE;
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ swiWaitForVBlank();
+ }
+
+ return accept;
+}
+