[libhandy/wip/exalm/paginator-animate: 72/78] carousel-box: Extract animation struct



commit 92ae1390faaac0dfcbb49bcfbb170d19dafd63ac
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sat Dec 28 18:07:39 2019 +0500

    carousel-box: Extract animation struct
    
    This will allow child animations to use the same struct, and to make the
    code a bit more generic in future.
    
    Signed-off-by: Alexander Mikhaylenko <alexm gnome org>

 src/hdy-carousel-box.c | 49 +++++++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 22 deletions(-)
---
diff --git a/src/hdy-carousel-box.c b/src/hdy-carousel-box.c
index d7d855e1..1643f9b8 100644
--- a/src/hdy-carousel-box.c
+++ b/src/hdy-carousel-box.c
@@ -26,6 +26,16 @@
  * Since: 1.0
  */
 
+typedef struct _HdyCarouselBoxAnimation HdyCarouselBoxAnimation;
+
+struct _HdyCarouselBoxAnimation
+{
+  gint64 start_time;
+  gint64 end_time;
+  gdouble start_value;
+  gdouble end_value;
+};
+
 typedef struct _HdyCarouselBoxChildInfo HdyCarouselBoxChildInfo;
 
 struct _HdyCarouselBoxChildInfo
@@ -45,12 +55,7 @@ struct _HdyCarouselBox
 {
   GtkContainer parent_instance;
 
-  struct {
-    gint64 start_time;
-    gint64 end_time;
-    gdouble start_position;
-    gdouble end_position;
-  } animation_data;
+  HdyCarouselBoxAnimation animation;
   GList *children;
 
   gint child_width;
@@ -251,19 +256,19 @@ animation_cb (GtkWidget     *widget,
   }
 
   frame_time = gdk_frame_clock_get_frame_time (frame_clock) / 1000;
-  frame_time = MIN (frame_time, self->animation_data.end_time);
+  frame_time = MIN (frame_time, self->animation.end_time);
 
-  duration = self->animation_data.end_time - self->animation_data.start_time;
-  position = (gdouble) (frame_time - self->animation_data.start_time) / duration;
+  duration = self->animation.end_time - self->animation.start_time;
+  position = (gdouble) (frame_time - self->animation.start_time) / duration;
 
   t = hdy_ease_out_cubic (position);
   hdy_carousel_box_set_position (self,
-                                 hdy_lerp (self->animation_data.start_position,
-                                           self->animation_data.end_position, 1 - t));
+                                 hdy_lerp (self->animation.start_value,
+                                           self->animation.end_value, 1 - t));
 
-  if (frame_time == self->animation_data.end_time) {
-    self->animation_data.start_time = 0;
-    self->animation_data.end_time = 0;
+  if (frame_time == self->animation.end_time) {
+    self->animation.start_time = 0;
+    self->animation.end_time = 0;
     g_signal_emit (self, signals[SIGNAL_ANIMATION_STOPPED], 0);
   }
 
@@ -1051,7 +1056,7 @@ hdy_carousel_box_is_animating (HdyCarouselBox *self)
 {
   g_return_val_if_fail (HDY_IS_CAROUSEL_BOX (self), FALSE);
 
-  return (self->animation_data.start_time != 0);
+  return (self->animation.start_time != 0);
 }
 
 /**
@@ -1069,11 +1074,11 @@ hdy_carousel_box_stop_animation (HdyCarouselBox *self)
 {
   g_return_if_fail (HDY_IS_CAROUSEL_BOX (self));
 
-  if (self->animation_data.start_time == 0)
+  if (self->animation.start_time == 0)
     return;
 
-  self->animation_data.start_time = 0;
-  self->animation_data.end_time = 0;
+  self->animation.start_time = 0;
+  self->animation.end_time = 0;
 }
 
 /**
@@ -1126,11 +1131,11 @@ hdy_carousel_box_scroll_to (HdyCarouselBox *self,
 
   frame_time = gdk_frame_clock_get_frame_time (frame_clock);
 
-  self->animation_data.start_position = self->position;
-  self->animation_data.end_position = position;
+  self->animation.start_value = self->position;
+  self->animation.end_value = position;
 
-  self->animation_data.start_time = frame_time / 1000;
-  self->animation_data.end_time = self->animation_data.start_time + duration;
+  self->animation.start_time = frame_time / 1000;
+  self->animation.end_time = self->animation.start_time + duration;
   if (self->tick_cb_id == 0)
     self->tick_cb_id =
       gtk_widget_add_tick_callback (GTK_WIDGET (self), animation_cb, self, NULL);


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