2 * Copyright © 2012 Red Hat Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 * Authors: Benjamin Otte <otte@gnome.org>
22 #include "gtkcsstransitionprivate.h"
24 #include "gtkcsseasevalueprivate.h"
26 G_DEFINE_TYPE (GtkCssTransition, _gtk_css_transition, GTK_TYPE_STYLE_ANIMATION)
29 gtk_css_transition_set_values (GtkStyleAnimation *animation,
32 GtkCssComputedValues *values)
34 GtkCssTransition *transition = GTK_CSS_TRANSITION (animation);
38 if (transition->start_time >= for_time_us)
39 value = _gtk_css_value_ref (transition->start);
40 else if (transition->end_time <= for_time_us)
41 value = _gtk_css_value_ref (transition->end);
44 progress = (double) (for_time_us - transition->start_time) / (transition->end_time - transition->start_time);
45 progress = _gtk_css_ease_value_transform (transition->ease, progress);
47 value = _gtk_css_value_transition (transition->start,
52 value = _gtk_css_value_ref (transition->end);
55 /* XXX: Is using 0 correct here? */
56 _gtk_css_computed_values_set_value (values, transition->property, value, 0, NULL);
57 _gtk_css_value_unref (value);
59 return _gtk_bitmask_set (changed, transition->property, TRUE);
63 gtk_css_transition_is_finished (GtkStyleAnimation *animation,
66 GtkCssTransition *transition = GTK_CSS_TRANSITION (animation);
68 return at_time_us >= transition->end_time;
72 gtk_css_transition_finalize (GObject *object)
74 GtkCssTransition *transition = GTK_CSS_TRANSITION (object);
76 _gtk_css_value_unref (transition->start);
77 _gtk_css_value_unref (transition->end);
78 _gtk_css_value_unref (transition->ease);
80 G_OBJECT_CLASS (_gtk_css_transition_parent_class)->finalize (object);
84 _gtk_css_transition_class_init (GtkCssTransitionClass *klass)
86 GObjectClass *object_class = G_OBJECT_CLASS (klass);
87 GtkStyleAnimationClass *animation_class = GTK_STYLE_ANIMATION_CLASS (klass);
89 object_class->finalize = gtk_css_transition_finalize;
91 animation_class->set_values = gtk_css_transition_set_values;
92 animation_class->is_finished = gtk_css_transition_is_finished;
96 _gtk_css_transition_init (GtkCssTransition *transition)
101 _gtk_css_transition_new (guint property,
105 gint64 start_time_us,
108 GtkCssTransition *transition;
110 g_return_val_if_fail (start != NULL, NULL);
111 g_return_val_if_fail (end != NULL, NULL);
112 g_return_val_if_fail (ease != NULL, NULL);
113 g_return_val_if_fail (start_time_us <= end_time_us, NULL);
115 transition = g_object_new (GTK_TYPE_CSS_TRANSITION, NULL);
117 transition->property = property;
118 transition->start = _gtk_css_value_ref (start);
119 transition->end = _gtk_css_value_ref (end);
120 transition->ease = _gtk_css_value_ref (ease);
121 transition->start_time = start_time_us;
122 transition->end_time = end_time_us;
124 return GTK_STYLE_ANIMATION (transition);
128 _gtk_css_transition_get_property (GtkCssTransition *transition)
130 g_return_val_if_fail (GTK_IS_CSS_TRANSITION (transition), 0);
132 return transition->property;