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_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

2
draw.h
View file

@ -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 *);

View file

@ -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)

View file

@ -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;

View file

@ -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);

View file

@ -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);
}

View file

@ -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;
}