[gtk+/revealer] GtkRevealer: Add a fading animation



commit 1b380611289d01ac1f1e69ef4ca94afd2878b520
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Apr 22 09:42:48 2013 -0400

    GtkRevealer: Add a fading animation
    
    Using a container for this is not necessarily the most
    elegant solution, but it lets us reuse the animation
    machinery in GtkRevealer.

 gtk/gtkrevealer.c    | 13 +++++++++----
 gtk/gtkrevealer.h    |  1 +
 tests/testrevealer.c |  4 ++--
 3 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkrevealer.c b/gtk/gtkrevealer.c
index 133793e..3e40d00 100644
--- a/gtk/gtkrevealer.c
+++ b/gtk/gtkrevealer.c
@@ -439,7 +439,15 @@ gtk_revealer_set_position (GtkRevealer *revealer,
       new_visible != gtk_widget_get_child_visible (child))
     gtk_widget_set_child_visible (child, new_visible);
 
-  gtk_widget_queue_resize (GTK_WIDGET (revealer));
+  if (priv->transition_type == GTK_REVEALER_TRANSITION_TYPE_CROSSFADE)
+    {
+      gtk_widget_set_opacity (GTK_WIDGET (revealer), priv->current_pos);
+      gtk_widget_queue_draw (GTK_WIDGET (revealer));
+    }
+  else
+    {
+      gtk_widget_queue_resize (GTK_WIDGET (revealer));
+    }
 
   if (priv->current_pos == priv->target_pos)
     g_object_notify (G_OBJECT (revealer), "child-revealed");
@@ -480,7 +488,6 @@ gtk_revealer_animate_cb (GtkRevealer   *revealer,
   gtk_revealer_animate_step (revealer, now);
   if (priv->current_pos == priv->target_pos)
     {
-      gtk_widget_set_opacity (GTK_WIDGET (revealer), 1.0);
       priv->tick_id = 0;
       return FALSE;
     }
@@ -505,8 +512,6 @@ gtk_revealer_start_animation (GtkRevealer *revealer,
       priv->transition_duration != 0 &&
       priv->transition_type != GTK_REVEALER_TRANSITION_TYPE_NONE)
     {
-      gtk_widget_set_opacity (widget, 0.999);
-
       priv->source_pos = priv->current_pos;
       priv->start_time = gdk_frame_clock_get_frame_time (gtk_widget_get_frame_clock (widget));
       priv->end_time = priv->start_time + (priv->transition_duration * 1000);
diff --git a/gtk/gtkrevealer.h b/gtk/gtkrevealer.h
index c6da3d7..30db0a6 100644
--- a/gtk/gtkrevealer.h
+++ b/gtk/gtkrevealer.h
@@ -40,6 +40,7 @@ typedef struct _GtkRevealerPrivate GtkRevealerPrivate;
 
 typedef enum {
   GTK_REVEALER_TRANSITION_TYPE_NONE,
+  GTK_REVEALER_TRANSITION_TYPE_CROSSFADE,
   GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT,
   GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT,
   GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP,
diff --git a/tests/testrevealer.c b/tests/testrevealer.c
index a71327d..3eab9cd 100644
--- a/tests/testrevealer.c
+++ b/tests/testrevealer.c
@@ -41,7 +41,7 @@ main (gint argc,
   gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
   gtk_grid_attach (GTK_GRID (box), revealer, 1, 0, 1, 1);
 
-  widget = gtk_toggle_button_new_with_label ("None");
+  widget = gtk_toggle_button_new_with_label ("Fade");
   gtk_grid_attach (GTK_GRID (box), widget, 4, 4, 1, 1);
   revealer = gtk_revealer_new ();
   gtk_widget_set_halign (revealer, GTK_ALIGN_END);
@@ -50,7 +50,7 @@ main (gint argc,
   gtk_entry_set_text (GTK_ENTRY (entry), "00000");
   gtk_container_add (GTK_CONTAINER (revealer), entry);
   g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
-  gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_NONE);
+  gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_CROSSFADE);
   gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
   gtk_grid_attach (GTK_GRID (box), revealer, 3, 4, 1, 1);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]