[gtk+/wip/watson/progress-tracker: 3/7] progresstracker: add easing function



commit 08688cdc85743a323e072e4d4d0c9d52b4191479
Author: Matt Watson <mattdangerw gmail com>
Date:   Tue Mar 1 00:24:13 2016 -0800

    progresstracker: add easing function
    
    We have the ease_out_cubic copied all over the place, this is a
    good chance to consolidate

 gtk/gtkprogresstracker.c        |   16 ++++++++++++++++
 gtk/gtkprogresstrackerprivate.h |    2 ++
 gtk/gtkstack.c                  |   34 ++++++++++------------------------
 3 files changed, 28 insertions(+), 24 deletions(-)
---
diff --git a/gtk/gtkprogresstracker.c b/gtk/gtkprogresstracker.c
index 2fcd726..aa8edb4 100644
--- a/gtk/gtkprogresstracker.c
+++ b/gtk/gtkprogresstracker.c
@@ -70,3 +70,19 @@ gtk_progress_tracker_get_progress (GtkProgressTracker *helper)
 {
   return helper->is_running ? helper->progress : 1.0;
 }
+
+/* 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;
+}
+
+gdouble
+gtk_progress_tracker_get_ease (GtkProgressTracker *helper)
+{
+  return ease_out_cubic (gtk_progress_tracker_get_progress (helper));
+}
diff --git a/gtk/gtkprogresstrackerprivate.h b/gtk/gtkprogresstrackerprivate.h
index 9be7b11..442a4f4 100644
--- a/gtk/gtkprogresstrackerprivate.h
+++ b/gtk/gtkprogresstrackerprivate.h
@@ -46,6 +46,8 @@ gboolean             gtk_progress_tracker_is_running   (GtkProgressTracker *help
 
 gdouble              gtk_progress_tracker_get_progress (GtkProgressTracker *helper);
 
+gdouble              gtk_progress_tracker_get_ease     (GtkProgressTracker *helper);
+
 G_END_DECLS
 
 #endif /* __GTK_PROGRESS_TRACKER_PRIVATE_H__ */
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index 8bd2f26..eb6aafe 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -764,16 +764,6 @@ gtk_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 inline gboolean
 is_left_transition (GtkStackTransitionType transition_type)
 {
@@ -861,14 +851,13 @@ get_bin_window_x (GtkStack            *stack,
 {
   GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
   int x = 0;
-  gdouble progress = gtk_progress_tracker_get_progress (&priv->progress_tracker);
 
   if (gtk_progress_tracker_is_running (&priv->progress_tracker))
     {
       if (is_left_transition (priv->active_transition_type))
-        x = allocation->width * (1 - ease_out_cubic (progress));
+        x = allocation->width * (1 - gtk_progress_tracker_get_ease (&priv->progress_tracker));
       if (is_right_transition (priv->active_transition_type))
-        x = -allocation->width * (1 - ease_out_cubic (progress));
+        x = -allocation->width * (1 - gtk_progress_tracker_get_ease (&priv->progress_tracker));
     }
 
   return x;
@@ -880,14 +869,13 @@ get_bin_window_y (GtkStack            *stack,
 {
   GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
   int y = 0;
-  gdouble progress = gtk_progress_tracker_get_progress (&priv->progress_tracker);
 
   if (gtk_progress_tracker_is_running (&priv->progress_tracker))
     {
       if (is_up_transition (priv->active_transition_type))
-        y = allocation->height * (1 - ease_out_cubic (progress));
+        y = allocation->height * (1 - gtk_progress_tracker_get_ease (&priv->progress_tracker));
       if (is_down_transition(priv->active_transition_type))
-        y = -allocation->height * (1 - ease_out_cubic (progress));
+        y = -allocation->height * (1 - gtk_progress_tracker_get_ease (&priv->progress_tracker));
     }
 
   return y;
@@ -1990,7 +1978,6 @@ gtk_stack_draw_under (GtkWidget *widget,
   GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
   GtkAllocation allocation;
   gint x, y, width, height, pos_x, pos_y;
-  gdouble progress = gtk_progress_tracker_get_progress (&priv->progress_tracker);
 
   gtk_widget_get_allocation (widget, &allocation);
   x = y = 0;
@@ -2002,22 +1989,22 @@ gtk_stack_draw_under (GtkWidget *widget,
     {
     case GTK_STACK_TRANSITION_TYPE_UNDER_DOWN:
       y = 0;
-      height = allocation.height * (ease_out_cubic (progress));
+      height = allocation.height * (gtk_progress_tracker_get_ease (&priv->progress_tracker));
       pos_y = height;
       break;
     case GTK_STACK_TRANSITION_TYPE_UNDER_UP:
-      y = allocation.height * (1 - ease_out_cubic (progress));
+      y = allocation.height * (1 - gtk_progress_tracker_get_ease (&priv->progress_tracker));
       height = allocation.height - y;
       pos_y = y - allocation.height;
       break;
     case GTK_STACK_TRANSITION_TYPE_UNDER_LEFT:
-      x = allocation.width * (1 - ease_out_cubic (progress));
+      x = allocation.width * (1 - gtk_progress_tracker_get_ease (&priv->progress_tracker));
       width = allocation.width - x;
       pos_x = x - allocation.width;
       break;
     case GTK_STACK_TRANSITION_TYPE_UNDER_RIGHT:
       x = 0;
-      width = allocation.width * (ease_out_cubic (progress));
+      width = allocation.width * (gtk_progress_tracker_get_ease (&priv->progress_tracker));
       pos_x = width;
       break;
     default:
@@ -2374,7 +2361,6 @@ gtk_stack_measure (GtkCssGadget   *gadget,
   GtkWidget *child;
   gint child_min, child_nat;
   GList *l;
-  gdouble progress = gtk_progress_tracker_get_progress (&priv->progress_tracker);
 
   *minimum = 0;
   *natural = 0;
@@ -2415,13 +2401,13 @@ gtk_stack_measure (GtkCssGadget   *gadget,
     {
       if (orientation == GTK_ORIENTATION_VERTICAL && !priv->vhomogeneous)
         {
-          gdouble t = priv->interpolate_size ? ease_out_cubic (progress) : 1.0;
+          gdouble t = priv->interpolate_size ? gtk_progress_tracker_get_ease (&priv->progress_tracker) : 1.0;
           *minimum = LERP (*minimum, priv->last_visible_widget_height, t);
           *natural = LERP (*natural, priv->last_visible_widget_height, t);
         }
       if (orientation == GTK_ORIENTATION_HORIZONTAL && !priv->hhomogeneous)
         {
-          gdouble t = priv->interpolate_size ? ease_out_cubic (progress) : 1.0;
+          gdouble t = priv->interpolate_size ? gtk_progress_tracker_get_ease (&priv->progress_tracker) : 1.0;
           *minimum = LERP (*minimum, priv->last_visible_widget_width, t);
           *natural = LERP (*natural, priv->last_visible_widget_width, t);
         }


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