/* * Copyright 2006 (C) George Peter Staplin * * This is roughly based on the NexTk ideas. Rather than having the * structures stored in Tcl, we will store it in C structs that are malloced. * * Is there a better design for rendertree? Right now rendertree results * in 2 copies of all data for performance of rotation, and scaling. */ typedef unsigned char byte; /* * This is used with the nx_jpeg, nx_png, and nx_freetype code. */ struct nx_image { int version; int width; int height; byte *rgba; size_t imagesize; }; struct nx_system { void *(*malloc) (size_t size); void (*out_of_memory) (char *forthis); }; struct nx_event { /* * The first handler to return 1 (if any of them do in the list) * is done processing the event, and it should not be passed further. * userdata is passed as the 3rd argument to the handler. */ int (*event_handler) (struct nx_system *sys, struct nx_window *win, void *p); void *userdata; struct nx_event *next; }; struct nx_window { struct nx_window *children; struct nx_window *parent; int width; int height; size_t imagesize; byte *rgba; byte flags; struct nx_event *buttonpress; struct nx_event *buttonrelease; struct nx_event *keypress; struct nx_event *keyrelease; struct nx_event *motion; struct nx_event *globalbuttonpress; struct nx_event *globalbuttonrelease; struct nx_event *globalkeypress; struct nx_event *globalkeyrelease; struct nx_event *globalmotion; struct nx_window *next; /* Used for the list of children */ }; struct nx_color { byte r, g, b, a; }; int nx_rotate (struct nx_system *sys, struct nx_window *win, int degrees); int nx_blend (struct nx_system *sys, struct nx_window *base, struct nx_window *overlay, int x, int y); int nx_line (struct nx_system *sys, struct nx_window *win, struct nx_color *color, int x1, int y1, int x2, int y2); int nx_rectangle (struct nx_system *sys, struct nx_window *win, struct nx_color *color, int x, int y, int width, int height); int nx_setall (struct nx_system *sys, struct nx_window *win, struct nx_color *color); /* * This iterates and destroys all children. * If win->parent is non-NULL then it removes win from the parent's list. * */ void nx_destroy_window (struct nx_system *sys, struct nx_window *win); void nx_create_window (struct nx_system *sys, int width, int height); /* * This puts win at the head of the win->parent->children list, and renders. */ void nx_raise_window (struct nx_system *sys, struct nx_window *win); void nx_lower_window (struct nx_system *sys, struct nx_window *win); void nx_render_tree (struct nx_system *sys);