[libgd] gd-stack: Allow turning off transitions



commit 0d817b002d6c782cb6d0db8ca6a69312cf1293eb
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Feb 21 14:13:13 2013 -0500

    gd-stack: Allow turning off transitions
    
    https://bugzilla.gnome.org/show_bug.cgi?id=694388

 libgd/gd-stack.c |   38 +++++++++++++++++++++++++++++++++++++-
 libgd/gd-stack.h |   49 +++++++++++++++++++++++++++++--------------------
 test-stack.c     |   12 ++++++++++++
 3 files changed, 78 insertions(+), 21 deletions(-)
---
diff --git a/libgd/gd-stack.c b/libgd/gd-stack.c
index 6fcaf3a..2f7bc24 100644
--- a/libgd/gd-stack.c
+++ b/libgd/gd-stack.c
@@ -28,7 +28,6 @@
 /* TODO:
  *  more transiton types (slides)
  *  filter events out events to the last_child widget during transitions
- *  add way to disable transitions
  */
 
 enum  {
@@ -37,6 +36,7 @@ enum  {
   PROP_VISIBLE_CHILD,
   PROP_VISIBLE_CHILD_NAME,
   PROP_TRANSITION_DURATION,
+  PROP_TRANSITION_TYPE,
 };
 
 enum
@@ -62,6 +62,8 @@ struct _GdStackPrivate {
   GdStackChildInfo *visible_child;
 
   gboolean homogeneous;
+
+  GdStackTransitionType transition_type;
   gint transition_duration;
 
   GdStackChildInfo *last_visible_child;
@@ -181,6 +183,9 @@ gd_stack_get_property (GObject *object,
     case PROP_TRANSITION_DURATION:
       g_value_set_int (value, gd_stack_get_transition_duration (stack));
       break;
+    case PROP_TRANSITION_TYPE:
+      g_value_set_int (value, gd_stack_get_transition_type (stack));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -209,6 +214,9 @@ gd_stack_set_property (GObject *object,
     case PROP_TRANSITION_DURATION:
       gd_stack_set_transition_duration (stack, g_value_get_int (value));
       break;
+    case PROP_TRANSITION_TYPE:
+      gd_stack_set_transition_type (stack, g_value_get_int (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -271,6 +279,15 @@ gd_stack_class_init (GdStackClass * klass)
                                                      G_MININT, G_MAXINT,
                                                      200,
                                                      GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+  g_object_class_install_property (object_class,
+                                   PROP_TRANSITION_TYPE,
+                                   g_param_spec_int ("transition-type",
+                                                     "Transition type",
+                                                     "The type of animation used to transition",
+                                                     GD_STACK_TRANSITION_TYPE_NONE,
+                                                     G_MAXINT,
+                                                     GD_STACK_TRANSITION_TYPE_NONE,
+                                                     GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
   gtk_container_class_install_child_property (container_class, CHILD_PROP_NAME,
     g_param_spec_string ("name",
@@ -503,6 +520,7 @@ gd_stack_start_transition (GdStack *stack)
   GtkWidget *widget = GTK_WIDGET (stack);
 
   if (gtk_widget_get_mapped (widget) &&
+      priv->transition_type != GD_STACK_TRANSITION_TYPE_NONE &&
       priv->last_visible_child != NULL)
     {
       gtk_widget_set_opacity (widget, 0.999);
@@ -747,6 +765,24 @@ gd_stack_set_transition_duration (GdStack *stack,
   g_object_notify (G_OBJECT (stack), "transition-duration");
 }
 
+GdStackTransitionType
+gd_stack_get_transition_type (GdStack *stack)
+{
+  g_return_val_if_fail (stack != NULL, GD_STACK_TRANSITION_TYPE_NONE);
+
+  return stack->priv->transition_type;
+}
+
+void
+gd_stack_set_transition_type (GdStack *stack,
+                              GdStackTransitionType value)
+{
+  g_return_if_fail (stack != NULL);
+
+  stack->priv->transition_type = value;
+  g_object_notify (G_OBJECT (stack), "transition-type");
+}
+
 /**
  * gd_stack_get_visible_child:
  * @stack: a #GdStack
diff --git a/libgd/gd-stack.h b/libgd/gd-stack.h
index 4997e9f..37e58c5 100644
--- a/libgd/gd-stack.h
+++ b/libgd/gd-stack.h
@@ -38,6 +38,11 @@ typedef struct _GdStack GdStack;
 typedef struct _GdStackClass GdStackClass;
 typedef struct _GdStackPrivate GdStackPrivate;
 
+typedef enum {
+  GD_STACK_TRANSITION_TYPE_NONE,
+  GD_STACK_TRANSITION_TYPE_CROSSFADE
+} GdStackTransitionType;
+
 struct _GdStack {
   GtkContainer parent_instance;
   GdStackPrivate *priv;
@@ -49,26 +54,30 @@ struct _GdStackClass {
 
 GType gd_stack_get_type (void) G_GNUC_CONST;
 
-GtkWidget  *gd_stack_new                    (void);
-void        gd_stack_add_named              (GdStack    *stack,
-                                            GtkWidget  *child,
-                                            const char *name);
-void        gd_stack_add_titled             (GdStack    *stack,
-                                            GtkWidget  *child,
-                                            const char *name,
-                                            const char *title);
-void        gd_stack_set_visible_child      (GdStack    *stack,
-                                            GtkWidget  *child);
-GtkWidget * gd_stack_get_visible_child      (GdStack    *stack);
-void        gd_stack_set_visible_child_name (GdStack    *stack,
-                                            const char *name);
-const char *gd_stack_get_visible_child_name (GdStack    *stack);
-void        gd_stack_set_homogeneous        (GdStack    *stack,
-                                            gboolean    homogeneous);
-gboolean    gd_stack_get_homogeneous        (GdStack    *stack);
-void        gd_stack_set_transition_duration(GdStack    *stack,
-                                            gint        transition_duration);
-gint        gd_stack_get_transition_duration(GdStack    *stack);
+GtkWidget  *          gd_stack_new                     (void);
+void                  gd_stack_add_named               (GdStack               *stack,
+                                                       GtkWidget             *child,
+                                                       const char            *name);
+void                  gd_stack_add_titled              (GdStack               *stack,
+                                                       GtkWidget             *child,
+                                                       const char            *name,
+                                                       const char            *title);
+void                  gd_stack_set_visible_child       (GdStack               *stack,
+                                                       GtkWidget             *child);
+GtkWidget *           gd_stack_get_visible_child       (GdStack               *stack);
+void                  gd_stack_set_visible_child_name  (GdStack               *stack,
+                                                       const char            *name);
+const char *          gd_stack_get_visible_child_name  (GdStack               *stack);
+void                  gd_stack_set_homogeneous         (GdStack               *stack,
+                                                       gboolean               homogeneous);
+gboolean              gd_stack_get_homogeneous         (GdStack               *stack);
+void                  gd_stack_set_transition_duration (GdStack               *stack,
+                                                       gint                   transition_duration);
+gint                  gd_stack_get_transition_duration (GdStack               *stack);
+void                  gd_stack_set_transition_type     (GdStack               *stack,
+                                                       GdStackTransitionType  type);
+GdStackTransitionType gd_stack_get_transition_type     (GdStack               *stack);
+
 
 
 G_END_DECLS
diff --git a/test-stack.c b/test-stack.c
index cf12f79..7f6bb88 100644
--- a/test-stack.c
+++ b/test-stack.c
@@ -35,6 +35,13 @@ toggle_icon_name (GtkWidget *button, gpointer data)
                           NULL);
 }
 
+static void
+toggle_transitions (GtkWidget *button, gpointer data)
+{
+  gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+  gd_stack_set_transition_type (GD_STACK (stack), active ? GD_STACK_TRANSITION_TYPE_CROSSFADE : 
GD_STACK_TRANSITION_TYPE_NONE);
+}
+
 gint
 main (gint argc,
       gchar ** argv)
@@ -112,6 +119,11 @@ main (gint argc,
   g_signal_connect (button, "toggled", (GCallback) toggle_icon_name, NULL);
   gtk_container_add (GTK_CONTAINER (hbox), button);
 
+  button = gtk_check_button_new_with_label ("transitions");
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
+  gtk_container_add (GTK_CONTAINER (hbox), button);
+  g_signal_connect (button, "clicked", (GCallback) toggle_transitions, NULL);
+
   gtk_widget_show_all (window);
   gtk_main ();
 


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