draw rectangle take an Area as arg

This commit is contained in:
Julien Danjou 2008-01-12 23:38:31 +01:00
parent 641d5fb9b1
commit d59fc62739
7 changed files with 68 additions and 38 deletions

22
draw.c
View File

@ -88,8 +88,14 @@ draw_text(DrawCtx *ctx,
cairo_font_face_t *font_face; cairo_font_face_t *font_face;
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_t *cr; 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); olen = len = a_strlen(text);
@ -140,8 +146,14 @@ draw_text(DrawCtx *ctx,
cairo_surface_destroy(surface); cairo_surface_destroy(surface);
} }
/** Draw rectangle
* \param ctx Draw context
* \param geometry geometry
* \param filled filled rectangle?
* \param color color to use
*/
void 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_surface_t *surface;
cairo_t *cr; 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); cairo_set_source_rgb(cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
if(filled) if(filled)
{ {
cairo_rectangle(cr, x, y, w, h); cairo_rectangle(cr, geometry.x, geometry.y, geometry.width, geometry.height);
cairo_fill(cr); cairo_fill(cr);
} }
else 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); 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_destroy(cr);
cairo_surface_destroy(source); cairo_surface_destroy(source);
cairo_surface_destroy(surface); cairo_surface_destroy(surface);
} }
Area Area

2
draw.h
View File

@ -55,7 +55,7 @@ typedef struct
DrawCtx *draw_get_context(int, int, int); DrawCtx *draw_get_context(int, int, int);
void draw_free_context(DrawCtx *); void draw_free_context(DrawCtx *);
void draw_text(DrawCtx *, int, int, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg); 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_graph(DrawCtx *, int, int, int, int *, int, XColor);
void draw_circle(DrawCtx *, int, int, int, Bool, XColor); void draw_circle(DrawCtx *, int, int, int, Bool, XColor);
void draw_image(DrawCtx *, int, int, int, const char *); void draw_image(DrawCtx *, int, int, int, const char *);

View File

@ -68,6 +68,7 @@ statusbar_draw(Statusbar *statusbar)
int phys_screen = get_phys_screen(statusbar->screen); int phys_screen = get_phys_screen(statusbar->screen);
Widget *widget, *last_drawn = NULL; Widget *widget, *last_drawn = NULL;
int left = 0, right = 0; int left = 0, right = 0;
Area rectangle = { 0, 0, 0, 0 };
/* don't waste our time */ /* don't waste our time */
if(statusbar->position == Off) if(statusbar->position == Off)
@ -79,7 +80,9 @@ statusbar_draw(Statusbar *statusbar)
statusbar->width, statusbar->width,
statusbar->height); 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]); globalconf.screens[statusbar->screen].colors_normal[ColBG]);
for(widget = statusbar->widgets; widget; widget = widget->next) for(widget = statusbar->widgets; widget; widget = widget->next)

View File

@ -67,8 +67,13 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
sel->ismax, d->fg); sel->ismax, d->fg);
} }
else 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.width = widget->statusbar->width - used;
widget->area.height = widget->statusbar->height; widget->area.height = widget->statusbar->height;

View File

@ -46,14 +46,13 @@ typedef struct
int line_max_index; /* Index of the current maximum value */ int line_max_index; /* Index of the current maximum value */
} Data; } Data;
static int static int
graph_draw(Widget *widget, DrawCtx *ctx, int offset, graph_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused))) int used __attribute__ ((unused)))
{ {
int margin_top, left_offset; int margin_top, left_offset;
Data *d = widget->data; Data *d = widget->data;
Area rectangle;
if(!widget->user_supplied_x) if(!widget->user_supplied_x)
widget->area.x = widget_calculate_offset(widget->statusbar->width, 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)) if(!(d->box_height))
d->box_height = (int) (widget->statusbar->height * d->height + 0.5) - 2; 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, rectangle.x++;
left_offset, margin_top, rectangle.y++;
d->lines_size + 2, d->box_height + 2, rectangle.width -= 2;
False, d->bordercolor); rectangle.height -= 2;
draw_rectangle(ctx, rectangle, True, d->bg);
draw_rectangle(ctx,
left_offset + 1, margin_top + 1,
d->lines_size, d->box_height,
True, d->bg);
if(d->lines[d->lines_index] < 0) if(d->lines[d->lines_index] < 0)
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 */ /* find the new max */
for (i = 0; i < d->lines_size; i++) 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->line_max_index = i;
d->current_max = MAX(d->line_values[d->line_max_index], d->max); d->current_max = MAX(d->line_values[d->line_max_index], d->max);

View File

@ -55,6 +55,7 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused))) int used __attribute__ ((unused)))
{ {
int i, width, pwidth, margin_top, pb_height, left_offset; int i, width, pwidth, margin_top, pb_height, left_offset;
Area rectangle;
Data *d = widget->data; 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; pwidth = (int) d->percent[i] ? ((width - 2) * d->percent[i]) / 100 : 0;
draw_rectangle(ctx, rectangle.x = left_offset;
left_offset, margin_top, rectangle.y = margin_top;
width, pb_height, rectangle.width = width;
False, d->bordercolor[i]); rectangle.height = pb_height;
draw_rectangle(ctx, rectangle, False, d->bordercolor[i]);
if(pwidth > 0) if(pwidth > 0)
draw_rectangle(ctx, {
left_offset + 1, margin_top + 1, rectangle.x = left_offset + 1;
pwidth, pb_height - 2, rectangle.y = margin_top + 1;
True, d->fg[i]); rectangle.width = pwidth;
rectangle.height = pb_height - 2;
draw_rectangle(ctx, rectangle, True, d->fg[i]);
}
if(width - 2 - pwidth > 0) /* not filled area */ if(width - 2 - pwidth > 0) /* not filled area */
draw_rectangle(ctx, {
left_offset + 1 + pwidth, margin_top + 1, rectangle.x = left_offset + 1 + pwidth;
width - 2 - pwidth, pb_height - 2, rectangle.y = margin_top + 1;
True, d->bg[i]); rectangle.width = width - 2 - pwidth;
rectangle.height = pb_height - 2;
draw_rectangle(ctx, rectangle, True, d->bg[i]);
}
margin_top += (pb_height + d->gap); margin_top += (pb_height + d->gap);
} }

View File

@ -105,10 +105,13 @@ taglist_draw(Widget *widget,
colors[ColFG], colors[ColFG],
colors[ColBG]); colors[ColBG]);
if(isoccupied(tag)) if(isoccupied(tag))
draw_rectangle(ctx, {
widget->area.x + widget->area.width, widget->area.y, Area rectangle = { widget->area.x + widget->area.width,
flagsize, flagsize, widget->area.y,
sel && is_client_tagged(sel, tag), colors[ColFG]); flagsize,
flagsize };
draw_rectangle(ctx, rectangle, sel && is_client_tagged(sel, tag), colors[ColFG]);
}
widget->area.width += w; widget->area.width += w;
} }