#define ALLEGRO_UNSTABLE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
if (!ok) {
} else {
}
}
int opt = 0;
while ((opt = getopt(argc, argv, "V:")) != -1) {
if (opt == 'V') {
} else {
return -1;
}
}
return 0;
}
(void)widget_id;
(void)user_data;
}
free(state);
}
ALLEGRO_EVENT ev;
memset(&ev, 0, sizeof(ev));
ev.type = (ALLEGRO_EVENT_TYPE)
type;
ev.mouse.x = x;
ev.mouse.y = y;
ev.mouse.dx = (
type == ALLEGRO_EVENT_MOUSE_AXES && dz == 0) ? 1 : 0;
ev.mouse.dz = dz;
ev.mouse.button = (unsigned int)button;
}
static int was(
int type,
int button,
float x,
float y) {
}
int main(
int argc,
char** argv) {
int before = 0;
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();
return 1;
}
feed(
gui, ALLEGRO_EVENT_MOUSE_AXES, 60, 70, 0, 0);
feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_DOWN, 60, 70, 1, 0);
feed(
gui, ALLEGRO_EVENT_MOUSE_AXES, 200, 200, 0, 0);
feed(
gui, ALLEGRO_EVENT_MOUSE_AXES, 210, 190, 0, 0);
feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_UP, 210, 190, 1, 0);
feed(
gui, ALLEGRO_EVENT_MOUSE_AXES, 220, 220, 0, 0);
feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_DOWN, 70, 60, 2, 0);
feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_UP, 70, 60, 2, 0);
expect_true(
"a wheel it takes is consumed",
feed(
gui, ALLEGRO_EVENT_MOUSE_AXES, 60, 70, 0, 1) == 1);
feed(
gui, ALLEGRO_EVENT_MOUSE_AXES, 60, 70, 0, -1);
feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_DOWN, 300, 250, 1, 0);
feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_UP, 300, 250, 1, 0);
feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_DOWN, 55, 55, 1, 0);
feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_UP, 55, 55, 1, 0);
expect_true(
"a press on a widget over it does not reach it",
told == before);
feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_DOWN, 100, 100, 1, 0);
feed(
gui, ALLEGRO_EVENT_MOUSE_BUTTON_UP, 100, 100, 1, 0);
expect_true(
"with the callback taken away it is told nothing",
told == before);
int* state = malloc(sizeof(int));
fprintf(stderr,
"ex_gui_custom_mouse: %d failure(s)\n",
failures);
return 1;
}
printf("ex_gui_custom_mouse: ok\n");
return 0;
}
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, int button)
feed one mouse event at display coordinates
static int was(int type, int button, float x, float y)
was the last thing told this
static int destroyed
how many times the owned state was destroyed
static int on_mouse(int widget_id, const N_GUI_MOUSE_EVENT *ev, void *user_data)
the widget's mouse callback
static N_GUI_MOUSE_EVENT last
the last event the widget was told of, and how many
static int wheel_answer
what the widget answers to a wheel
static void destroy_state(void *state)
the owned state's destructor
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
N_GUI_MOUSE_DOWN, _UP, _MOVE, _DRAG or _WHEEL.
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_MOUSE_DOWN
custom widget mouse event: a press inside it, button 1 or 2
#define N_GUI_MOUSE_WHEEL
custom widget mouse event: the wheel turned over it
int n_gui_process_event(N_GUI_CTX *ctx, ALLEGRO_EVENT event)
Process an allegro event through the GUI system.
#define N_GUI_MOUSE_DRAG
custom widget mouse event: the pointer moved with button 1 held after a press in it; reported outside...
#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_custom_set_mouse(N_GUI_CTX *ctx, int widget_id, N_GUI_CUSTOM_MOUSE on_mouse, void *user_data)
give a custom widget mouse input
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_MOUSE_MOVE
custom widget mouse event: the pointer moved over it with no button held
#define N_GUI_MOUSE_UP
custom widget mouse event: the release of a button 1 press that began in it, wherever the pointer is ...
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.
void n_gui_custom_set_destroy(N_GUI_CTX *ctx, int widget_id, void(*destroy)(void *user_data))
hand a custom widget's paint user pointer to the widget
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)
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.
int n_gui_add_custom(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, N_GUI_CUSTOM_DRAW draw, void *user_data)
add an owner-draw custom widget; returns the widget id or -1
The top-level GUI context that holds all windows.
A mouse event handed to a custom widget, in the widget's own coordinates.
#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.