1 /*         ______   ___    ___
2  *        /\  _  \ /\_ \  /\_ \
3  *        \ \ \L\ \\//\ \ \//\ \      __     __   _ __   ___
4  *         \ \  __ \ \ \ \  \ \ \   /'__`\ /'_ `\/\`'__\/ __`\
5  *          \ \ \/\ \ \_\ \_ \_\ \_/\  __//\ \L\ \ \ \//\ \L\ \
6  *           \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7  *            \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8  *                                           /\____/
9  *                                           \_/__/
10  *
11  *      GUI routines.
12  *
13  *      By Shawn Hargreaves.
14  *
15  *      See readme.txt for copyright information.
16  */
17 
18 
19 #ifndef ALLEGRO_GUI_H
20 #define ALLEGRO_GUI_H
21 
22 #include "base.h"
23 
24 #ifdef __cplusplus
25    extern "C" {
26 #endif
27 
28 struct BITMAP;
29 struct DIALOG;
30 
31 typedef AL_METHOD(int, DIALOG_PROC, (int msg, struct DIALOG *d, int c));
32 
33 typedef struct DIALOG
34 {
35    DIALOG_PROC proc;
36    int x, y, w, h;               /* position and size of the object */
37    int fg, bg;                   /* foreground and background colors */
38    int key;                      /* keyboard shortcut (ASCII code) */
39    int flags;                    /* flags about the object state */
40    int d1, d2;                   /* any data the object might require */
41    void *dp, *dp2, *dp3;         /* pointers to more object data */
42 } DIALOG;
43 
44 
45 /* a popup menu */
46 typedef struct MENU
47 {
48    char *text;                   /* menu item text */
49    AL_METHOD(int, proc, (void)); /* callback function */
50    struct MENU *child;           /* to allow nested menus */
51    int flags;                    /* flags about the menu state */
52    void *dp;                     /* any data the menu might require */
53 } MENU;
54 
55 
56 /* stored information about the state of an active GUI dialog */
57 typedef struct DIALOG_PLAYER
58 {
59    int obj;
60    int res;
61    int mouse_obj;
62    int focus_obj;
63    int joy_on;
64    int click_wait;
65    int mouse_ox, mouse_oy;
66    int mouse_oz;
67    int mouse_b;
68    DIALOG *dialog;
69 } DIALOG_PLAYER;
70 
71 
72 /* stored information about the state of an active GUI menu */
73 typedef struct MENU_PLAYER
74 {
75    MENU *menu;                      /* the menu itself */
76    int bar;                         /* set if it is a top level menu bar */
77    int size;                        /* number of items in the menu */
78    int sel;                         /* selected item */
79    int x, y, w, h;                  /* screen position of the menu */
80    int (*proc)(void);               /* callback function */
81    BITMAP *saved;                   /* saved what was underneath it */
82 
83    int mouse_button_was_pressed;    /* set if mouse button pressed on last iteration */
84    int back_from_child;             /* set if a child was activated on last iteration */
85    int timestamp;                   /* timestamp for gui_timer events */
86    int mouse_sel;                   /* item the mouse is currently over */
87    int redraw;                      /* set if redrawing is required */
88    int auto_open;                   /* set if menu auto-opening is activated */
89    int ret;                         /* return value */
90 
91    DIALOG *dialog;                  /* d_menu_proc() parent dialog (if any) */
92 
93    struct MENU_PLAYER *parent;      /* the parent menu, or NULL for root */
94    struct MENU_PLAYER *child;       /* the child menu, or NULL for none */
95 } MENU_PLAYER;
96 
97 
98 /* bits for the flags field */
99 #define D_EXIT          1        /* object makes the dialog exit */
100 #define D_SELECTED      2        /* object is selected */
101 #define D_GOTFOCUS      4        /* object has the input focus */
102 #define D_GOTMOUSE      8        /* mouse is on top of object */
103 #define D_HIDDEN        16       /* object is not visible */
104 #define D_DISABLED      32       /* object is visible but inactive */
105 #define D_DIRTY         64       /* object needs to be redrawn */
106 #define D_INTERNAL      128      /* reserved for internal use */
107 #define D_USER          256      /* from here on is free for your own use */
108 
109 
110 /* return values for the dialog procedures */
111 #define D_O_K           0        /* normal exit status */
112 #define D_CLOSE         1        /* request to close the dialog */
113 #define D_REDRAW        2        /* request to redraw the dialog */
114 #define D_REDRAWME      4        /* request to redraw this object */
115 #define D_WANTFOCUS     8        /* this object wants the input focus */
116 #define D_USED_CHAR     16       /* object has used the keypress */
117 #define D_REDRAW_ALL    32       /* request to redraw all active dialogs */
118 #define D_DONTWANTMOUSE 64       /* this object does not want mouse focus */
119 
120 
121 /* messages for the dialog procedures */
122 #define MSG_START       1        /* start the dialog, initialise */
123 #define MSG_END         2        /* dialog is finished - cleanup */
124 #define MSG_DRAW        3        /* draw the object */
125 #define MSG_CLICK       4        /* mouse click on the object */
126 #define MSG_DCLICK      5        /* double click on the object */
127 #define MSG_KEY         6        /* keyboard shortcut */
128 #define MSG_CHAR        7        /* other keyboard input */
129 #define MSG_UCHAR       8        /* unicode keyboard input */
130 #define MSG_XCHAR       9        /* broadcast character to all objects */
131 #define MSG_WANTFOCUS   10       /* does object want the input focus? */
132 #define MSG_GOTFOCUS    11       /* got the input focus */
133 #define MSG_LOSTFOCUS   12       /* lost the input focus */
134 #define MSG_GOTMOUSE    13       /* mouse on top of object */
135 #define MSG_LOSTMOUSE   14       /* mouse moved away from object */
136 #define MSG_IDLE        15       /* update any background stuff */
137 #define MSG_RADIO       16       /* clear radio buttons */
138 #define MSG_WHEEL       17       /* mouse wheel moved */
139 #define MSG_LPRESS      18       /* mouse left button pressed */
140 #define MSG_LRELEASE    19       /* mouse left button released */
141 #define MSG_MPRESS      20       /* mouse middle button pressed */
142 #define MSG_MRELEASE    21       /* mouse middle button released */
143 #define MSG_RPRESS      22       /* mouse right button pressed */
144 #define MSG_RRELEASE    23       /* mouse right button released */
145 #define MSG_WANTMOUSE   24       /* does object want the mouse? */
146 #define MSG_USER        25       /* from here on are free... */
147 
148 
149 /* some dialog procedures */
150 AL_FUNC(int, d_yield_proc, (int msg, DIALOG *d, int c));
151 AL_FUNC(int, d_clear_proc, (int msg, DIALOG *d, int c));
152 AL_FUNC(int, d_box_proc, (int msg, DIALOG *d, int c));
153 AL_FUNC(int, d_shadow_box_proc, (int msg, DIALOG *d, int c));
154 AL_FUNC(int, d_bitmap_proc, (int msg, DIALOG *d, int c));
155 AL_FUNC(int, d_text_proc, (int msg, DIALOG *d, int c));
156 AL_FUNC(int, d_ctext_proc, (int msg, DIALOG *d, int c));
157 AL_FUNC(int, d_rtext_proc, (int msg, DIALOG *d, int c));
158 AL_FUNC(int, d_button_proc, (int msg, DIALOG *d, int c));
159 AL_FUNC(int, d_check_proc, (int msg, DIALOG *d, int c));
160 AL_FUNC(int, d_radio_proc, (int msg, DIALOG *d, int c));
161 AL_FUNC(int, d_icon_proc, (int msg, DIALOG *d, int c));
162 AL_FUNC(int, d_keyboard_proc, (int msg, DIALOG *d, int c));
163 AL_FUNC(int, d_edit_proc, (int msg, DIALOG *d, int c));
164 AL_FUNC(int, d_list_proc, (int msg, DIALOG *d, int c));
165 AL_FUNC(int, d_text_list_proc, (int msg, DIALOG *d, int c));
166 AL_FUNC(int, d_textbox_proc, (int msg, DIALOG *d, int c));
167 AL_FUNC(int, d_slider_proc, (int msg, DIALOG *d, int c));
168 AL_FUNC(int, d_menu_proc, (int msg, DIALOG *d, int c));
169 
170 AL_VAR(DIALOG_PROC, gui_shadow_box_proc);
171 AL_VAR(DIALOG_PROC, gui_ctext_proc);
172 AL_VAR(DIALOG_PROC, gui_button_proc);
173 AL_VAR(DIALOG_PROC, gui_edit_proc);
174 AL_VAR(DIALOG_PROC, gui_list_proc);
175 AL_VAR(DIALOG_PROC, gui_text_list_proc);
176 
177 AL_FUNCPTR(void, gui_menu_draw_menu, (int x, int y, int w, int h));
178 AL_FUNCPTR(void, gui_menu_draw_menu_item, (MENU *m, int x, int y, int w, int h, int bar, int sel));
179 
180 AL_VAR(DIALOG *, active_dialog);
181 AL_VAR(MENU *, active_menu);
182 
183 AL_VAR(int, gui_mouse_focus);
184 
185 AL_VAR(int, gui_fg_color);
186 AL_VAR(int, gui_mg_color);
187 AL_VAR(int, gui_bg_color);
188 
189 AL_VAR(int, gui_font_baseline);
190 
191 AL_FUNCPTR(int, gui_mouse_x, (void));
192 AL_FUNCPTR(int, gui_mouse_y, (void));
193 AL_FUNCPTR(int, gui_mouse_z, (void));
194 AL_FUNCPTR(int, gui_mouse_b, (void));
195 
196 AL_FUNC(void, gui_set_screen, (BITMAP *bmp));
197 AL_FUNC(BITMAP *, gui_get_screen, (void));
198 AL_FUNC(int, gui_textout_ex, (struct BITMAP *bmp, AL_CONST char *s, int x, int y, int color, int bg, int centre));
199 AL_FUNC(int, gui_strlen, (AL_CONST char *s));
200 AL_FUNC(void, position_dialog, (DIALOG *dialog, int x, int y));
201 AL_FUNC(void, centre_dialog, (DIALOG *dialog));
202 AL_FUNC(void, set_dialog_color, (DIALOG *dialog, int fg, int bg));
203 AL_FUNC(int, find_dialog_focus, (DIALOG *dialog));
204 AL_FUNC(int, offer_focus, (DIALOG *dialog, int obj, int *focus_obj, int force));
205 AL_FUNC(int, object_message, (DIALOG *dialog, int msg, int c));
206 AL_FUNC(int, dialog_message, (DIALOG *dialog, int msg, int c, int *obj));
207 AL_FUNC(int, broadcast_dialog_message, (int msg, int c));
208 AL_FUNC(int, do_dialog, (DIALOG *dialog, int focus_obj));
209 AL_FUNC(int, popup_dialog, (DIALOG *dialog, int focus_obj));
210 AL_FUNC(DIALOG_PLAYER *, init_dialog, (DIALOG *dialog, int focus_obj));
211 AL_FUNC(int, update_dialog, (DIALOG_PLAYER *player));
212 AL_FUNC(int, shutdown_dialog, (DIALOG_PLAYER *player));
213 AL_FUNC(int, do_menu, (MENU *menu, int x, int y));
214 AL_FUNC(MENU_PLAYER *, init_menu, (MENU *menu, int x, int y));
215 AL_FUNC(int, update_menu, (MENU_PLAYER *player));
216 AL_FUNC(int, shutdown_menu, (MENU_PLAYER *player));
217 AL_FUNC(int, alert, (AL_CONST char *s1, AL_CONST char *s2, AL_CONST char *s3, AL_CONST char *b1, AL_CONST char *b2, int c1, int c2));
218 AL_FUNC(int, alert3, (AL_CONST char *s1, AL_CONST char *s2, AL_CONST char *s3, AL_CONST char *b1, AL_CONST char *b2, AL_CONST char *b3, int c1, int c2, int c3));
219 AL_FUNC(int, file_select_ex, (AL_CONST char *message, char *path, AL_CONST char *ext, int size, int w, int h));
220 
221 AL_FUNC(int, gfx_mode_select, (int *card, int *w, int *h));
222 AL_FUNC(int, gfx_mode_select_ex, (int *card, int *w, int *h, int *color_depth));
223 AL_FUNC(int, gfx_mode_select_filter, (int *card, int *w, int *h, int *color_depth, int (*filter)(int, int, int, int)));
224 
225 #ifdef __cplusplus
226    }
227 #endif
228 
229 #endif          /* ifndef ALLEGRO_GUI_H */
230 
231 
232