[gnome-builder] widget: add fade in/out widget helpers



commit e8e742a31f785ffba8ff31a7d229e6ca214c2c37
Author: Christian Hergert <christian hergert me>
Date:   Thu Nov 20 16:42:39 2014 -0800

    widget: add fade in/out widget helpers

 src/util/gb-widget.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/util/gb-widget.h |    2 +
 2 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/src/util/gb-widget.c b/src/util/gb-widget.c
index 2b61366..12699a5 100644
--- a/src/util/gb-widget.c
+++ b/src/util/gb-widget.c
@@ -18,6 +18,7 @@
 
 #include <math.h>
 
+#include "gb-animation.h"
 #include "gb-cairo.h"
 #include "gb-rgba.h"
 #include "gb-widget.h"
@@ -171,3 +172,56 @@ gb_widget_shrink_font (gpointer widget)
   gtk_widget_override_font (widget, f);
   pango_font_description_free (f);
 }
+
+static void
+hide_callback (gpointer data)
+{
+  GtkWidget *widget = data;
+
+  gtk_widget_hide (widget);
+  gtk_widget_set_opacity (widget, 1.0);
+}
+
+void
+gb_widget_fade_hide (GtkWidget *widget)
+{
+  GdkFrameClock *frame_clock;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  if (gtk_widget_get_visible (widget))
+    {
+      frame_clock = gtk_widget_get_frame_clock (widget);
+      gb_object_animate_full (widget,
+                              GB_ANIMATION_LINEAR,
+                              1000,
+                              frame_clock,
+                              hide_callback,
+                              widget,
+                              "opacity", 0.0,
+                              NULL);
+    }
+}
+
+void
+gb_widget_fade_show (GtkWidget *widget)
+{
+  GdkFrameClock *frame_clock;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  if (!gtk_widget_get_visible (widget))
+    {
+      frame_clock = gtk_widget_get_frame_clock (widget);
+      gtk_widget_set_opacity (widget, 0.0);
+      gtk_widget_show (widget);
+      gb_object_animate_full (widget,
+                              GB_ANIMATION_LINEAR,
+                              500,
+                              frame_clock,
+                              NULL,
+                              NULL,
+                              "opacity", 1.0,
+                              NULL);
+    }
+}
diff --git a/src/util/gb-widget.h b/src/util/gb-widget.h
index fabd945..67f1b11 100644
--- a/src/util/gb-widget.h
+++ b/src/util/gb-widget.h
@@ -32,6 +32,8 @@ cairo_surface_t *gb_widget_snapshot        (GtkWidget    *widget,
                                             gdouble       alpha,
                                             gboolean      draw_border);
 gpointer         gb_widget_get_workbench   (GtkWidget    *widget);
+void             gb_widget_fade_hide       (GtkWidget    *widget);
+void             gb_widget_fade_show       (GtkWidget    *widget);
 
 G_END_DECLS
 


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