mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-07 19:30:12 +00:00
switch: port to progress tracker
This commit is contained in:
parent
2ff62595ed
commit
7ad64a20aa
@ -67,6 +67,7 @@
|
|||||||
#include "gtkwidgetprivate.h"
|
#include "gtkwidgetprivate.h"
|
||||||
#include "gtkcssshadowsvalueprivate.h"
|
#include "gtkcssshadowsvalueprivate.h"
|
||||||
#include "gtkcssnumbervalueprivate.h"
|
#include "gtkcssnumbervalueprivate.h"
|
||||||
|
#include "gtkprogresstrackerprivate.h"
|
||||||
|
|
||||||
#include "fallback-c89.c"
|
#include "fallback-c89.c"
|
||||||
|
|
||||||
@ -86,9 +87,8 @@ struct _GtkSwitchPrivate
|
|||||||
GtkCssGadget *slider_gadget;
|
GtkCssGadget *slider_gadget;
|
||||||
|
|
||||||
double handle_pos;
|
double handle_pos;
|
||||||
gint64 start_time;
|
|
||||||
gint64 end_time;
|
|
||||||
guint tick_id;
|
guint tick_id;
|
||||||
|
GtkProgressTracker tracker;
|
||||||
|
|
||||||
guint state : 1;
|
guint state : 1;
|
||||||
guint is_active : 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));
|
gtk_switch_activatable_interface_init));
|
||||||
G_GNUC_END_IGNORE_DEPRECATIONS;
|
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
|
static void
|
||||||
gtk_switch_end_toggle_animation (GtkSwitch *sw)
|
gtk_switch_end_toggle_animation (GtkSwitch *sw)
|
||||||
{
|
{
|
||||||
@ -161,20 +150,16 @@ gtk_switch_on_frame_clock_update (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
GtkSwitch *sw = GTK_SWITCH (widget);
|
GtkSwitch *sw = GTK_SWITCH (widget);
|
||||||
GtkSwitchPrivate *priv = sw->priv;
|
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)
|
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
|
else
|
||||||
priv->handle_pos = t;
|
priv->handle_pos = gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -200,9 +185,7 @@ gtk_switch_begin_toggle_animation (GtkSwitch *sw)
|
|||||||
|
|
||||||
if (animate)
|
if (animate)
|
||||||
{
|
{
|
||||||
GdkFrameClock *clock = gtk_widget_get_frame_clock (GTK_WIDGET (sw));
|
gtk_progress_tracker_start (&priv->tracker, 1000 * ANIMATION_DURATION, 0, 1.0);
|
||||||
priv->start_time = gdk_frame_clock_get_frame_time (clock);
|
|
||||||
priv->end_time = priv->start_time + 1000 * ANIMATION_DURATION;
|
|
||||||
if (priv->tick_id == 0)
|
if (priv->tick_id == 0)
|
||||||
priv->tick_id = gtk_widget_add_tick_callback (GTK_WIDGET (sw),
|
priv->tick_id = gtk_widget_add_tick_callback (GTK_WIDGET (sw),
|
||||||
gtk_switch_on_frame_clock_update,
|
gtk_switch_on_frame_clock_update,
|
||||||
|
Loading…
Reference in New Issue
Block a user