N_GUI_TYPE_DROPMENU entry, label, and clear regression test (headless).
N_GUI_TYPE_DROPMENU entry, label, and clear regression test (headless).
#define ALLEGRO_UNSTABLE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static void on_combo(
int widget_id,
int index,
void* user_data) {
(void)widget_id;
(void)user_data;
}
int opt;
while ((opt = getopt(argc, argv, "V:")) != -1) {
switch (opt) {
case 'V':
if (!strcmp("LOG_NULL", optarg))
else if (!strcmp("LOG_NOTICE", optarg))
else if (!strcmp("LOG_INFO", optarg))
else if (!strcmp("LOG_ERR", optarg))
else if (!strcmp("LOG_DEBUG", optarg))
else
return -1;
break;
default:
return -1;
}
}
return 0;
}
if (!cond) {
}
}
static void on_entry(
int widget_id,
int entry_index,
int tag,
void* user_data) {
(void)widget_id;
(void)entry_index;
(void)user_data;
}
return NULL;
}
int main(
int argc,
char** argv) {
fprintf(stderr, "Usage: %s [-V LOG_LEVEL]\n", argv[0]);
return 2;
}
if (!al_init() || !al_init_font_addon()) {
return 1;
}
ALLEGRO_FONT* font = al_create_builtin_font();
if (!font) {
return 1;
}
al_destroy_font(font);
return 1;
}
{
float long_w;
long_w = (float)al_get_text_width(font, "DOM Invader proxy");
}
{
ALLEGRO_EVENT ev;
int consumed;
underw->
state &= ~N_GUI_STATE_HOVER;
memset(&ev, 0, sizeof(ev));
ev.type = ALLEGRO_EVENT_MOUSE_AXES;
ev.mouse.x = 100;
ev.mouse.y = 40;
underw->
state &= ~N_GUI_STATE_HOVER;
memset(&ev, 0, sizeof(ev));
ev.type = ALLEGRO_EVENT_MOUSE_AXES;
ev.mouse.x = 100;
ev.mouse.y = 40;
expect_true(
"hover over the open panel is consumed", consumed == 1);
}
{
ALLEGRO_EVENT ev;
int i;
for (i = 0; i < 5; i++) {
char name[16];
snprintf(name, sizeof(name), "Item %d", i);
}
memset(&ev, 0, sizeof(ev));
ev.type = ALLEGRO_EVENT_MOUSE_AXES;
ev.mouse.x = 5000;
ev.mouse.y = 5000;
ev.mouse.dz = -1;
memset(&ev, 0, sizeof(ev));
ev.type = ALLEGRO_EVENT_KEY_CHAR;
ev.keyboard.keycode = ALLEGRO_KEY_DOWN;
ev.keyboard.keycode = ALLEGRO_KEY_UP;
ev.keyboard.keycode = ALLEGRO_KEY_HOME;
ev.keyboard.keycode = ALLEGRO_KEY_END;
ev.keyboard.keycode = ALLEGRO_KEY_ENTER;
ev.keyboard.keycode = ALLEGRO_KEY_ESCAPE;
}
{
ALLEGRO_EVENT ev;
int i;
expect_true(
"combobox created", cb >= 0 && cbd != NULL);
for (i = 0; i < 5; i++) {
char name[16];
snprintf(name, sizeof(name), "Opt %d", i);
}
memset(&ev, 0, sizeof(ev));
ev.type = ALLEGRO_EVENT_MOUSE_AXES;
ev.mouse.x = 5000;
ev.mouse.y = 5000;
ev.mouse.dz = -1;
memset(&ev, 0, sizeof(ev));
ev.type = ALLEGRO_EVENT_KEY_CHAR;
ev.keyboard.keycode = ALLEGRO_KEY_UP;
ev.keyboard.keycode = ALLEGRO_KEY_HOME;
ev.keyboard.keycode = ALLEGRO_KEY_ENTER;
}
al_destroy_font(font);
return 1;
}
return 0;
}
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.