16#define ALLEGRO_UNSTABLE 1
47 while ((opt = getopt(argc, argv,
"V:")) != -1) {
58static void on_toggle(
int widget_id,
int checked,
void* user_data) {
68 memset(&ev, 0,
sizeof(ev));
69 ev.type = (ALLEGRO_EVENT_TYPE)
type;
72 ev.mouse.dx =
type == ALLEGRO_EVENT_MOUSE_AXES ? 1 : 0;
73 ev.mouse.button =
type == ALLEGRO_EVENT_MOUSE_AXES ? 0u : 1u;
77int main(
int argc,
char** argv) {
80 fprintf(stderr,
"Usage: %s [-V LOG_LEVEL]\n", argv[0]);
85 if (!al_init() || !al_init_font_addon()) {
89 ALLEGRO_FONT*
font = al_create_builtin_font();
93 al_destroy_font(
font);
103 feed(
gui, ALLEGRO_EVENT_MOUSE_AXES, 60, 60);
104 feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_DOWN, 60, 60);
106 feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_UP, 60, 60);
110 feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_DOWN, 60, 60);
111 feed(
gui, ALLEGRO_EVENT_MOUSE_AXES, 190, 70);
112 feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_UP, 190, 70);
116 feed(
gui, ALLEGRO_EVENT_MOUSE_AXES, 60, 60);
117 feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_DOWN, 60, 60);
118 feed(
gui, ALLEGRO_EVENT_MOUSE_AXES, 60, 150);
119 feed(
gui, ALLEGRO_EVENT_MOUSE_AXES, 60, 250);
120 feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_UP, 60, 250);
124 feed(
gui, ALLEGRO_EVENT_MOUSE_AXES, 300, 250);
125 feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_DOWN, 300, 250);
126 feed(
gui, ALLEGRO_EVENT_MOUSE_AXES, 60, 60);
127 feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_UP, 60, 60);
131 feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_DOWN, 60, 60);
132 feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_UP, 60, 60);
136 al_destroy_font(
font);
138 fprintf(stderr,
"ex_gui_checkbox_release: %d failure(s)\n",
failures);
141 printf(
"ex_gui_checkbox_release: ok\n");
void process_args(int argc, char **argv)
static void expect_true(const char *label, int cond)
static void feed(N_GUI_CTX *gui, int type, int x, int y)
feed one mouse event
static int toggles
how many times on_toggle ran, and with what
static void on_toggle(int widget_id, int checked, void *user_data)
the checkbox callback
static void type(N_GUI_CTX *gui, const char *s)
Type a whole string into whatever has focus.
FONT * font
the default 8x8 font, valid after allegro_init()
void n_gui_set_display_size(N_GUI_CTX *ctx, float w, float h)
set the display (viewport) size so global scrollbars can be computed.
int n_gui_process_event(N_GUI_CTX *ctx, ALLEGRO_EVENT event)
Process an allegro event through the GUI system.
#define N_GUI_WIN_FIXED_POSITION
disable window dragging (default:enable)
#define N_GUI_WIN_FRAMELESS
frameless window: no title bar drawn, drag via window body unless N_GUI_WIN_FIXED_POSITION is also se...
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.
void n_gui_destroy_ctx(N_GUI_CTX **ctx)
Destroy a GUI context and all its windows/widgets.
void n_gui_open_window(N_GUI_CTX *ctx, int window_id)
Open (show) a window.
int n_gui_checkbox_is_checked(N_GUI_CTX *ctx, int widget_id)
check if a checkbox widget is checked
void n_gui_window_set_flags(N_GUI_CTX *ctx, int window_id, int flags)
Set feature flags on a window.
int n_gui_add_checkbox(N_GUI_CTX *ctx, int window_id, const char *label, float x, float y, float w, float h, int initial_checked, void(*on_toggle)(int, int, void *), void *user_data)
Add a checkbox widget.
The top-level GUI context that holds all windows.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#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_INFO
informational
Common headers and low-level functions & define.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.