17#define ALLEGRO_UNSTABLE 1
24#include <allegro5/allegro_primitives.h>
47 while ((opt = getopt(argc, argv,
"V:")) != -1) {
59 int old_flags = al_get_new_bitmap_flags();
61 al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
62 ALLEGRO_BITMAP* target = al_create_bitmap(w, h);
63 al_set_new_bitmap_flags(old_flags);
68 al_set_target_bitmap(target);
69 al_clear_to_color(al_map_rgb(0, 0, 0));
71 al_set_target_bitmap(NULL);
72 al_destroy_bitmap(target);
75int main(
int argc,
char** argv) {
78 fprintf(stderr,
"Usage: %s [-V LOG_LEVEL]\n", argv[0]);
83 if (!al_init() || !al_init_font_addon() || !al_init_primitives_addon()) {
87 ALLEGRO_FONT*
font = al_create_builtin_font();
94 al_destroy_font(
font);
101 expect_true(
"a new context has no display size",
gui->display_w == 0.0f &&
gui->display_h == 0.0f);
104 expect_true(
"with none set, a draw takes the target's size",
105 gui->display_w == 640.0f &&
gui->display_h == 400.0f);
108 expect_true(
"and follows it when the target changes, as a resize would",
109 gui->display_w == 1024.0f &&
gui->display_h == 300.0f);
113 expect_true(
"once a size is set, the target no longer overrides it",
114 gui->display_w == 800.0f &&
gui->display_h == 600.0f);
117 al_destroy_font(
font);
119 fprintf(stderr,
"ex_gui_display_fallback: %d failure(s)\n",
failures);
122 printf(
"ex_gui_display_fallback: ok\n");
void process_args(int argc, char **argv)
static void expect_true(const char *label, int cond)
static void draw_into(N_GUI_CTX *gui, int w, int h)
draw one pass of the context into a memory bitmap of the given size
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_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_draw(N_GUI_CTX *ctx)
draw all visible GUI windows and widgets
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.
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.