FreeBASIC  0.91.0
gfx_readstr.c
Go to the documentation of this file.
1 /* gfx hook for INPUT support */
2 
3 #include "fb_gfx.h"
4 
5 
6 /*:::::*/
7 static void move_back(void)
8 {
10  if (__fb_gfx->cursor_x < 0) {
12  __fb_gfx->cursor_y--;
13  }
14 }
15 
16 char *fb_GfxReadStr(char *buffer, ssize_t maxlen)
17 {
18  int key;
19  ssize_t len = 0;
20  char cursor_normal[2] = { 219, '\0' };
21  char cursor_backspace[3] = { 219, ' ', '\0' };
22  char space[2] = { ' ', '\0' };
23  char character[2] = { 0, '\0' };
24  char *cursor = cursor_normal;
25 
26  if (!__fb_gfx)
27  return NULL;
28 
29  do {
30  fb_GfxPrintBuffer(cursor, 0);
31 
32  if (cursor == cursor_backspace) {
33  move_back();
34  cursor = cursor_normal;
35  }
36  move_back();
37 
38  key = fb_Getkey();
39  if (key < 0x100) {
40  if (key == 8) {
41  if (len > 0) {
42  cursor = cursor_backspace;
43  move_back();
44  if (__fb_gfx->cursor_y < 0) {
46  cursor = cursor_normal;
47  }
48  len--;
49  }
50  }
51  else if ((key != 7) && (len < maxlen - 1)) {
52  if (key == 13) {
53  fb_GfxPrintBuffer(space, 0);
54  move_back();
55  }
56  buffer[len++] = key;
57  character[0] = key;
58  fb_GfxPrintBuffer(character, 0);
59  }
60  }
61  } while (key != 13);
62 
63  buffer[len] = '\0';
64 
65  return buffer;
66 }