27#define ALLEGRO_UNSTABLE 1
43 while ((opt = getopt(argc, argv,
"V:")) != -1) {
46 if (!strcmp(
"LOG_NULL", optarg))
48 else if (!strcmp(
"LOG_NOTICE", optarg))
50 else if (!strcmp(
"LOG_INFO", optarg))
52 else if (!strcmp(
"LOG_ERR", optarg))
54 else if (!strcmp(
"LOG_DEBUG", optarg))
80 memset(&ev, 0,
sizeof(ev));
81 ev.type = ALLEGRO_EVENT_KEY_CHAR;
82 ev.keyboard.keycode = keycode;
83 ev.keyboard.unichar = unichar;
84 ev.keyboard.modifiers = (
unsigned int)modifiers;
92 if (len != want_len)
return 0;
93 if (want_len == 0)
return 1;
94 return got && memcmp(got, want, want_len) == 0;
97int main(
int argc,
char** argv) {
100 fprintf(stderr,
"Usage: %s [-V LOG_LEVEL]\n", argv[0]);
105 if (!al_init() || !al_init_font_addon()) {
109 ALLEGRO_FONT*
font = al_create_builtin_font();
117 al_destroy_font(
font);
130 unsigned char payload[260];
132 for (i = 0; i <
sizeof(payload); i++)
133 payload[i] = (
unsigned char)(i & 0xFF);
144 static const unsigned char start[4] = {0xDE, 0xAD, 0xBE, 0xEF};
145 unsigned char want[8];
164 memcpy(want, start,
sizeof(start));
180 expect_true(
"inserted byte is zero", got && got[0] == 0x00);
200 static const unsigned char crlf[2] = {0x0D, 0x0A};
207 unsigned char all[256];
209 for (i2 = 0; i2 <
sizeof(all); i2++)
210 all[i2] = (
unsigned char)i2;
222 al_destroy_font(
font);
void process_args(int argc, char **argv)
static void expect_true(const char *label, int cond)
static int hex_equals(N_GUI_CTX *gui, int hv, const unsigned char *want, size_t want_len)
static void send_key(N_GUI_CTX *gui, int keycode, int unichar, int modifiers)
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.
int n_gui_add_hexview(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h)
Add a read-only hexadecimal byte viewer.
void n_gui_hexview_set_data(N_GUI_CTX *ctx, int widget_id, const unsigned char *data, size_t len)
set (copy) the bytes shown by a hex viewer
void n_gui_hexview_set_cursor(N_GUI_CTX *ctx, int widget_id, size_t offset)
move the edit cursor to a byte offset
const unsigned char * n_gui_hexview_get_data(N_GUI_CTX *ctx, int widget_id, size_t *len)
borrow the bytes a hex view holds
int n_gui_process_event(N_GUI_CTX *ctx, ALLEGRO_EVENT event)
Process an allegro event through the GUI system.
void n_gui_set_focus(N_GUI_CTX *ctx, int widget_id)
Set keyboard focus to a specific widget.
size_t n_gui_hexview_get_length(N_GUI_CTX *ctx, int widget_id)
get the number of bytes currently held by a hex viewer
void n_gui_hexview_set_editable(N_GUI_CTX *ctx, int widget_id, int editable)
make a hex view editable, or read-only again
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.
size_t n_gui_hexview_get_cursor(N_GUI_CTX *ctx, int widget_id)
the byte offset the edit cursor sits on
The top-level GUI context that holds all windows.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#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_NULL
no log output
#define LOG_INFO
informational
Common headers and low-level functions & define.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.