Rev 6601 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6601 | Rev 6612 | ||
---|---|---|---|
1 | #ifndef KOLIBRI_MSGBOX_H |
1 | #ifndef KOLIBRI_MSGBOX_H |
2 | #define KOLIBRI_MSGBOX_H |
2 | #define KOLIBRI_MSGBOX_H |
3 | #include |
3 | #include |
4 | 4 | ||
5 | typedef struct __attribute__ ((__packed__)) { |
5 | typedef struct __attribute__ ((__packed__)) { |
6 | uint8_t retval; // 0 - win closed, 1 to n - button num, also default button on start |
6 | uint8_t retval; // 0 - win closed, 1 to n - button num, also default button on start |
7 | uint8_t reserv; |
7 | uint8_t reserv; |
8 | char texts[2048]; // mus be enough ;-) |
8 | char texts[2048]; // must be enough ;-) |
9 | char msgbox_stack[1024]; |
9 | char msgbox_stack[1024]; |
10 | uint32_t top_stack; |
10 | uint32_t top_stack; |
11 | } msgbox; |
11 | } msgbox; |
12 | 12 | ||
13 | 13 | ||
14 | typedef void (*msgbox_callback)(void); |
14 | typedef void (*msgbox_callback)(void); |
15 | 15 | ||
16 | static int msgbox_inited; |
16 | static int msgbox_inited; |
17 | extern void kolibri_msgbox_init(); |
17 | extern void kolibri_msgbox_init(); |
18 | extern void (*msgbox_create)(msgbox *, void *thread) __attribute__((__stdcall__)); // clears callbacks, ! if fix lib, we can return eax as of Fn51 |
18 | extern void (*msgbox_create)(msgbox *, void *thread) __attribute__((__stdcall__)); // clears callbacks, ! if fix lib, we can return eax as of Fn51 |
19 | extern void (*msgbox_setfunctions)(msgbox_callback*) __attribute__((__stdcall__)); // must be called immediately after create, zero-ended array |
19 | extern void (*msgbox_setfunctions)(msgbox_callback*) __attribute__((__stdcall__)); // must be called immediately after create, zero-ended array |
20 | extern void (*msgbox_reinit)(msgbox *) __attribute__((__stdcall__)); // recalc sizes when structure changes, called auto when MsgBoxCreate |
20 | extern void (*msgbox_reinit)(msgbox *) __attribute__((__stdcall__)); // recalc sizes when structure changes, called auto when MsgBoxCreate |
21 | 21 | ||
22 | static inline msgbox* kolibri_new_msgbox(char* title, char* text, int def_but, ...) |
22 | static inline msgbox* kolibri_new_msgbox(char* title, char* text, int def_but, ...) |
23 | /// text can be multilined by code 13 = "\r" |
23 | /// text can be multilined by code 13 = "\r" |
24 | /// def_but - highlighted and used on Enter (if zero - default is [X]), user may use Tabs or Arrows |
24 | /// def_but - highlighted and used on Enter (if zero - default is [X]), user may use Tabs or Arrows |
25 | /// last params are buttons text, max 8. last must set as NULL |
25 | /// last params are buttons text, max 8. last must set as NULL |
26 | { |
26 | { |
27 | va_list vl; |
27 | va_list vl; |
28 | va_start(vl, def_but); |
28 | va_start(vl, def_but); |
29 | 29 | ||
30 | msgbox* box = calloc(sizeof(msgbox), 1); |
30 | msgbox* box = calloc(sizeof(msgbox), 1); |
31 | box->retval = (uint8_t)def_but; |
31 | box->retval = (uint8_t)def_but; |
32 | char *pc = box->texts; |
32 | char *pc = box->texts; |
33 | strcpy(pc, title); |
33 | strcpy(pc, title); |
34 | pc += strlen(title) + 1; |
34 | pc += strlen(title) + 1; |
35 | strcpy(pc, text); |
35 | strcpy(pc, text); |
36 | pc += strlen(text) + 1; |
36 | pc += strlen(text) + 1; |
37 | 37 | ||
38 | char *but_text = va_arg(vl, char*); |
38 | char *but_text = va_arg(vl, char*); |
39 | while (but_text) |
39 | while (but_text) |
40 | { |
40 | { |
41 | strcpy(pc, but_text); |
41 | strcpy(pc, but_text); |
42 | pc += strlen(but_text) + 1; |
42 | pc += strlen(but_text) + 1; |
43 | // assert(pc - box->texts < sizeof box->texts); |
43 | // assert(pc - box->texts < sizeof box->texts); |
44 | but_text = va_arg(vl, char*); |
44 | but_text = va_arg(vl, char*); |
45 | } |
45 | } |
46 | 46 | ||
47 | va_end(vl); |
47 | va_end(vl); |
48 | 48 | ||
49 | return box; |
49 | return box; |
50 | } |
50 | } |
51 | 51 | ||
52 | void kolibri_start_msgbox(msgbox* box, msgbox_callback cb[]) |
52 | static inline void kolibri_start_msgbox(msgbox* box, msgbox_callback cb[]) |
53 | { |
53 | { |
54 | if (!msgbox_inited) |
54 | if (!msgbox_inited) |
55 | { |
55 | { |
56 | kolibri_msgbox_init(); |
56 | kolibri_msgbox_init(); |
57 | msgbox_inited++; |
57 | msgbox_inited++; |
58 | } |
58 | } |
59 | (*msgbox_create)(box, &box->top_stack); |
59 | (*msgbox_create)(box, &box->top_stack); |
60 | if (cb) (*msgbox_setfunctions)(cb); |
60 | if (cb) (*msgbox_setfunctions)(cb); |
61 | } |
61 | } |
62 | 62 | ||
63 | #endif> |
63 | #endif> |