2 * vim:ts=4:sw=4:expandtab
4 * © 2015 Ingo Bürk and contributors (see also: LICENSE)
6 * cairo_util.h: Utility for operations using cairo.
11 #include <cairo/cairo-xcb.h>
13 /* Represents a color split by color channel. */
14 typedef struct color_t {
20 /* For compatibility, we also store the colorpixel for now. */
24 /* A wrapper grouping an XCB drawable and both a graphics context
25 * and the corresponding cairo objects representing it. */
26 typedef struct surface_t {
27 /* The drawable which is being represented. */
30 // TODO remove this once i3 uses solely cairo for drawing operations
31 /* A classic XCB graphics context. This should not be used for
32 * drawing operations. */
35 /* A cairo surface representing the drawable. */
36 cairo_surface_t *surface;
38 /* The cairo object representing the drawale. In general,
39 * this is what one should use for any drawing operation. */
44 * Initialize the cairo surface to represent the given drawable.
47 void cairo_surface_init(surface_t *surface, xcb_drawable_t drawable, int width, int height);
50 * Destroys the surface.
53 void cairo_surface_free(surface_t *surface);
56 * Parses the given color in hex format to an internal color representation.
57 * Note that the input must begin with a hash sign, e.g., "#3fbc59".
60 color_t cairo_hex_to_color(const char *color);
63 * Set the given color as the source color on the surface.
66 void cairo_set_source_color(surface_t *surface, color_t color);
69 * Draw the given text using libi3.
70 * This function also marks the surface dirty which is needed if other means of
71 * drawing are used. This will be the case when using XCB to draw text.
74 void cairo_draw_text(i3String *text, surface_t *surface, color_t fg_color, color_t bg_color, int x, int y, int max_width);
77 * Draws a filled rectangle.
78 * This function is a convenience wrapper and takes care of flushing the
79 * surface as well as restoring the cairo state.
80 * Note that the drawing is done using CAIRO_OPERATOR_SOURCE.
83 void cairo_draw_rectangle(surface_t *surface, color_t color, double x, double y, double w, double h);
86 * Copies a surface onto another surface.
87 * Note that the drawing is done using CAIRO_OPERATOR_SOURCE.
90 void cairo_copy_surface(surface_t *src, surface_t *dest, double src_x, double src_y,
91 double dest_x, double dest_y, double dest_w, double dest_h);