[libadwaita/wip/exalm/animation-cleanup: 7/10] animation: Reorder functions properly




commit 8ed18fc9255b7ecee33056c5b80133bd38cb1110
Author: Manuel Genovés <manuel genoves gmail com>
Date:   Tue Nov 16 04:26:07 2021 +0500

    animation: Reorder functions properly

 src/adw-animation-private.h |  19 +--
 src/adw-animation.c         | 326 ++++++++++++++++++++++----------------------
 2 files changed, 173 insertions(+), 172 deletions(-)
---
diff --git a/src/adw-animation-private.h b/src/adw-animation-private.h
index cf1146aa..0607c2a6 100644
--- a/src/adw-animation-private.h
+++ b/src/adw-animation-private.h
@@ -59,12 +59,19 @@ AdwAnimation *adw_animation_new (GtkWidget          *widget,
                                  gint64              duration,
                                  AdwAnimationTarget *target) G_GNUC_WARN_UNUSED_RESULT;
 
+GtkWidget *adw_animation_get_widget (AdwAnimation *self);
+
+AdwAnimationTarget *adw_animation_get_target (AdwAnimation *self);
+
+double adw_animation_get_value (AdwAnimation *self);
+
+AdwAnimationStatus adw_animation_get_status (AdwAnimation       *self);
+void               adw_animation_set_status (AdwAnimation       *self,
+                                             AdwAnimationStatus  status);
+
 void adw_animation_start (AdwAnimation *self);
 void adw_animation_stop  (AdwAnimation *self);
 
-GtkWidget *adw_animation_get_widget (AdwAnimation *self);
-double     adw_animation_get_value  (AdwAnimation *self);
-
 double adw_animation_get_value_from (AdwAnimation *self);
 void   adw_animation_set_value_from (AdwAnimation *self,
                                      double        value);
@@ -81,10 +88,4 @@ AdwAnimationInterpolator adw_animation_get_interpolator (AdwAnimation
 void                     adw_animation_set_interpolator (AdwAnimation             *self,
                                                          AdwAnimationInterpolator  interpolator);
 
-AdwAnimationTarget *adw_animation_get_target (AdwAnimation *self);
-
-AdwAnimationStatus adw_animation_get_status (AdwAnimation       *self);
-void               adw_animation_set_status (AdwAnimation       *self,
-                                             AdwAnimationStatus  status);
-
 G_END_DECLS
diff --git a/src/adw-animation.c b/src/adw-animation.c
index 5c5af375..71d69ae2 100644
--- a/src/adw-animation.c
+++ b/src/adw-animation.c
@@ -56,6 +56,102 @@ enum {
 
 static guint signals[SIGNAL_LAST_SIGNAL];
 
+static void
+set_value (AdwAnimation *self,
+           double        value)
+{
+  AdwAnimationPrivate *priv = adw_animation_get_instance_private (self);
+
+  priv->value = value;
+  adw_animation_target_set_value (priv->target, value);
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_VALUE]);
+}
+
+static void
+done (AdwAnimation *self)
+{
+  AdwAnimationPrivate *priv = adw_animation_get_instance_private (self);
+
+  if (priv->status == ADW_ANIMATION_STATUS_COMPLETED)
+    return;
+
+  priv->status = ADW_ANIMATION_STATUS_COMPLETED;
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_STATUS]);
+
+  g_signal_emit (self, signals[SIGNAL_DONE], 0);
+}
+
+static gboolean
+tick_cb (GtkWidget     *widget,
+         GdkFrameClock *frame_clock,
+         AdwAnimation  *self)
+{
+  AdwAnimationPrivate *priv = adw_animation_get_instance_private (self);
+
+  gint64 frame_time = gdk_frame_clock_get_frame_time (frame_clock) / 1000; /* ms */
+  double t = (double) (frame_time - priv->start_time) / priv->duration;
+  double value;
+
+  if (t >= 1) {
+    priv->tick_cb_id = 0;
+
+    set_value (self, priv->value_to);
+
+    if (priv->unmap_cb_id) {
+      g_signal_handler_disconnect (priv->widget, priv->unmap_cb_id);
+      priv->unmap_cb_id = 0;
+    }
+
+    done (self);
+
+    return G_SOURCE_REMOVE;
+  }
+
+  switch (priv->interpolator) {
+    case ADW_ANIMATION_INTERPOLATOR_EASE_IN:
+      value = adw_ease_in_cubic (t);
+      break;
+    case ADW_ANIMATION_INTERPOLATOR_EASE_OUT:
+      value = adw_ease_out_cubic (t);
+      break;
+    case ADW_ANIMATION_INTERPOLATOR_EASE_IN_OUT:
+      value = adw_ease_in_out_cubic (t);
+      break;
+    default:
+      g_assert_not_reached ();
+  }
+
+  set_value (self, adw_lerp (priv->value_from, priv->value_to, value));
+
+  return G_SOURCE_CONTINUE;
+}
+
+static void
+adw_animation_constructed (GObject *object)
+{
+  AdwAnimation *self = ADW_ANIMATION (object);
+  AdwAnimationPrivate *priv = adw_animation_get_instance_private (self);
+
+  G_OBJECT_CLASS (adw_animation_parent_class)->constructed (object);
+
+  priv->value = priv->value_from;
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_VALUE]);
+}
+
+static void
+adw_animation_dispose (GObject *object)
+{
+  AdwAnimation *self = ADW_ANIMATION (object);
+  AdwAnimationPrivate *priv = adw_animation_get_instance_private (self);
+
+  adw_animation_stop (self);
+
+  g_clear_object (&priv->target);
+  g_clear_object (&priv->widget);
+
+  G_OBJECT_CLASS (adw_animation_parent_class)->dispose (object);
+}
+
 static void
 adw_animation_get_property (GObject    *object,
                             guint       prop_id,
@@ -145,43 +241,6 @@ adw_animation_set_property (GObject      *object,
   }
 }
 
-static void
-set_value (AdwAnimation *self,
-           double        value)
-{
-  AdwAnimationPrivate *priv = adw_animation_get_instance_private (self);
-
-  priv->value = value;
-  adw_animation_target_set_value (priv->target, value);
-  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_VALUE]);
-}
-
-static void
-adw_animation_constructed (GObject *object)
-{
-  AdwAnimation *self = ADW_ANIMATION (object);
-  AdwAnimationPrivate *priv = adw_animation_get_instance_private (self);
-
-  priv->value = priv->value_from;
-  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_VALUE]);
-
-  G_OBJECT_CLASS (adw_animation_parent_class)->constructed (object);
-}
-
-static void
-adw_animation_dispose (GObject *object)
-{
-  AdwAnimation *self = ADW_ANIMATION (object);
-  AdwAnimationPrivate *priv = adw_animation_get_instance_private (self);
-
-  adw_animation_stop (self);
-
-  g_clear_object (&priv->target);
-  g_clear_object (&priv->widget);
-
-  G_OBJECT_CLASS (adw_animation_parent_class)->dispose (object);
-}
-
 static void
 adw_animation_class_init (AdwAnimationClass *klass)
 {
@@ -275,65 +334,6 @@ adw_animation_init (AdwAnimation *self)
 {
 }
 
-static void
-done (AdwAnimation *self)
-{
-  AdwAnimationPrivate *priv = adw_animation_get_instance_private (self);
-
-  if (priv->status == ADW_ANIMATION_STATUS_COMPLETED)
-    return;
-
-  priv->status = ADW_ANIMATION_STATUS_COMPLETED;
-  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_STATUS]);
-
-  g_signal_emit (self, signals[SIGNAL_DONE], 0);
-}
-
-static gboolean
-tick_cb (GtkWidget     *widget,
-         GdkFrameClock *frame_clock,
-         AdwAnimation  *self)
-{
-  AdwAnimationPrivate *priv = adw_animation_get_instance_private (self);
-
-  gint64 frame_time = gdk_frame_clock_get_frame_time (frame_clock) / 1000; /* ms */
-  double t = (double) (frame_time - priv->start_time) / priv->duration;
-  double value;
-
-  if (t >= 1) {
-    priv->tick_cb_id = 0;
-
-    set_value (self, priv->value_to);
-
-    if (priv->unmap_cb_id) {
-      g_signal_handler_disconnect (priv->widget, priv->unmap_cb_id);
-      priv->unmap_cb_id = 0;
-    }
-
-    done (self);
-
-    return G_SOURCE_REMOVE;
-  }
-
-  switch (priv->interpolator) {
-    case ADW_ANIMATION_INTERPOLATOR_EASE_IN:
-      value = adw_ease_in_cubic (t);
-      break;
-    case ADW_ANIMATION_INTERPOLATOR_EASE_OUT:
-      value = adw_ease_out_cubic (t);
-      break;
-    case ADW_ANIMATION_INTERPOLATOR_EASE_IN_OUT:
-      value = adw_ease_in_out_cubic (t);
-      break;
-    default:
-      g_assert_not_reached ();
-  }
-
-  set_value (self, adw_lerp (priv->value_from, priv->value_to, value));
-
-  return G_SOURCE_CONTINUE;
-}
-
 AdwAnimation *
 adw_animation_new (GtkWidget          *widget,
                    double              from,
@@ -359,6 +359,73 @@ adw_animation_new (GtkWidget          *widget,
   return animation;
 }
 
+GtkWidget *
+adw_animation_get_widget (AdwAnimation *self)
+{
+  AdwAnimationPrivate *priv;
+
+  g_return_val_if_fail (ADW_IS_ANIMATION (self), NULL);
+
+  priv = adw_animation_get_instance_private (self);
+
+  return priv->widget;
+}
+
+AdwAnimationTarget *
+adw_animation_get_target (AdwAnimation *self)
+{
+  AdwAnimationPrivate *priv;
+
+  g_return_val_if_fail (ADW_IS_ANIMATION (self), NULL);
+
+  priv = adw_animation_get_instance_private (self);
+
+  return priv->target;
+}
+
+double
+adw_animation_get_value (AdwAnimation *self)
+{
+  AdwAnimationPrivate *priv;
+
+  g_return_val_if_fail (ADW_IS_ANIMATION (self), 0.0);
+
+  priv = adw_animation_get_instance_private (self);
+
+  return priv->value;
+}
+
+AdwAnimationStatus
+adw_animation_get_status (AdwAnimation *self)
+{
+  AdwAnimationPrivate *priv;
+
+  g_return_val_if_fail (ADW_IS_ANIMATION (self), ADW_ANIMATION_STATUS_NONE);
+
+  priv = adw_animation_get_instance_private (self);
+
+  return priv->status;
+}
+
+void
+adw_animation_set_status (AdwAnimation       *self,
+                          AdwAnimationStatus  status)
+{
+  AdwAnimationPrivate *priv;
+
+  g_return_if_fail (ADW_IS_ANIMATION (self));
+  g_return_if_fail (status <= ADW_ANIMATION_STATUS_CANCELED);
+
+  priv = adw_animation_get_instance_private (self);
+
+  if (priv->status == status)
+    return;
+
+  priv->status = status;
+
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_STATUS]);
+}
+
 void
 adw_animation_start (AdwAnimation *self)
 {
@@ -411,30 +478,6 @@ adw_animation_stop (AdwAnimation *self)
   done (self);
 }
 
-double
-adw_animation_get_value (AdwAnimation *self)
-{
-  AdwAnimationPrivate *priv;
-
-  g_return_val_if_fail (ADW_IS_ANIMATION (self), 0.0);
-
-  priv = adw_animation_get_instance_private (self);
-
-  return priv->value;
-}
-
-GtkWidget *
-adw_animation_get_widget (AdwAnimation *self)
-{
-  AdwAnimationPrivate *priv;
-
-  g_return_val_if_fail (ADW_IS_ANIMATION (self), NULL);
-
-  priv = adw_animation_get_instance_private (self);
-
-  return priv->widget;
-}
-
 double
 adw_animation_get_value_from (AdwAnimation *self)
 {
@@ -555,46 +598,3 @@ adw_animation_set_interpolator (AdwAnimation             *self,
 
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_INTERPOLATOR]);
 }
-
-AdwAnimationTarget *
-adw_animation_get_target (AdwAnimation *self)
-{
-  AdwAnimationPrivate *priv;
-
-  g_return_val_if_fail (ADW_IS_ANIMATION (self), NULL);
-
-  priv = adw_animation_get_instance_private (self);
-
-  return priv->target;
-}
-
-AdwAnimationStatus
-adw_animation_get_status (AdwAnimation *self)
-{
-  AdwAnimationPrivate *priv;
-
-  g_return_val_if_fail (ADW_IS_ANIMATION (self), ADW_ANIMATION_STATUS_NONE);
-
-  priv = adw_animation_get_instance_private (self);
-
-  return priv->status;
-}
-
-void
-adw_animation_set_status (AdwAnimation       *self,
-                          AdwAnimationStatus  status)
-{
-  AdwAnimationPrivate *priv;
-
-  g_return_if_fail (ADW_IS_ANIMATION (self));
-  g_return_if_fail (status <= ADW_ANIMATION_STATUS_CANCELED);
-
-  priv = adw_animation_get_instance_private (self);
-
-  if (priv->status == status)
-    return;
-
-  priv->status = status;
-
-  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_STATUS]);
-}


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