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