41#define ALLEGRO_UNSTABLE 1
78static void on_slider(
int id,
double value,
void* data) {
94 memset(&ev, 0,
sizeof(ev));
95 ev.type = (
unsigned int)
type;
114 for (i = 1; i <= 3; i++) {
129 if (!al_init() || !al_init_font_addon()) {
133 font = al_create_builtin_font();
139 al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
140 pic = al_create_bitmap(16, 16);
143 al_destroy_font(
font);
149 al_destroy_bitmap(pic);
150 al_destroy_font(
font);
165 al_destroy_bitmap(pic);
166 al_destroy_font(
font);
177 expect_true(
"a drag on a slider leaves the window where it was",
178 w->
x == 0.0f && w->
y == 0.0f);
185 expect_true(
"a drag on the empty body moves the window", w->
x == 30.0f && w->
y == 0.0f);
190 expect_true(
"a drag on an image moves the window", w->
x == 60.0f);
193 al_destroy_bitmap(pic);
194 al_destroy_font(
font);
static void expect_true(const char *label, int cond)
static ALLEGRO_EVENT mouse_event(int type, int x, int y, int dz)
Build a left-button mouse event at (x, y).
static int slider_changes
How many times the slider's callback fired.
static void drag_right(N_GUI_CTX *gui, int x, int y, int step)
Press at (x, y), move right in three steps of step with the button held, and release where the pointe...
static void on_slider(int id, double value, void *data)
Slider callback: counts the changes it is told about.
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()
float x
position x on screen
float y
position y on screen
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_IMAGE_FIT
scale to fit within bounds, keep aspect ratio
int n_gui_add_slider(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, double min_val, double max_val, double initial, int mode, void(*on_change)(int, double, void *), void *user_data)
Add a slider widget.
#define N_GUI_SLIDER_VALUE
slider uses raw start/end values
int n_gui_process_event(N_GUI_CTX *ctx, ALLEGRO_EVENT event)
Process an allegro event through the GUI system.
double n_gui_slider_get_value(N_GUI_CTX *ctx, int widget_id)
get the current value of a slider widget
#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_image(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, ALLEGRO_BITMAP *bitmap, int scale_mode)
Add an image display widget.
N_GUI_WINDOW * n_gui_get_window(N_GUI_CTX *ctx, int window_id)
Get a window 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.
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_slider_set_value(N_GUI_CTX *ctx, int widget_id, double value)
set the value of a slider widget
void n_gui_window_set_flags(N_GUI_CTX *ctx, int window_id, int flags)
Set feature flags on a window.
The top-level GUI context that holds all windows.
A pseudo window that contains widgets.
#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_NOTICE
normal but significant condition
#define LOG_INFO
informational
Common headers and low-level functions & define.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.