Commit bbb5fc98 authored by Adrien Plazas's avatar Adrien Plazas Committed by Guido Gunther

Use animation helpers

Use the animation helpers added by the previous commit and drop their
implementations around the codebase.
parent fc78be62
......@@ -24,6 +24,8 @@
#include <math.h>
#include <string.h>
#include "hdy-animation-private.h"
/*
* Progress tracker is small helper for tracking progress through gtk
* animations. It's a simple zero-initable struct, meant to be thrown in a
......@@ -227,16 +229,6 @@ gtk_progress_tracker_get_progress (GtkProgressTracker *tracker,
return reversed ? 1.0 - progress : progress;
}
/* 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;
}
/**
* gtk_progress_tracker_get_ease_out_cubic:
* @tracker: The progress tracker
......@@ -252,5 +244,5 @@ gtk_progress_tracker_get_ease_out_cubic (GtkProgressTracker *tracker,
gboolean reversed)
{
gdouble progress = gtk_progress_tracker_get_progress (tracker, reversed);
return ease_out_cubic (progress);
return hdy_ease_out_cubic (progress);
}
......@@ -7,6 +7,7 @@
#include "config.h"
#include <glib/gi18n-lib.h>
#include "hdy-animation-private.h"
#include "hdy-arrows.h"
#include "hdy-enums.h"
#include "gtkprogresstrackerprivate.h"
......@@ -62,17 +63,6 @@ enum {
};
static GParamSpec *style_properties [N_STYLE_PROPS];
static gboolean
get_enable_animations (void)
{
gboolean enable_animations;
g_object_get (gtk_settings_get_default (),
"gtk-enable-animations", &enable_animations,
NULL);
return enable_animations;
}
static void
schedule_draw (HdyArrows *self)
{
......@@ -134,7 +124,7 @@ start_animation (HdyArrows *self)
GtkWidget *widget = GTK_WIDGET (self);
if (gtk_widget_get_mapped (widget) &&
get_enable_animations () &&
hdy_get_enable_animations (widget) &&
priv->animation.duration > 0.0 &&
/* Don't schedule an animation when already ongoing. */
priv->animation.tick_id == 0) {
......
......@@ -10,6 +10,8 @@
#include <glib/gi18n-lib.h>
#include <math.h>
#include "hdy-animation-private.h"
/**
* SECTION:hdy-column
* @short_description: A container letting its child grow up to a given width.
......@@ -44,14 +46,6 @@ static GParamSpec *props[LAST_PROP];
G_DEFINE_TYPE (HdyColumn, hdy_column, GTK_TYPE_BIN)
static gdouble
ease_out_cubic (gdouble progress)
{
gdouble tmp = progress - 1;
return tmp * tmp * tmp + 1;
}
static void
hdy_column_get_property (GObject *object,
guint prop_id,
......@@ -124,7 +118,7 @@ get_child_width (HdyColumn *self,
progress = (width - minimum_width) / (threshold - minimum_width);
return ease_out_cubic (progress) * amplitude + minimum_width;
return hdy_ease_out_cubic (progress) * amplitude + minimum_width;
}
/* This private method is prefixed by the call name because it will be a virtual
......
......@@ -24,6 +24,7 @@
#include "hdy-header-bar.h"
#include "hdy-animation-private.h"
#include "hdy-dialog.h"
#include "hdy-enums.h"
#include "gtkprogresstrackerprivate.h"
......@@ -137,8 +138,6 @@ G_DEFINE_TYPE_WITH_CODE (HdyHeaderBar, hdy_header_bar, GTK_TYPE_CONTAINER,
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
hdy_header_bar_buildable_init));
#define LERP(a, b, t) ((a) + (((b) - (a)) * (1.0 - (t))))
static gboolean
hdy_header_bar_transition_cb (GtkWidget *widget,
GdkFrameClock *frame_clock,
......@@ -774,13 +773,13 @@ hdy_header_bar_get_size (GtkWidget *widget,
strict_centering_t = priv->centering_policy == HDY_CENTERING_POLICY_STRICT ? 1.0 : 0.0;
*minimum = center_min + n_start_children * priv->spacing +
LERP (2 * MAX (start_min_spaced, end_min_spaced),
start_min_spaced + end_min_spaced,
strict_centering_t);
hdy_lerp (2 * MAX (start_min_spaced, end_min_spaced),
start_min_spaced + end_min_spaced,
strict_centering_t);
*natural = center_nat + n_start_children * priv->spacing +
LERP (2 * MAX (start_nat_spaced, end_nat_spaced),
start_nat_spaced + end_nat_spaced,
strict_centering_t);
hdy_lerp (2 * MAX (start_nat_spaced, end_nat_spaced),
start_nat_spaced + end_nat_spaced,
strict_centering_t);
} else {
*minimum = MAX (MAX (start_min, end_min), center_min);
*natural = MAX (MAX (start_nat, end_nat), center_nat);
......@@ -1521,15 +1520,15 @@ hdy_header_bar_size_allocate (GtkWidget *widget,
get_strict_centering_allocations (self, allocation, &strict_allocations, &strict_title_allocation, decoration_width);
for (i = 0; i < nvis_children; i++) {
allocations[i].x = LERP (strict_allocations[i].x, allocations[i].x, strict_centering_t);
allocations[i].y = LERP (strict_allocations[i].y, allocations[i].y, strict_centering_t);
allocations[i].width = LERP (strict_allocations[i].width, allocations[i].width, strict_centering_t);
allocations[i].height = LERP (strict_allocations[i].height, allocations[i].height, strict_centering_t);
allocations[i].x = hdy_lerp (strict_allocations[i].x, allocations[i].x, strict_centering_t);
allocations[i].y = hdy_lerp (strict_allocations[i].y, allocations[i].y, strict_centering_t);
allocations[i].width = hdy_lerp (strict_allocations[i].width, allocations[i].width, strict_centering_t);
allocations[i].height = hdy_lerp (strict_allocations[i].height, allocations[i].height, strict_centering_t);
}
title_allocation.x = LERP (strict_title_allocation.x, title_allocation.x, strict_centering_t);
title_allocation.y = LERP (strict_title_allocation.y, title_allocation.y, strict_centering_t);
title_allocation.width = LERP (strict_title_allocation.width, title_allocation.width, strict_centering_t);
title_allocation.height = LERP (strict_title_allocation.height, title_allocation.height, strict_centering_t);
title_allocation.x = hdy_lerp (strict_title_allocation.x, title_allocation.x, strict_centering_t);
title_allocation.y = hdy_lerp (strict_title_allocation.y, title_allocation.y, strict_centering_t);
title_allocation.width = hdy_lerp (strict_title_allocation.width, title_allocation.width, strict_centering_t);
title_allocation.height = hdy_lerp (strict_title_allocation.height, title_allocation.height, strict_centering_t);
}
/* Allocate the children on both sides of the title. */
......
......@@ -8,6 +8,7 @@
#include <glib/gi18n-lib.h>
#include "gtkprogresstrackerprivate.h"
#include "hdy-animation-private.h"
#include "hdy-leaflet.h"
/* TODO:
......@@ -228,18 +229,6 @@ get_directed_children (HdyLeaflet *self)
priv->children_reversed : priv->children;
}
static gboolean
get_enable_animations (void)
{
gboolean enable_animations;
g_object_get (gtk_settings_get_default (),
"gtk-enable-animations", &enable_animations,
NULL);
return enable_animations;
}
/* Transitions that cause the bin window to move */
static inline gboolean
is_window_moving_child_transition (HdyLeaflet *self)
......@@ -474,7 +463,7 @@ hdy_leaflet_start_child_transition (HdyLeaflet *self,
GtkWidget *widget = GTK_WIDGET (self);
if (gtk_widget_get_mapped (widget) &&
get_enable_animations () &&
hdy_get_enable_animations (widget) &&
transition_type != HDY_LEAFLET_CHILD_TRANSITION_TYPE_NONE &&
transition_duration != 0 &&
priv->last_visible_child != NULL &&
......@@ -739,7 +728,7 @@ hdy_leaflet_start_mode_transition (HdyLeaflet *self,
if (gtk_widget_get_mapped (widget) &&
priv->mode_transition.duration != 0 &&
transition != HDY_LEAFLET_MODE_TRANSITION_TYPE_NONE &&
get_enable_animations ()) {
hdy_get_enable_animations (widget)) {
priv->mode_transition.source_pos = priv->mode_transition.current_pos;
if (priv->mode_transition.tick_id == 0)
priv->mode_transition.tick_id = gtk_widget_add_tick_callback (widget, hdy_leaflet_mode_transition_cb, self, NULL);
......@@ -1229,8 +1218,6 @@ hdy_leaflet_get_interpolate_size (HdyLeaflet *self)
return priv->child_transition.interpolate_size;
}
#define LERP(a, b, t) ((a) + (((b) - (a)) * (1.0 - (t))))
static void
get_preferred_size (gint *min,
gint *nat,
......@@ -1248,7 +1235,7 @@ get_preferred_size (gint *min,
if (same_orientation) {
*min = homogeneous_folded ?
max_min :
LERP (visible_min, last_visible_min, visible_child_progress);
hdy_lerp (visible_min, last_visible_min, visible_child_progress);
*nat = homogeneous_unfolded ?
max_nat * visible_children :
sum_nat;
......@@ -1256,7 +1243,7 @@ get_preferred_size (gint *min,
else {
*min = homogeneous_folded ?
max_min :
LERP (visible_min, last_visible_min, visible_child_progress);
hdy_lerp (visible_min, last_visible_min, visible_child_progress);
*nat = max_nat;
}
}
......
......@@ -20,6 +20,7 @@
#include "hdy-squeezer.h"
#include "gtkprogresstrackerprivate.h"
#include "hdy-animation-private.h"
/**
* SECTION:hdy-squeezer
......@@ -860,8 +861,6 @@ hdy_squeezer_size_allocate (GtkWidget *widget,
}
}
#define LERP(a, b, t) ((a) + (((b) - (a)) * (1.0 - (t))))
/* This private method is prefixed by the class name because it will be a
* virtual method in GTK 4.
*/
......@@ -925,11 +924,11 @@ hdy_squeezer_measure (GtkWidget *widget,
priv->last_visible_child != NULL) {
gdouble t = gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE);
if (orientation == GTK_ORIENTATION_VERTICAL) {
*minimum = LERP (*minimum, priv->last_visible_widget_height, t);
*natural = LERP (*natural, priv->last_visible_widget_height, t);
*minimum = hdy_lerp (*minimum, priv->last_visible_widget_height, t);
*natural = hdy_lerp (*natural, priv->last_visible_widget_height, t);
} else {
*minimum = LERP (*minimum, priv->last_visible_widget_width, t);
*natural = LERP (*natural, priv->last_visible_widget_width, t);
*minimum = hdy_lerp (*minimum, priv->last_visible_widget_width, t);
*natural = hdy_lerp (*natural, priv->last_visible_widget_width, t);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment