2 * vim:ts=4:sw=4:expandtab
4 * © 2015 Ingo Bürk and contributors (see also: LICENSE)
6 * draw.h: Utility for drawing.
12 #include <cairo/cairo-xcb.h>
16 /* We need to flush cairo surfaces twice to avoid an assertion bug. See #1989
17 * and https://bugs.freedesktop.org/show_bug.cgi?id=92455. */
18 #define CAIRO_SURFACE_FLUSH(surface) \
20 cairo_surface_flush(surface); \
21 cairo_surface_flush(surface); \
25 /* Represents a color split by color channel. */
26 typedef struct color_t {
31 /* For compatibility, we also store the colorpixel for now. */
35 /* A wrapper grouping an XCB drawable and both a graphics context
36 * and the corresponding cairo objects representing it. */
37 typedef struct surface_t {
38 /* The drawable which is being represented. */
41 /* A classic XCB graphics context. */
48 /* A cairo surface representing the drawable. */
49 cairo_surface_t *surface;
51 /* The cairo object representing the drawale. In general,
52 * this is what one should use for any drawing operation. */
58 * Initialize the surface to represent the given drawable.
61 void draw_util_surface_init(surface_t *surface, xcb_drawable_t drawable, int width, int height);
64 * Destroys the surface.
67 void draw_util_surface_free(surface_t *surface);
70 * Parses the given color in hex format to an internal color representation.
71 * Note that the input must begin with a hash sign, e.g., "#3fbc59".
74 color_t draw_util_hex_to_color(const char *color);
77 * Draw the given text using libi3.
78 * This function also marks the surface dirty which is needed if other means of
79 * drawing are used. This will be the case when using XCB to draw text.
82 void draw_util_text(i3String *text, surface_t *surface, color_t fg_color, color_t bg_color, int x, int y, int max_width);
85 * Draws a filled rectangle.
86 * This function is a convenience wrapper and takes care of flushing the
87 * surface as well as restoring the cairo state.
90 void draw_util_rectangle(surface_t *surface, color_t color, double x, double y, double w, double h);
93 * Clears a surface with the given color.
96 void draw_util_clear_surface(surface_t *surface, color_t color);
99 * Copies a surface onto another surface.
102 void draw_util_copy_surface(surface_t *src, surface_t *dest, double src_x, double src_y,
103 double dest_x, double dest_y, double width, double height);