X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libi3%2Fdraw_util.c;h=f88360dc32ecab74a146a6e7e35789c9c35efc0b;hb=e4d2b385529847b926a716731be4a8c22ed79007;hp=56b1bce8db882ee666a4c2e6fd069ef63d986c81;hpb=0e73a6e9e7dcc0a01b8666f85bc279a72f7c5936;p=i3%2Fi3 diff --git a/libi3/draw_util.c b/libi3/draw_util.c index 56b1bce8..f88360dc 100644 --- a/libi3/draw_util.c +++ b/libi3/draw_util.c @@ -6,6 +6,8 @@ * draw.c: Utility for drawing. * */ +#include "libi3.h" + #include #include #include @@ -13,13 +15,11 @@ #include #include -#include "libi3.h" - /* The default visual_type to use if none is specified when creating the surface. Must be defined globally. */ xcb_visualtype_t *visual_type; /* Forward declarations */ -static void draw_util_set_source_color(xcb_connection_t *conn, surface_t *surface, color_t color); +static void draw_util_set_source_color(surface_t *surface, color_t color); #define RETURN_UNLESS_SURFACE_INITIALIZED(surface) \ do { \ @@ -84,6 +84,11 @@ void draw_util_surface_set_size(surface_t *surface, int width, int height) { * */ color_t draw_util_hex_to_color(const char *color) { + if (strlen(color) < 6 || color[0] != '#') { + ELOG("Could not parse color: %s\n", color); + return draw_util_hex_to_color("#A9A9A9"); + } + char alpha[2]; if (strlen(color) == strlen("#rrggbbaa")) { alpha[0] = color[7]; @@ -110,13 +115,13 @@ color_t draw_util_hex_to_color(const char *color) { * Set the given color as the source color on the surface. * */ -static void draw_util_set_source_color(xcb_connection_t *conn, surface_t *surface, color_t color) { +static void draw_util_set_source_color(surface_t *surface, color_t color) { RETURN_UNLESS_SURFACE_INITIALIZED(surface); cairo_set_source_rgba(surface->cr, color.red, color.green, color.blue, color.alpha); } -/** +/* * Draw the given text using libi3. * This function also marks the surface dirty which is needed if other means of * drawing are used. This will be the case when using XCB to draw text. @@ -135,13 +140,13 @@ void draw_util_text(i3String *text, surface_t *surface, color_t fg_color, color_ cairo_surface_mark_dirty(surface->surface); } -/** +/* * Draws a filled rectangle. * This function is a convenience wrapper and takes care of flushing the * surface as well as restoring the cairo state. * */ -void draw_util_rectangle(xcb_connection_t *conn, surface_t *surface, color_t color, double x, double y, double w, double h) { +void draw_util_rectangle(surface_t *surface, color_t color, double x, double y, double w, double h) { RETURN_UNLESS_SURFACE_INITIALIZED(surface); cairo_save(surface->cr); @@ -150,7 +155,7 @@ void draw_util_rectangle(xcb_connection_t *conn, surface_t *surface, color_t col * onto the surface rather than blending it. This is a bit more efficient and * allows better color control for the user when using opacity. */ cairo_set_operator(surface->cr, CAIRO_OPERATOR_SOURCE); - draw_util_set_source_color(conn, surface, color); + draw_util_set_source_color(surface, color); cairo_rectangle(surface->cr, x, y, w, h); cairo_fill(surface->cr); @@ -162,11 +167,11 @@ void draw_util_rectangle(xcb_connection_t *conn, surface_t *surface, color_t col cairo_restore(surface->cr); } -/** +/* * Clears a surface with the given color. * */ -void draw_util_clear_surface(xcb_connection_t *conn, surface_t *surface, color_t color) { +void draw_util_clear_surface(surface_t *surface, color_t color) { RETURN_UNLESS_SURFACE_INITIALIZED(surface); cairo_save(surface->cr); @@ -175,7 +180,7 @@ void draw_util_clear_surface(xcb_connection_t *conn, surface_t *surface, color_t * onto the surface rather than blending it. This is a bit more efficient and * allows better color control for the user when using opacity. */ cairo_set_operator(surface->cr, CAIRO_OPERATOR_SOURCE); - draw_util_set_source_color(conn, surface, color); + draw_util_set_source_color(surface, color); cairo_paint(surface->cr); @@ -186,11 +191,11 @@ void draw_util_clear_surface(xcb_connection_t *conn, surface_t *surface, color_t cairo_restore(surface->cr); } -/** +/* * Copies a surface onto another surface. * */ -void draw_util_copy_surface(xcb_connection_t *conn, surface_t *src, surface_t *dest, double src_x, double src_y, +void draw_util_copy_surface(surface_t *src, surface_t *dest, double src_x, double src_y, double dest_x, double dest_y, double width, double height) { RETURN_UNLESS_SURFACE_INITIALIZED(src); RETURN_UNLESS_SURFACE_INITIALIZED(dest);