static gboolean um_strength_bar_expose (GtkWidget *widget, GdkEventExpose *event) { UmStrengthBar *bar = UM_STRENGTH_BAR (widget); gdouble r, g, b; if (GTK_WIDGET_DRAWABLE (widget)) { cairo_t *cr; cr = gdk_cairo_create (widget->window); cairo_set_line_width (cr, 1); cairo_rectangle (cr, widget->allocation.x, widget->allocation.y, bar->priv->strength * widget->allocation.width, widget->allocation.height); cairo_clip (cr); curved_rectangle (cr, widget->allocation.x + 0.5, widget->allocation.y + 0.5, widget->allocation.width - 1, widget->allocation.height - 1, 4); get_color (bar->priv->strength, &r, &g ,&b); cairo_set_source_rgb (cr, r, g, b); cairo_fill_preserve (cr); cairo_reset_clip (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_stroke (cr); cairo_destroy (cr); } return FALSE; }
static gboolean on_expose_event (GtkWidget *widget, GdkEventExpose *event, GsdMediaKeysWindow *window) { cairo_t *context; cairo_t *cr; cairo_surface_t *surface; int width; int height; GdkColor color; double r, g, b; context = gdk_cairo_create (GTK_WIDGET (window)->window); cairo_set_operator (context, CAIRO_OPERATOR_SOURCE); gtk_window_get_size (GTK_WINDOW (widget), &width, &height); surface = cairo_surface_create_similar (cairo_get_target (context), CAIRO_CONTENT_COLOR_ALPHA, width, height); if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) { goto done; } cr = cairo_create (surface); if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { goto done; } cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_paint (cr); /* draw a box */ curved_rectangle (cr, 0, 0, width, height, height / 10); color = GTK_WIDGET (window)->style->bg [GTK_STATE_NORMAL]; r = (float)color.red / 65535.0; g = (float)color.green / 65535.0; b = (float)color.blue / 65535.0; cairo_set_source_rgba (cr, r, g, b, BG_ALPHA); cairo_fill_preserve (cr); color = GTK_WIDGET (window)->style->fg [GTK_STATE_NORMAL]; r = (float)color.red / 65535.0; g = (float)color.green / 65535.0; b = (float)color.blue / 65535.0; cairo_set_source_rgba (cr, r, g, b, BG_ALPHA); cairo_set_line_width (cr, 1); cairo_stroke (cr); /* draw action */ draw_action (window, cr); cairo_destroy (cr); /* Make sure we have a transparent background */ cairo_rectangle (context, 0, 0, width, height); cairo_set_source_rgba (context, 0.0, 0.0, 0.0, 0.0); cairo_fill (context); cairo_set_source_surface (context, surface, 0, 0); cairo_paint_with_alpha (context, window->priv->fade_out_alpha); done: if (surface != NULL) { cairo_surface_destroy (surface); } cairo_destroy (context); return FALSE; }