36#define ALLEGRO_UNSTABLE 1
59static void on_click(
int widget_id,
void* user_data) {
66 while ((opt = getopt(argc, argv,
"V:")) != -1) {
69 if (!strcmp(
"LOG_NULL", optarg))
71 else if (!strcmp(
"LOG_NOTICE", optarg))
73 else if (!strcmp(
"LOG_INFO", optarg))
75 else if (!strcmp(
"LOG_ERR", optarg))
77 else if (!strcmp(
"LOG_DEBUG", optarg))
92 memset(&ev, 0,
sizeof(ev));
93 ev.type = (
unsigned int)
type;
101 ALLEGRO_EVENT ev =
mouse_event(ALLEGRO_EVENT_MOUSE_AXES, x, y);
105int main(
int argc,
char** argv) {
108 fprintf(stderr,
"Usage: %s [-V LOG_LEVEL]\n", argv[0]);
117 if (!al_init_font_addon()) {
122 ALLEGRO_FONT*
font = al_create_builtin_font();
131 al_destroy_font(
font);
146 expect_true(
"window + widgets created", win_a >= 0 && btn >= 0 && lbl >= 0);
164 ALLEGRO_EVENT down =
mouse_event(ALLEGRO_EVENT_MOUSE_BUTTON_DOWN, 50, 25);
167 ALLEGRO_EVENT up =
mouse_event(ALLEGRO_EVENT_MOUSE_BUTTON_UP, 50, 25);
193 al_destroy_font(
font);
196 fprintf(stderr,
"ex_gui_hover: %d failure(s)\n",
failures);
199 printf(
"ex_gui_hover: all checks passed\n");
void process_args(int argc, char **argv)
static void expect_true(const char *label, int cond)
static void move_to(N_GUI_CTX *gui, float x, float y)
a move of the pointer to a point, nothing pressed
static ALLEGRO_EVENT mouse_event(int type, int x, int y, int dz)
Build a left-button mouse event at (x, y).
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()
int type
widget type (N_GUI_TYPE_*)
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.
#define N_GUI_ALIGN_LEFT
left aligned text
void n_gui_raise_window(N_GUI_CTX *ctx, int window_id)
Bring a window to the front (top of draw order).
int n_gui_hovered_widget(const N_GUI_CTX *ctx)
Id of the widget currently under the mouse pointer, or -1.
int n_gui_process_event(N_GUI_CTX *ctx, ALLEGRO_EVENT event)
Process an allegro event through the GUI system.
int n_gui_add_label(N_GUI_CTX *ctx, int window_id, const char *text, float x, float y, float w, float h, int align)
Add a static text label.
void n_gui_close_window(N_GUI_CTX *ctx, int window_id)
Close (hide) a window.
#define N_GUI_WIN_FRAMELESS
frameless window: no title bar drawn, drag via window body unless N_GUI_WIN_FIXED_POSITION is also se...
N_GUI_WIDGET * n_gui_get_widget(N_GUI_CTX *ctx, int widget_id)
Get a widget pointer by id.
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.
#define N_GUI_TYPE_BUTTON
widget type: button
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.
#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.
void n_gui_set_widget_visible(N_GUI_CTX *ctx, int widget_id, int visible)
Show or hide a 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.
#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.