diff options
author | Matt Watson <mattdangerw@gmail.com> | 2016-03-28 14:38:22 -0700 |
---|---|---|
committer | Matt Watson <mattdangerw@gmail.com> | 2016-04-08 16:09:30 -0700 |
commit | 7ad64a20aa48b94b89919020643d6ab061e5260d (patch) | |
tree | 02d7b516b3d22419d2c6de8c35ac1fa128852533 /gtk/gtkswitch.c | |
parent | 2ff62595eda55548287cb2257b0864268e228405 (diff) | |
download | gtk+-7ad64a20aa48b94b89919020643d6ab061e5260d.tar.gz |
switch: port to progress tracker
Diffstat (limited to 'gtk/gtkswitch.c')
-rw-r--r-- | gtk/gtkswitch.c | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c index 6e6a8203a9..1cab4ec8a8 100644 --- a/gtk/gtkswitch.c +++ b/gtk/gtkswitch.c @@ -67,6 +67,7 @@ #include "gtkwidgetprivate.h" #include "gtkcssshadowsvalueprivate.h" #include "gtkcssnumbervalueprivate.h" +#include "gtkprogresstrackerprivate.h" #include "fallback-c89.c" @@ -86,9 +87,8 @@ struct _GtkSwitchPrivate GtkCssGadget *slider_gadget; double handle_pos; - gint64 start_time; - gint64 end_time; guint tick_id; + GtkProgressTracker tracker; guint state : 1; guint is_active : 1; @@ -131,17 +131,6 @@ G_DEFINE_TYPE_WITH_CODE (GtkSwitch, gtk_switch, GTK_TYPE_WIDGET, gtk_switch_activatable_interface_init)); G_GNUC_END_IGNORE_DEPRECATIONS; -/* From clutter-easing.c, based on Robert Penner's - * infamous easing equations, MIT license. - */ -static gdouble -ease_out_cubic (gdouble t) -{ - gdouble p = t - 1; - - return p * p * p + 1; -} - static void gtk_switch_end_toggle_animation (GtkSwitch *sw) { @@ -161,20 +150,16 @@ gtk_switch_on_frame_clock_update (GtkWidget *widget, { GtkSwitch *sw = GTK_SWITCH (widget); GtkSwitchPrivate *priv = sw->priv; - gint64 now; - now = gdk_frame_clock_get_frame_time (clock); + gtk_progress_tracker_advance_frame (&priv->tracker, + gdk_frame_clock_get_frame_time (clock)); - if (now < priv->end_time) + if (gtk_progress_tracker_get_state (&priv->tracker) != GTK_PROGRESS_STATE_AFTER) { - gdouble t; - - t = (now - priv->start_time) / (gdouble) (priv->end_time - priv->start_time); - t = ease_out_cubic (t); if (priv->is_active) - priv->handle_pos = 1.0 - t; + priv->handle_pos = 1.0 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE); else - priv->handle_pos = t; + priv->handle_pos = gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE); } else { @@ -200,9 +185,7 @@ gtk_switch_begin_toggle_animation (GtkSwitch *sw) if (animate) { - GdkFrameClock *clock = gtk_widget_get_frame_clock (GTK_WIDGET (sw)); - priv->start_time = gdk_frame_clock_get_frame_time (clock); - priv->end_time = priv->start_time + 1000 * ANIMATION_DURATION; + gtk_progress_tracker_start (&priv->tracker, 1000 * ANIMATION_DURATION, 0, 1.0); if (priv->tick_id == 0) priv->tick_id = gtk_widget_add_tick_callback (GTK_WIDGET (sw), gtk_switch_on_frame_clock_update, |