[gtk+/wip/matthiasc/fancy-overlay] overlay: Change the effect to a blur
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/fancy-overlay] overlay: Change the effect to a blur
- Date: Sun, 3 Sep 2017 03:54:29 +0000 (UTC)
commit 5c88157a0679fd196d49db9c4dab6982773a4c9a
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Sep 2 23:53:34 2017 -0400
overlay: Change the effect to a blur
And rename the child property blur, and make it a double,
so we can specify the blur radius.
gtk/gtkoverlay.c | 53 +++++++++++++++++---------------------------------
tests/testoverlay.c | 2 +-
2 files changed, 19 insertions(+), 36 deletions(-)
---
diff --git a/gtk/gtkoverlay.c b/gtk/gtkoverlay.c
index e7ed1a1..b96e5f2 100644
--- a/gtk/gtkoverlay.c
+++ b/gtk/gtkoverlay.c
@@ -66,7 +66,7 @@ struct _GtkOverlayChild
{
GtkWidget *widget;
gboolean pass_through;
- gboolean effect;
+ double blur;
};
enum {
@@ -78,7 +78,7 @@ enum
{
CHILD_PROP_0,
CHILD_PROP_PASS_THROUGH,
- CHILD_PROP_EFFECT,
+ CHILD_PROP_BLUR,
CHILD_PROP_INDEX
};
@@ -542,13 +542,13 @@ gtk_overlay_set_child_property (GtkContainer *container,
}
}
break;
- case CHILD_PROP_EFFECT:
+ case CHILD_PROP_BLUR:
if (child_info)
{
- if (g_value_get_boolean (value) != child_info->effect)
+ if (g_value_get_double (value) != child_info->blur)
{
- child_info->effect = g_value_get_boolean (value);
- gtk_container_child_notify (container, child, "effect");
+ child_info->blur = g_value_get_double (value);
+ gtk_container_child_notify (container, child, "blur");
gtk_widget_queue_draw (GTK_WIDGET (overlay));
}
}
@@ -599,11 +599,11 @@ gtk_overlay_get_child_property (GtkContainer *container,
else
g_value_set_boolean (value, FALSE);
break;
- case CHILD_PROP_EFFECT:
+ case CHILD_PROP_BLUR:
if (child_info)
- g_value_set_boolean (value, child_info->effect);
+ g_value_set_double (value, child_info->blur);
else
- g_value_set_boolean (value, FALSE);
+ g_value_set_double (value, 0);
break;
case CHILD_PROP_INDEX:
g_value_set_int (value, g_slist_index (priv->children, child_info));
@@ -621,10 +621,7 @@ gtk_overlay_snapshot (GtkWidget *widget,
GtkWidget *main_widget;
GtkWidget *child;
graphene_rect_t bounds;
- gboolean effect;
- double value;
- graphene_matrix_t matrix;
- graphene_vec4_t offset;
+ double blur = 0;
GtkAllocation alloc;
GtkAllocation effect_alloc;
cairo_region_t *clip;
@@ -634,15 +631,15 @@ gtk_overlay_snapshot (GtkWidget *widget,
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
- gtk_container_child_get (GTK_CONTAINER (widget), child, "effect", &effect, NULL);
- if (effect)
+ gtk_container_child_get (GTK_CONTAINER (widget), child, "blur", &blur, NULL);
+ if (blur > 0)
{
gtk_widget_get_allocation (child, &effect_alloc);
break;
}
}
- if (!effect)
+ if (blur == 0)
{
GTK_WIDGET_CLASS (gtk_overlay_parent_class)->snapshot (widget, snapshot);
return;
@@ -650,24 +647,10 @@ gtk_overlay_snapshot (GtkWidget *widget,
main_widget = gtk_bin_get_child (GTK_BIN (widget));
- /* hardcode grayscale for now */
-#define R 0.2126
-#define G 0.7152
-#define B 0.0722
-
- value = 1.0;
- graphene_matrix_init_from_float (&matrix, (float[16]) {
- 1.0 - (1.0 - R) * value, R * value, R * value, 0.0,
- G * value, 1.0 - (1.0 - G) * value, G * value, 0.0,
- B * value, B * value, 1.0 - (1.0 - B) * value, 0.0,
- 0.0, 0.0, 0.0, 1.0
- });
- graphene_vec4_init (&offset, 0.0, 0.0, 0.0, 0.0);
-
gtk_widget_get_allocation (widget, &alloc);
graphene_rect_init (&bounds, effect_alloc.x, effect_alloc.y, effect_alloc.width, effect_alloc.height);
gtk_snapshot_push_clip (snapshot, &bounds, "Overlay Effect Clip");
- gtk_snapshot_push_color_matrix (snapshot, &matrix, &offset, "Overlay Effect");
+ gtk_snapshot_push_blur (snapshot, blur, "Overlay Effect");
gtk_widget_snapshot_child (widget, main_widget, snapshot);
@@ -730,10 +713,10 @@ gtk_overlay_class_init (GtkOverlayClass *klass)
FALSE,
GTK_PARAM_READWRITE));
- gtk_container_class_install_child_property (container_class, CHILD_PROP_EFFECT,
- g_param_spec_boolean ("effect", NULL, NULL,
- FALSE,
- GTK_PARAM_READWRITE));
+ gtk_container_class_install_child_property (container_class, CHILD_PROP_BLUR,
+ g_param_spec_double ("blur", NULL, NULL,
+ 0, 100, 0,
+ GTK_PARAM_READWRITE));
/**
* GtkOverlay:index:
*
diff --git a/tests/testoverlay.c b/tests/testoverlay.c
index 7b0ae47..041c22e 100644
--- a/tests/testoverlay.c
+++ b/tests/testoverlay.c
@@ -561,7 +561,7 @@ test_effect (void)
gtk_widget_set_valign (button, GTK_ALIGN_START);
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), button);
- gtk_container_child_set (GTK_CONTAINER (overlay), button, "effect", TRUE, NULL);
+ gtk_container_child_set (GTK_CONTAINER (overlay), button, "blur", 5.0, NULL);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (overlay), sw);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]