27#define ALLEGRO_UNSTABLE 1
43static void on_combo(
int widget_id,
int index,
void* user_data) {
51 while ((opt = getopt(argc, argv,
"V:")) != -1) {
54 if (!strcmp(
"LOG_NULL", optarg))
56 else if (!strcmp(
"LOG_NOTICE", optarg))
58 else if (!strcmp(
"LOG_INFO", optarg))
60 else if (!strcmp(
"LOG_ERR", optarg))
62 else if (!strcmp(
"LOG_DEBUG", optarg))
81static void on_entry(
int widget_id,
int entry_index,
int tag,
void* user_data) {
97int main(
int argc,
char** argv) {
100 fprintf(stderr,
"Usage: %s [-V LOG_LEVEL]\n", argv[0]);
105 if (!al_init() || !al_init_font_addon()) {
109 ALLEGRO_FONT* font = al_create_builtin_font();
117 al_destroy_font(font);
158 expect_true(
"narrow dropmenu created", narrow >= 0);
165 long_w = (float)al_get_text_width(font,
"DOM Invader proxy");
186 underw->
state &= ~N_GUI_STATE_HOVER;
187 memset(&ev, 0,
sizeof(ev));
188 ev.type = ALLEGRO_EVENT_MOUSE_AXES;
197 underw->
state &= ~N_GUI_STATE_HOVER;
198 memset(&ev, 0,
sizeof(ev));
199 ev.type = ALLEGRO_EVENT_MOUSE_AXES;
203 expect_true(
"hover over the open panel is consumed", consumed == 1);
229 for (i = 0; i < 5; i++) {
231 snprintf(name,
sizeof(name),
"Item %d", i);
242 memset(&ev, 0,
sizeof(ev));
243 ev.type = ALLEGRO_EVENT_MOUSE_AXES;
258 memset(&ev, 0,
sizeof(ev));
259 ev.type = ALLEGRO_EVENT_KEY_CHAR;
260 ev.keyboard.keycode = ALLEGRO_KEY_DOWN;
263 ev.keyboard.keycode = ALLEGRO_KEY_UP;
266 ev.keyboard.keycode = ALLEGRO_KEY_HOME;
269 ev.keyboard.keycode = ALLEGRO_KEY_END;
275 ev.keyboard.keycode = ALLEGRO_KEY_ENTER;
285 ev.keyboard.keycode = ALLEGRO_KEY_ESCAPE;
298 expect_true(
"combobox created", cb >= 0 && cbd != NULL);
299 for (i = 0; i < 5; i++) {
301 snprintf(name,
sizeof(name),
"Opt %d", i);
311 memset(&ev, 0,
sizeof(ev));
312 ev.type = ALLEGRO_EVENT_MOUSE_AXES;
319 memset(&ev, 0,
sizeof(ev));
320 ev.type = ALLEGRO_EVENT_KEY_CHAR;
321 ev.keyboard.keycode = ALLEGRO_KEY_UP;
324 ev.keyboard.keycode = ALLEGRO_KEY_HOME;
330 ev.keyboard.keycode = ALLEGRO_KEY_ENTER;
345 al_destroy_font(font);
void process_args(int argc, char **argv)
static void expect_true(const char *label, int cond)
int is_open
is dropdown currently open
int open_combobox_id
id of the combobox whose dropdown is currently open, or -1
int max_visible
max visible items in dropdown
int selected_index
currently selected index (-1 = none)
int open_dropmenu_id
id of the dropdown menu whose panel is currently open, or -1
int type
widget type (N_GUI_TYPE_*)
int state
current state flags (N_GUI_STATE_*)
int max_visible
max visible items
int highlight_index
open-panel navigation cursor for the wheel and Up/Down keys (-1 = none).
int scroll_offset
scroll offset
int highlight_index
open-panel navigation cursor for the wheel and Up/Down keys (-1 = none).
void * data
widget-specific data (union via void pointer)
int is_open
is the menu currently open
void n_gui_set_display_size(N_GUI_CTX *ctx, float w, float h)
Set the display (viewport) size for global scrollbar computation.
void n_gui_dropmenu_clear(N_GUI_CTX *ctx, int widget_id)
Remove all entries from a dropdown menu.
#define N_GUI_STATE_HOVER
mouse is hovering the widget
int n_gui_dropmenu_get_count(N_GUI_CTX *ctx, int widget_id)
Get number of entries in a dropdown menu.
#define N_GUI_TYPE_DROPMENU
widget type: dropdown menu with static and dynamic entries
int n_gui_process_event(N_GUI_CTX *ctx, ALLEGRO_EVENT event)
Process an allegro event through the GUI system.
int n_gui_combobox_add_item(N_GUI_CTX *ctx, int widget_id, const char *text)
add an item to a combo box
#define N_GUI_WIN_FRAMELESS
frameless window: no title bar drawn, drag via window body unless N_GUI_WIN_FIXED_POSITION is also se...
void n_gui_set_shape_mode(N_GUI_CTX *ctx, int shape_mode)
Set the global widget shape (round or square GUI).
int n_gui_add_combobox(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, void(*on_select)(int, int, void *), void *user_data)
Add a combo box widget (dropdown selector)
N_GUI_WIDGET * n_gui_get_widget(N_GUI_CTX *ctx, int widget_id)
Get a widget pointer by id.
int n_gui_dropmenu_add_entry(N_GUI_CTX *ctx, int widget_id, const char *text, int tag, void(*on_click)(int, int, int, void *), void *user_data)
Add a static entry to a dropdown menu.
int n_gui_add_window(N_GUI_CTX *ctx, const char *title, float x, float y, float w, float h)
Add a new pseudo-window to the context.
N_GUI_CTX * n_gui_new_ctx(ALLEGRO_FONT *default_font)
Create a new GUI context.
float n_gui_dropmenu_panel_width(N_GUI_CTX *ctx, int widget_id)
Width the open drop-down panel needs to show its entries.
void n_gui_destroy_ctx(N_GUI_CTX **ctx)
Destroy a GUI context and all its windows/widgets.
int n_gui_get_shape_mode(N_GUI_CTX *ctx)
Get the global widget shape.
void n_gui_dropmenu_set_label(N_GUI_CTX *ctx, int widget_id, const char *label)
Replace the button label shown on a dropmenu.
int n_gui_combobox_get_selected(N_GUI_CTX *ctx, int widget_id)
get the selected item index in a combobox widget
#define N_GUI_SHAPE_ROUNDED
rounded rectangle shape
void n_gui_window_set_flags(N_GUI_CTX *ctx, int window_id, int flags)
Set feature flags on a window.
#define N_GUI_SHAPE_RECT
rectangle shape (default)
void n_gui_combobox_set_selected(N_GUI_CTX *ctx, int widget_id, int index)
set the selected item in a combobox widget
int n_gui_add_dropmenu(N_GUI_CTX *ctx, int window_id, const char *label, float x, float y, float w, float h, void(*on_open)(int, void *), void *on_open_user_data)
Add a dropdown menu widget.
int n_gui_add_button(N_GUI_CTX *ctx, int window_id, const char *label, float x, float y, float w, float h, int shape, void(*on_click)(int, void *), void *user_data)
Add a button widget to a window.
The top-level GUI context that holds all windows.
dropdown menu specific data
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_NOTICE
normal but significant condition
#define LOG_NULL
no log output
#define LOG_INFO
informational
Common headers and low-level functions & define.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.