42#define ALLEGRO_UNSTABLE 1
76static void expect_near(
const char* label,
double got,
double want) {
77 if (fabs(got - want) > 1e-9) {
78 n_log(
LOG_ERR,
"%s: FAILED, got %g wanted %g", label, got, want);
92 memset(&ev, 0,
sizeof(ev));
93 ev.type = ALLEGRO_EVENT_KEY_CHAR;
94 ev.keyboard.keycode = keycode;
108 memset(&ev, 0,
sizeof(ev));
109 ev.type = (
unsigned int)
type;
120 int win, plain, keyed, snapped;
123 if (!al_init() || !al_init_font_addon()) {
127 font = al_create_builtin_font();
135 al_destroy_font(
font);
154 expect_near(
"with neither set, a key moves a twentieth of the range",
160 expect_near(
"the snapping step is the next fallback",
178 expect_near(
"one arrow press moves by the key step",
185 expect_near(
"one wheel notch moves by the key step",
196 double thirds = dragged / (1.0 / 3.0);
198 expect_true(
"a drag moved it", fabs(dragged) > 1e-9);
199 expect_true(
"and it did not land on a multiple of the key step",
200 fabs(thirds - floor(thirds + 0.5)) > 1e-6);
208 expect_near(
"zero falls back rather than freezing the slider",
227 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 ALLEGRO_EVENT key_event(int keycode, unsigned int modifiers)
Build a key event for keycode with modifiers.
static void expect_near(const char *label, double got, double want)
Assert two values are equal to within a tolerance.
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.
#define N_GUI_ALIGN_LEFT
left aligned text
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.
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.
double n_gui_slider_get_value(N_GUI_CTX *ctx, int widget_id)
get the current value of a slider widget
void n_gui_set_focus(N_GUI_CTX *ctx, int widget_id)
Set keyboard focus to a specific 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...
void n_gui_slider_set_step(N_GUI_CTX *ctx, int widget_id, double step)
set slider step increment.
double n_gui_slider_get_key_step(N_GUI_CTX *ctx, int widget_id)
get the arrow key and wheel increment a slider actually uses
void n_gui_slider_set_key_step(N_GUI_CTX *ctx, int widget_id, double step)
set how far one arrow key press or wheel notch moves a slider
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.
#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.