aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/draw.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/draw.c b/src/draw.c
index c952309..7ee9de4 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -104,33 +104,21 @@ static void paint_text(cairo_t *cr, const Layout *layout)
pango_cairo_show_layout(cr, layout->pl);
}
-void draw_paint(Drawer *draw, Window *win)
+static void paint_button_list(cairo_t *cr, GList *layouts)
{
- int width, height;
- compute_width(draw, win, &width, &height);
-
- cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
-
- cairo_t *cr = cairo_create(surface);
- cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
- cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
-
- // Fill the background
- cairo_set_source_rgba(cr, draw->background.r, draw->background.g, draw->background.b, draw->background.a);
- cairo_paint(cr);
-
- for (GList *it = draw->layouts; it; it = it->next) {
+ for (GList *it = layouts; it; it = it->next) {
Layout *layout = it->data;
Button *btn = layout->btn;
cairo_push_group(cr);
-
paint_button(cr, layout);
if (btn->simple) {
+ g_assert_null(layout->children);
paint_text(cr, layout);
} else {
- // TODO
+ g_assert_nonnull(layout->children);
+ paint_button_list(cr, layout->children);
}
if (btn->anim != NULL && btn->anim->paint_func != NULL) {
@@ -147,10 +135,27 @@ void draw_paint(Drawer *draw, Window *win)
cairo_pop_group_to_source(cr);
cairo_paint(cr);
}
+}
+void draw_paint(Drawer *draw, Window *win)
+{
+ int width, height;
+ compute_width(draw, win, &width, &height);
+
+ cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
+
+ cairo_t *cr = cairo_create(surface);
+ cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
+ cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+
+ // Fill the background
+ cairo_set_source_rgba(cr, draw->background.r, draw->background.g, draw->background.b, draw->background.a);
+ cairo_paint(cr);
+
+ // Treat the top-level buttons similarly to a button group
+ paint_button_list(cr, draw->layouts);
cairo_destroy(cr);
- // TODO: Move these somewhere else
window_move(win, draw->left_pad, draw->top_pad);
window_resize(win, width, draw->height);
@@ -158,9 +163,10 @@ void draw_paint(Drawer *draw, Window *win)
cairo_surface_destroy(surface);
}
-// Works only for simple buttons
-static void layout_text(Layout *layout, PangoFontDescription *desc, int height, int radius)
+static void layout_set_text(Layout *layout, PangoFontDescription *desc, int height, int radius)
{
+ g_assert(layout->btn->simple);
+
const char *text = CAST(layout->btn, ButtonSimple)->text;
pango_layout_set_font_description(layout->pl, desc);
@@ -246,10 +252,10 @@ void draw_compute_layout(Drawer *draw, Window *win, GList *btns)
child->y = 0;
child->pl = pango_cairo_create_layout(window_get_context(win));
- layout_text(child, draw->desc, height, radius);
+ layout_set_text(child, draw->desc, height, radius);
child->width += child->line_w;
- draw->layouts = g_list_prepend(draw->layouts, child);
+ layout->children = g_list_prepend(layout->children, child);
x += child->width;
if (it->next != NULL) x += sep;
@@ -274,7 +280,7 @@ void draw_compute_layout(Drawer *draw, Window *win, GList *btns)
if (layout->btn->simple) {
layout->pl = pango_cairo_create_layout(window_get_context(win));
- layout_text(layout, draw->desc, height, radius);
+ layout_set_text(layout, draw->desc, height, radius);
// TODO: make it work for groups
if (btn->anim != NULL && btn->anim->layout_func != NULL) {