generic draw functions

/* These functions call the backend to draw in a window. There are primarily three users: - style code (to draw boxes and widgets) - widget implementations (to fallback-draw the widget) - app when drawing on a generic canvas widget */ /* Color is a global state of window rendering. Changes window's drawing color. Returns 0 on success. */ int mbtk_draw_color(mbtk_window_t *win, int r, int g, int b, int a); int mbtk_draw_color_ul(mbtk_window_t *win, unsigned long clr_packed);

/*** Simple drawing primitives ***/

/* Draw a filled rectangle with top-right corner on pixel x1;y1, bottom-left corner on x2;y2. Uses window's last set color. */ void mbtk_draw_fillrect(mbtk_window_t *win, int x1, int y1, int x2, int y2); /* Draw a line; both x1;y1 and x2;y2 are drawn. Uses window's last set color. For horizontal or vertical line use the h or v variant which gives the backend a chance for optimization. */ void mbtk_draw_line(mbtk_window_t *win, int x1, int y1, int x2, int y2); void mbtk_draw_hline(mbtk_window_t *win, int x1, int y1, int x2); void mbtk_draw_vline(mbtk_window_t *win, int x1, int y1, int y2);

/*** Font/text support ***/

/* Search a font by argc/argv[] (syntax is backend specific). If a font is found it is loaded and a valid font ID is returned. Return mbtk_invalid_font_id on error. */ mbtk_font_id_t mbtk_resolve_font(mbtk_display_t *display, int argc, char *argv[]); /* Each window has a global "current font" state. Changes window's font state, returns 0 on succes. */ int mbtk_draw_set_font(mbtk_window_t *win, mbtk_font_id_t fontid); /* Calculates text dimensions assuming a render with the window's current font. Fills in w with total with in pixels, ascent and descent with size above and below the baseline (total height is ascent+descent). */ void mbtk_draw_query_text(mbtk_window_t *win, int *w, int *ascent, int *descent, char *s, int slen); /* Returns character index or -1; fills in char_*_px; pxpos is relative to the text; delta_chr (-1 or +n) modifies the lookup jumping to the previous or next nth character. */ long mbtk_draw_query_text_pos(mbtk_window_t *win, long *char_start_px, long *char_end_px, long pxpos, long delta_chr, char *s, int slen); /* Render text at x;y. The text is placed so that the left side of the baseline is at x;y. The caller needs to store a void *cache for every string/font combination rendered; this saves some time for the backend in repeated text rendering. */ void mbtk_draw_text(mbtk_window_t *win, int x, int y, char *s, int slen, void **cache); /* Free the cache allocated in mbtk_draw_text(). Call this if the given string is no longer to be rendered. */ void mbtk_draw_free_text(mbtk_window_t *win, void **cache);

/*** Pixmap support ***/

/* Import a raw pixmap into dst. Raw format is either 3*8 bit RGB or 4*8 bit RGBA depending on has_alpha; pixals are packed in row major from left to right, from top to bottom, without any padding. */ int mbtk_draw_import_pixmap(mbtk_display_t *display, mbtk_pixmap_t *dst, unsigned char *pixels, int width, int height, int has_alpha); /* Free all memory used by px */ void mbtk_draw_free_pixmap(mbtk_display_t *display, mbtk_pixmap_t *px); /* A pixmap needs to be bound to a window before it can be drawn. Binding returns a pixmap ID which is specific to the window:pixmap combination. This pixmap id can be used to draw the pixmap in this window later. */ mbtk_px_id_t mbtk_draw_bind_pixmap(mbtk_window_t *win, mbtk_pixmap_t *px); void mbtk_draw_unbind_pixmap(mbtk_window_t *win, mbtk_px_id_t pxid); /* Renders a pixmap with it's top-right corner (first pixel) on x;y. The pixmap must be bound to the window already. */ void mbtk_draw_pixmap(mbtk_window_t *win, int x, int y, mbtk_px_id_t pxid); /* When drawing a whole window, call mbtk_draw_start() before the first drawing call and mbtk_draw_flush() after the last. Some backends will store the whole drawing sequence. Applications and widget/style implementations normally don't need to deal with this. */ void mbtk_draw_start(mbtk_window_t *win); void mbtk_draw_flush(mbtk_window_t *win);