[gtk+/wip/blur-2: 3/5] Add blur to box-shadow
- From: Andrea Cimitan <acimitan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/blur-2: 3/5] Add blur to box-shadow
- Date: Mon, 16 Apr 2012 18:04:45 +0000 (UTC)
commit a66425884de2ca86b4435e103533e22c9a297ce4
Author: Andrea Cimitan <andrea cimitan canonical com>
Date: Mon Apr 16 12:02:41 2012 +0100
Add blur to box-shadow
gtk/gtkshadow.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 60 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkshadow.c b/gtk/gtkshadow.c
index 52804af..dc3ffe2 100644
--- a/gtk/gtkshadow.c
+++ b/gtk/gtkshadow.c
@@ -283,11 +283,13 @@ _gtk_text_shadow_paint_layout (GtkShadow *shadow,
cairo_get_current_point (cr, &x, &y);
+ /* Create a larger surface to center the blur. */
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
ink_rect.width + bradius * 2 + padding * 2,
ink_rect.height + bradius * 2 + padding * 2);
cr_surface = cairo_create (surface);
+ /* Center the rendering. */
cairo_translate (cr_surface,
- ink_rect.x + bradius + padding,
- ink_rect.y + bradius + padding);
@@ -316,7 +318,7 @@ _gtk_text_shadow_paint_layout (GtkShadow *shadow,
cairo_rel_move_to (cr, -element->hoffset, -element->voffset);
cairo_restore (cr);
- }
+ }
}
void
@@ -398,12 +400,64 @@ _gtk_box_shadow_render (GtkShadow *shadow,
element->spread, element->spread,
element->spread, element->spread);
- _gtk_rounded_box_path (&box, cr);
- _gtk_rounded_box_clip_path (padding_box, cr);
+ if (element->radius > 0)
+ {
+ cairo_t *cr_surface;
+ cairo_surface_t *surface;
+ gint bradius;
+ gdouble x, y, width, height;
+
+ bradius = element->radius;
- gdk_cairo_set_source_rgba (cr, &element->color);
- cairo_fill (cr);
- }
+ cairo_get_current_point (cr, &x, &y);
+
+ /* Take the bigger box to create the surface. */
+ width = MAX (padding_box->box.width, box.box.width);
+ height = MAX (padding_box->box.height, box.box.height);
+
+ /* Create a larger surface to center the blur. */
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ width + bradius * 2,
+ height + bradius * 2);
+ cr_surface = cairo_create (surface);
+
+ /* Center the rendering. */
+ cairo_translate (cr_surface,
+ bradius,
+ bradius);
+
+ /* Create the path on the surface to blur. */
+ _gtk_rounded_box_path (padding_box, cr_surface);
+ cairo_clip (cr_surface);
+
+ _gtk_rounded_box_path (&box, cr_surface);
+ _gtk_rounded_box_clip_path (padding_box, cr_surface);
+
+ cairo_set_fill_rule (cr_surface, CAIRO_FILL_RULE_EVEN_ODD);
+ gdk_cairo_set_source_rgba (cr_surface, &element->color);
+ cairo_fill (cr_surface);
+
+ /* Blur the surface. */
+ _gtk_cairo_blur_surface (surface, bradius);
+
+ /* Paint the blurred surface to cr. */
+ cairo_set_source_surface (cr, surface,
+ x - bradius,
+ y - bradius);
+ cairo_paint (cr);
+
+ cairo_destroy (cr_surface);
+ cairo_surface_destroy (surface);
+ }
+ else
+ {
+ _gtk_rounded_box_path (&box, cr);
+ _gtk_rounded_box_clip_path (padding_box, cr);
+
+ gdk_cairo_set_source_rgba (cr, &element->color);
+ cairo_fill (cr);
+ }
+ }
cairo_restore (cr);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]