From d59fc6273967cddc791919355429c0e74df54000 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 12 Jan 2008 23:38:31 +0100 Subject: [PATCH] draw rectangle take an Area as arg --- draw.c | 22 ++++++++++++++++------ draw.h | 2 +- statusbar.c | 5 ++++- widgets/focustitle.c | 9 +++++++-- widgets/graph.c | 24 ++++++++++++------------ widgets/progressbar.c | 33 +++++++++++++++++++++------------ widgets/taglist.c | 11 +++++++---- 7 files changed, 68 insertions(+), 38 deletions(-) diff --git a/draw.c b/draw.c index 1f8aefb0..ecfe14ad 100644 --- a/draw.c +++ b/draw.c @@ -88,8 +88,14 @@ draw_text(DrawCtx *ctx, cairo_font_face_t *font_face; cairo_surface_t *surface; cairo_t *cr; + Area rectangle; - draw_rectangle(ctx, x, y, w, h, True, bg); + rectangle.x = x; + rectangle.y = y; + rectangle.width = w; + rectangle.height = h; + + draw_rectangle(ctx, rectangle, True, bg); olen = len = a_strlen(text); @@ -140,8 +146,14 @@ draw_text(DrawCtx *ctx, cairo_surface_destroy(surface); } +/** Draw rectangle + * \param ctx Draw context + * \param geometry geometry + * \param filled filled rectangle? + * \param color color to use + */ void -draw_rectangle(DrawCtx *ctx, int x, int y, int w, int h, Bool filled, XColor color) +draw_rectangle(DrawCtx *ctx, Area geometry, Bool filled, XColor color) { cairo_surface_t *surface; cairo_t *cr; @@ -154,11 +166,11 @@ draw_rectangle(DrawCtx *ctx, int x, int y, int w, int h, Bool filled, XColor col cairo_set_source_rgb(cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0); if(filled) { - cairo_rectangle(cr, x, y, w, h); + cairo_rectangle(cr, geometry.x, geometry.y, geometry.width, geometry.height); cairo_fill(cr); } else - cairo_rectangle(cr, x + 1, y, w - 1, h - 1); + cairo_rectangle(cr, geometry.x + 1, geometry.y, geometry.width - 1, geometry.height - 1); cairo_stroke(cr); @@ -274,8 +286,6 @@ draw_image(DrawCtx *ctx, int x, int y, int wanted_h, const char *filename) cairo_destroy(cr); cairo_surface_destroy(source); cairo_surface_destroy(surface); - - } Area diff --git a/draw.h b/draw.h index 653754df..e44a43b4 100644 --- a/draw.h +++ b/draw.h @@ -55,7 +55,7 @@ typedef struct DrawCtx *draw_get_context(int, int, int); void draw_free_context(DrawCtx *); void draw_text(DrawCtx *, int, int, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg); -void draw_rectangle(DrawCtx *, int, int, int, int, Bool, XColor); +void draw_rectangle(DrawCtx *, Area, Bool, XColor); void draw_graph(DrawCtx *, int, int, int, int *, int, XColor); void draw_circle(DrawCtx *, int, int, int, Bool, XColor); void draw_image(DrawCtx *, int, int, int, const char *); diff --git a/statusbar.c b/statusbar.c index 9c6602f6..9ccd6947 100644 --- a/statusbar.c +++ b/statusbar.c @@ -68,6 +68,7 @@ statusbar_draw(Statusbar *statusbar) int phys_screen = get_phys_screen(statusbar->screen); Widget *widget, *last_drawn = NULL; int left = 0, right = 0; + Area rectangle = { 0, 0, 0, 0 }; /* don't waste our time */ if(statusbar->position == Off) @@ -79,7 +80,9 @@ statusbar_draw(Statusbar *statusbar) statusbar->width, statusbar->height); - draw_rectangle(ctx, 0, 0, statusbar->width, statusbar->height, True, + rectangle.width = statusbar->width; + rectangle.height = statusbar->height; + draw_rectangle(ctx, rectangle, True, globalconf.screens[statusbar->screen].colors_normal[ColBG]); for(widget = statusbar->widgets; widget; widget = widget->next) diff --git a/widgets/focustitle.c b/widgets/focustitle.c index b92e93ad..7992c968 100644 --- a/widgets/focustitle.c +++ b/widgets/focustitle.c @@ -67,8 +67,13 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used) sel->ismax, d->fg); } else - draw_rectangle(ctx, widget->area.x, widget->area.y, - widget->statusbar->width - used, widget->statusbar->height, True, d->bg); + { + Area rectangle = { widget->area.x, + widget->area.y, + widget->statusbar->width - used, + widget->statusbar->height }; + draw_rectangle(ctx, rectangle, True, d->bg); + } widget->area.width = widget->statusbar->width - used; widget->area.height = widget->statusbar->height; diff --git a/widgets/graph.c b/widgets/graph.c index 0191cec0..66a69fbe 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -46,14 +46,13 @@ typedef struct int line_max_index; /* Index of the current maximum value */ } Data; - - static int graph_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { int margin_top, left_offset; Data *d = widget->data; + Area rectangle; if(!widget->user_supplied_x) widget->area.x = widget_calculate_offset(widget->statusbar->width, @@ -69,16 +68,17 @@ graph_draw(Widget *widget, DrawCtx *ctx, int offset, if(!(d->box_height)) d->box_height = (int) (widget->statusbar->height * d->height + 0.5) - 2; + rectangle.x = left_offset; + rectangle.y = margin_top; + rectangle.width = d->lines_size + 2; + rectangle.height = d->box_height + 2; + draw_rectangle(ctx, rectangle, False, d->bordercolor); - draw_rectangle(ctx, - left_offset, margin_top, - d->lines_size + 2, d->box_height + 2, - False, d->bordercolor); - - draw_rectangle(ctx, - left_offset + 1, margin_top + 1, - d->lines_size, d->box_height, - True, d->bg); + rectangle.x++; + rectangle.y++; + rectangle.width -= 2; + rectangle.height -= 2; + draw_rectangle(ctx, rectangle, True, d->bg); if(d->lines[d->lines_index] < 0) d->lines[d->lines_index] = 0; @@ -125,7 +125,7 @@ graph_tell(Widget *widget, char *command) { /* find the new max */ for (i = 0; i < d->lines_size; i++) - if (d->line_values[i] > d->line_values[d->line_max_index]) + if (d->line_values[i] > d->line_values[d->line_max_index]) d->line_max_index = i; d->current_max = MAX(d->line_values[d->line_max_index], d->max); diff --git a/widgets/progressbar.c b/widgets/progressbar.c index f76370ed..c5dbe0a2 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -55,6 +55,7 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { int i, width, pwidth, margin_top, pb_height, left_offset; + Area rectangle; Data *d = widget->data; @@ -80,22 +81,30 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, { pwidth = (int) d->percent[i] ? ((width - 2) * d->percent[i]) / 100 : 0; - draw_rectangle(ctx, - left_offset, margin_top, - width, pb_height, - False, d->bordercolor[i]); + rectangle.x = left_offset; + rectangle.y = margin_top; + rectangle.width = width; + rectangle.height = pb_height; + + draw_rectangle(ctx, rectangle, False, d->bordercolor[i]); if(pwidth > 0) - draw_rectangle(ctx, - left_offset + 1, margin_top + 1, - pwidth, pb_height - 2, - True, d->fg[i]); + { + rectangle.x = left_offset + 1; + rectangle.y = margin_top + 1; + rectangle.width = pwidth; + rectangle.height = pb_height - 2; + draw_rectangle(ctx, rectangle, True, d->fg[i]); + } if(width - 2 - pwidth > 0) /* not filled area */ - draw_rectangle(ctx, - left_offset + 1 + pwidth, margin_top + 1, - width - 2 - pwidth, pb_height - 2, - True, d->bg[i]); + { + rectangle.x = left_offset + 1 + pwidth; + rectangle.y = margin_top + 1; + rectangle.width = width - 2 - pwidth; + rectangle.height = pb_height - 2; + draw_rectangle(ctx, rectangle, True, d->bg[i]); + } margin_top += (pb_height + d->gap); } diff --git a/widgets/taglist.c b/widgets/taglist.c index 6dd803cb..fd072094 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -105,10 +105,13 @@ taglist_draw(Widget *widget, colors[ColFG], colors[ColBG]); if(isoccupied(tag)) - draw_rectangle(ctx, - widget->area.x + widget->area.width, widget->area.y, - flagsize, flagsize, - sel && is_client_tagged(sel, tag), colors[ColFG]); + { + Area rectangle = { widget->area.x + widget->area.width, + widget->area.y, + flagsize, + flagsize }; + draw_rectangle(ctx, rectangle, sel && is_client_tagged(sel, tag), colors[ColFG]); + } widget->area.width += w; }