[gnome-builder] gtk: improve show/hide fader to cancel previous animation
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] gtk: improve show/hide fader to cancel previous animation
- Date: Wed, 16 Sep 2015 23:04:22 +0000 (UTC)
commit 5d3d69697be40d9c37c053af8c0a7ff4b772df89
Author: Christian Hergert <christian hergert me>
Date: Wed Sep 16 16:01:13 2015 -0700
gtk: improve show/hide fader to cancel previous animation
If we have an animation in progress, we should cancel it before starting
a new animation.
src/util/gb-widget.c | 54 +++++++++++++++++++++++++++++++++++--------------
1 files changed, 38 insertions(+), 16 deletions(-)
---
diff --git a/src/util/gb-widget.c b/src/util/gb-widget.c
index 5b227df..f256f8b 100644
--- a/src/util/gb-widget.c
+++ b/src/util/gb-widget.c
@@ -158,10 +158,18 @@ gb_widget_snapshot (GtkWidget *widget,
}
static void
+show_callback (gpointer data)
+{
+ g_object_set_data (data, "FADE_ANIMATION", NULL);
+ g_object_unref (data);
+}
+
+static void
hide_callback (gpointer data)
{
GtkWidget *widget = data;
+ g_object_set_data (data, "FADE_ANIMATION", NULL);
gtk_widget_hide (widget);
gtk_widget_set_opacity (widget, 1.0);
g_object_unref (widget);
@@ -171,20 +179,27 @@ void
gb_widget_fade_hide (GtkWidget *widget)
{
GdkFrameClock *frame_clock;
+ EggAnimation *anim;
g_return_if_fail (GTK_IS_WIDGET (widget));
if (gtk_widget_get_visible (widget))
{
+ anim = g_object_get_data (G_OBJECT (widget), "FADE_ANIMATION");
+ if (anim != NULL)
+ egg_animation_stop (anim);
+
frame_clock = gtk_widget_get_frame_clock (widget);
- egg_object_animate_full (widget,
- EGG_ANIMATION_LINEAR,
- 1000,
- frame_clock,
- hide_callback,
- g_object_ref (widget),
- "opacity", 0.0,
- NULL);
+ anim = egg_object_animate_full (widget,
+ EGG_ANIMATION_LINEAR,
+ 1000,
+ frame_clock,
+ hide_callback,
+ g_object_ref (widget),
+ "opacity", 0.0,
+ NULL);
+ g_object_set_data_full (G_OBJECT (widget), "FADE_ANIMATION",
+ g_object_ref (anim), g_object_unref);
}
}
@@ -192,22 +207,29 @@ void
gb_widget_fade_show (GtkWidget *widget)
{
GdkFrameClock *frame_clock;
+ EggAnimation *anim;
g_return_if_fail (GTK_IS_WIDGET (widget));
if (!gtk_widget_get_visible (widget))
{
+ anim = g_object_get_data (G_OBJECT (widget), "FADE_ANIMATION");
+ if (anim != NULL)
+ egg_animation_stop (anim);
+
frame_clock = gtk_widget_get_frame_clock (widget);
gtk_widget_set_opacity (widget, 0.0);
gtk_widget_show (widget);
- egg_object_animate_full (widget,
- EGG_ANIMATION_LINEAR,
- 500,
- frame_clock,
- NULL,
- NULL,
- "opacity", 1.0,
- NULL);
+ anim = egg_object_animate_full (widget,
+ EGG_ANIMATION_LINEAR,
+ 500,
+ frame_clock,
+ show_callback,
+ g_object_ref (widget),
+ "opacity", 1.0,
+ NULL);
+ g_object_set_data_full (G_OBJECT (widget), "FADE_ANIMATION",
+ g_object_ref (anim), g_object_unref);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]