[libgd] GdStack: Add easing to the slide animation



commit 6d5a7b5d58175c1cabcc22fff18616827643eb88
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Feb 28 10:09:46 2013 +0100

    GdStack: Add easing to the slide animation
    
    This uses ease_out to get a nicer feel than a pure linear one.

 libgd/gd-stack.c |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/libgd/gd-stack.c b/libgd/gd-stack.c
index 3503ad4..f3657fb 100644
--- a/libgd/gd-stack.c
+++ b/libgd/gd-stack.c
@@ -492,6 +492,15 @@ gd_stack_set_child_property (GtkContainer *container,
     }
 }
 
+/* From clutter-easing.c, based on Robert Penner's
+ * infamous easing equations, MIT license. */
+static double
+ease_out_cubic (double t)
+{
+  double p = t - 1;
+  return p * p * p + 1;
+}
+
 static int
 get_bin_window_x (GdStack *stack, GtkAllocation *allocation)
 {
@@ -501,9 +510,9 @@ get_bin_window_x (GdStack *stack, GtkAllocation *allocation)
   if (priv->transition_pos < 1.0)
     {
       if (priv->transition_type == GD_STACK_TRANSITION_TYPE_SLIDE_LEFT)
-        x = allocation->width * (1 - priv->transition_pos);
+        x = allocation->width * ease_out_cubic (1 - priv->transition_pos);
       if (priv->transition_type == GD_STACK_TRANSITION_TYPE_SLIDE_RIGHT)
-        x = -allocation->width * (1 - priv->transition_pos);
+        x = -allocation->width * ease_out_cubic (1 - priv->transition_pos);
     }
 
   return x;
@@ -1049,10 +1058,12 @@ gd_stack_draw_slide (GtkWidget *widget,
 
   gtk_widget_get_allocation (widget, &allocation);
 
+  x = get_bin_window_x (stack, &allocation);
+
   if (priv->transition_type == GD_STACK_TRANSITION_TYPE_SLIDE_LEFT)
-    x = -allocation.width * priv->transition_pos;
+    x -= allocation.width;
   if (priv->transition_type == GD_STACK_TRANSITION_TYPE_SLIDE_RIGHT)
-    x = allocation.width * priv->transition_pos;
+    x += allocation.width;
 
   if (priv->last_visible_pattern)
     {


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