A context starts believing the display is zero by zero. A caller that never calls n_gui_set_display_size() used to get tooltips wrapped to one word per line and dropdowns clamped to nothing, with nothing pointing at the cause. Now n_gui_draw() takes the size of its target bitmap on every pass until a size is set, and the caller's size stands once it is.
Headless: the builtin font and memory bitmaps need no display.
#define ALLEGRO_UNSTABLE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <allegro5/allegro_primitives.h>
if (!ok) {
} else {
}
}
int opt = 0;
while ((opt = getopt(argc, argv, "V:")) != -1) {
if (opt == 'V') {
} else {
return -1;
}
}
return 0;
}
int old_flags = al_get_new_bitmap_flags();
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
ALLEGRO_BITMAP* target = al_create_bitmap(w, h);
al_set_new_bitmap_flags(old_flags);
if (!target) {
return;
}
al_set_target_bitmap(target);
al_clear_to_color(al_map_rgb(0, 0, 0));
al_set_target_bitmap(NULL);
al_destroy_bitmap(target);
}
int main(
int argc,
char** argv) {
fprintf(stderr, "Usage: %s [-V LOG_LEVEL]\n", argv[0]);
return 2;
}
if (!al_init() || !al_init_font_addon() || !al_init_primitives_addon()) {
return 1;
}
ALLEGRO_FONT*
font = al_create_builtin_font();
return 1;
}
return 1;
}
expect_true(
"a new context has no display size",
gui->display_w == 0.0f &&
gui->display_h == 0.0f);
expect_true(
"with none set, a draw takes the target's size",
gui->display_w == 640.0f &&
gui->display_h == 400.0f);
expect_true(
"and follows it when the target changes, as a resize would",
gui->display_w == 1024.0f &&
gui->display_h == 300.0f);
expect_true(
"once a size is set, the target no longer overrides it",
gui->display_w == 800.0f &&
gui->display_h == 600.0f);
fprintf(stderr,
"ex_gui_display_fallback: %d failure(s)\n",
failures);
return 1;
}
printf("ex_gui_display_fallback: ok\n");
return 0;
}
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.