st: Stop using (deprecated) ClutterAnimation

Instead, make StAdjustment a ClutterAnimatable and use a property
transition.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/572
This commit is contained in:
Florian Müllner 2015-09-26 05:20:04 +02:00 committed by Georges Basile Stavracas Neto
parent 443c8347ea
commit 3c5fea59df
2 changed files with 31 additions and 25 deletions

View File

@ -53,7 +53,12 @@ struct _StAdjustmentPrivate
gdouble page_size; gdouble page_size;
}; };
G_DEFINE_TYPE_WITH_PRIVATE (StAdjustment, st_adjustment, G_TYPE_OBJECT) static void animatable_iface_init (ClutterAnimatableInterface *iface);
G_DEFINE_TYPE_WITH_CODE (StAdjustment, st_adjustment, G_TYPE_OBJECT,
G_ADD_PRIVATE (StAdjustment)
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_ANIMATABLE,
animatable_iface_init));
enum enum
{ {
@ -87,6 +92,11 @@ static gboolean st_adjustment_set_page_increment (StAdjustment *adjustment,
static gboolean st_adjustment_set_page_size (StAdjustment *adjustment, static gboolean st_adjustment_set_page_size (StAdjustment *adjustment,
gdouble size); gdouble size);
static void
animatable_iface_init (ClutterAnimatableInterface *iface)
{
}
static void static void
st_adjustment_constructed (GObject *object) st_adjustment_constructed (GObject *object)
{ {

View File

@ -64,7 +64,7 @@ struct _StScrollBarPrivate
guint paging_source_id; guint paging_source_id;
guint paging_event_no; guint paging_event_no;
ClutterAnimation *paging_animation; ClutterTransition *paging_animation;
guint vertical : 1; guint vertical : 1;
}; };
@ -669,11 +669,11 @@ handle_button_press_event_cb (ClutterActor *actor,
} }
static void static void
animation_completed_cb (ClutterAnimation *animation, animation_completed_cb (ClutterTransition *animation,
gboolean is_finished,
StScrollBarPrivate *priv) StScrollBarPrivate *priv)
{ {
g_object_unref (priv->paging_animation); g_clear_object (&priv->paging_animation);
priv->paging_animation = NULL;
} }
static gboolean static gboolean
@ -681,14 +681,11 @@ trough_paging_cb (StScrollBar *self)
{ {
StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (self); StScrollBarPrivate *priv = st_scroll_bar_get_instance_private (self);
gfloat handle_pos, event_pos, tx, ty; gfloat handle_pos, event_pos, tx, ty;
gdouble value; gdouble value, new_value;
gdouble page_increment; gdouble page_increment;
gboolean ret; gboolean ret;
gulong mode; gulong mode;
ClutterAnimation *a;
GValue v = { 0, };
ClutterTimeline *t;
if (priv->paging_event_no == 0) if (priv->paging_event_no == 0)
{ {
@ -754,7 +751,7 @@ trough_paging_cb (StScrollBar *self)
/* Scrolled far enough. */ /* Scrolled far enough. */
return FALSE; return FALSE;
} }
value += page_increment; new_value = value + page_increment;
} }
else else
{ {
@ -768,27 +765,26 @@ trough_paging_cb (StScrollBar *self)
/* Scrolled far enough. */ /* Scrolled far enough. */
return FALSE; return FALSE;
} }
value -= page_increment; new_value = value - page_increment;
} }
if (priv->paging_animation) if (priv->paging_animation)
{ {
clutter_animation_completed (priv->paging_animation); clutter_timeline_stop (CLUTTER_TIMELINE (priv->paging_animation));
} }
/* FIXME: Creating a new animation for each scroll is probably not the best /* FIXME: Creating a new transition for each scroll is probably not the best
* idea, but it's a lot less involved than extenind the current animation */ * idea, but it's a lot less involved than extending the current animation */
a = priv->paging_animation = g_object_new (CLUTTER_TYPE_ANIMATION, priv->paging_animation = g_object_new (CLUTTER_TYPE_PROPERTY_TRANSITION,
"object", priv->adjustment, "animatable", priv->adjustment,
"duration", (guint)(PAGING_SUBSEQUENT_REPEAT_TIMEOUT * st_slow_down_factor), "property-name", "value",
"mode", mode, "interval", clutter_interval_new (G_TYPE_DOUBLE, value, new_value),
NULL); "duration", (guint)(PAGING_SUBSEQUENT_REPEAT_TIMEOUT * st_slow_down_factor),
g_value_init (&v, G_TYPE_DOUBLE); "progress-mode", mode,
g_value_set_double (&v, value); NULL);
clutter_animation_bind (priv->paging_animation, "value", &v); g_signal_connect (priv->paging_animation, "stopped",
t = clutter_animation_get_timeline (priv->paging_animation); G_CALLBACK (animation_completed_cb), priv);
g_signal_connect (a, "completed", G_CALLBACK (animation_completed_cb), priv); clutter_timeline_start (CLUTTER_TIMELINE (priv->paging_animation));
clutter_timeline_start (t);
return ret; return ret;
} }