5static void aa_editdisplay(
struct aa_edit *e)
9 if (e->cursor > strlen(e->data))
10 e->cursor = strlen(e->data);
11 if (e->cursor < e->printpos)
12 e->printpos = e->cursor;
13 if (e->cursor >= e->printpos + e->size)
14 e->printpos = e->cursor - e->size;
17 strncpy(s, e->data + e->printpos, e->size);
19 for (i = strlen(e->data) - e->printpos; i < e->size; i++)
21 aa_puts(e->c, e->x, e->y, e->clearafterpress ? AA_REVERSE : AA_SPECIAL, s);
22 aa_gotoxy(e->c, e->x + e->cursor - e->printpos, e->y);
24struct aa_edit *aa_createedit(
aa_context * c,
int x,
int y,
int size,
char *s,
int maxsize)
31 if (x >= aa_imgwidth(c) - 1)
32 x = aa_imgwidth(c) - 2;
33 if (y >= aa_imgheight(c) - 1)
34 y = aa_imgwidth(c) - 2;
35 if (x + size >= aa_imgwidth(c))
36 size = aa_imgwidth(c) - 1 - x;
37 e = malloc(
sizeof(
struct aa_edit));
42 e->cursor = strlen(s);
43 e->clearafterpress = 1;
52static void aa_insert(
struct aa_edit *e,
char ch)
54 int i, s = strlen(e->data);
55 if (s == e->maxsize - 1)
57 for (i = s; i >= e->cursor; i--) {
58 e->data[i + 1] = e->data[i];
61 e->data[e->cursor] = ch;
64static void aa_delete(
struct aa_edit *e)
66 int i, s = strlen(e->data);
70 for (i = e->cursor; i <= s; i++) {
71 e->data[i] = e->data[i + 1];
74void aa_editkey(
struct aa_edit *e,
int c)
76 if (c < 127 && (isgraph(c) || c ==
' ')) {
77 if (e->clearafterpress)
80 e->clearafterpress = 0;
83 }
else if (c == AA_BACKSPACE) {
84 e->clearafterpress = 0;
87 }
else if (c == AA_LEFT) {
89 e->clearafterpress = 0;
93 }
else if (c == AA_RIGHT) {
95 e->clearafterpress = 0;
96 if (e->cursor > strlen(e->data))
97 e->cursor = strlen(e->data);
107 e = aa_createedit(c, x, y, size, s, maxsize);
109 while ((ch = aa_getkey(c, 1)) != 13 && ch !=
'\n') {