1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
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 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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #include "gtkanimationdescription.h"
24 struct GtkAnimationDescription
26 GtkTimelineProgressType progress_type;
32 GtkAnimationDescription *
33 _gtk_animation_description_new (gdouble duration,
34 GtkTimelineProgressType progress_type,
37 GtkAnimationDescription *desc;
39 desc = g_slice_new (GtkAnimationDescription);
40 desc->duration = duration;
41 desc->progress_type = progress_type;
49 _gtk_animation_description_get_duration (GtkAnimationDescription *desc)
51 return desc->duration;
54 GtkTimelineProgressType
55 _gtk_animation_description_get_progress_type (GtkAnimationDescription *desc)
57 return desc->progress_type;
61 _gtk_animation_description_get_loop (GtkAnimationDescription *desc)
63 return (desc->loop != 0);
66 GtkAnimationDescription *
67 _gtk_animation_description_ref (GtkAnimationDescription *desc)
74 _gtk_animation_description_unref (GtkAnimationDescription *desc)
78 if (desc->ref_count == 0)
79 g_slice_free (GtkAnimationDescription, desc);
82 GtkAnimationDescription *
83 _gtk_animation_description_from_string (const gchar *str)
85 gchar timing_function[16] = { 0, };
86 gchar duration_unit[3] = { 0, };
87 gchar loop_str[5] = { 0, };
88 GtkTimelineProgressType progress_type;
92 if (sscanf (str, "%d%2s %15s %5s", &duration, duration_unit, timing_function, loop_str) == 4)
94 else if (sscanf (str, "%d%2s %15s", &duration, duration_unit, timing_function) == 3)
99 if (strcmp (duration_unit, "s") == 0)
101 else if (strcmp (duration_unit, "ms") != 0)
103 g_warning ("Unknown duration unit: %s\n", duration_unit);
107 if (strcmp (timing_function, "linear") == 0)
108 progress_type = GTK_TIMELINE_PROGRESS_LINEAR;
109 else if (strcmp (timing_function, "ease") == 0)
110 progress_type = GTK_TIMELINE_PROGRESS_EASE;
111 else if (strcmp (timing_function, "ease-in") == 0)
112 progress_type = GTK_TIMELINE_PROGRESS_EASE_IN;
113 else if (strcmp (timing_function, "ease-out") == 0)
114 progress_type = GTK_TIMELINE_PROGRESS_EASE_OUT;
115 else if (strcmp (timing_function, "ease-in-out") == 0)
116 progress_type = GTK_TIMELINE_PROGRESS_EASE_IN_OUT;
119 g_warning ("Unknown timing function: %s\n", timing_function);
123 return _gtk_animation_description_new ((gdouble) duration, progress_type, loop);
127 _gtk_animation_description_print (GtkAnimationDescription *desc,
132 g_return_if_fail (desc != NULL);
133 g_return_if_fail (str != NULL);
135 duration = desc->duration;
136 if (duration % 1000 == 0)
137 g_string_append_printf (str, "%ds", (int) desc->duration / 1000);
139 g_string_append_printf (str, "%dms", (int) desc->duration);
141 switch (desc->progress_type)
143 case GTK_TIMELINE_PROGRESS_LINEAR:
144 g_string_append (str, " linear");
146 case GTK_TIMELINE_PROGRESS_EASE:
147 g_string_append (str, " ease");
149 case GTK_TIMELINE_PROGRESS_EASE_IN:
150 g_string_append (str, " ease-in");
152 case GTK_TIMELINE_PROGRESS_EASE_OUT:
153 g_string_append (str, " ease-out");
155 case GTK_TIMELINE_PROGRESS_EASE_IN_OUT:
156 g_string_append (str, " ease-in-out");
159 g_assert_not_reached ();
163 g_string_append (str, " loop");
167 _gtk_animation_description_get_type (void)
169 static GType type = 0;
171 if (G_UNLIKELY (!type))
172 type = g_boxed_type_register_static (I_("GtkAnimationDescription"),
173 (GBoxedCopyFunc) _gtk_animation_description_ref,
174 (GBoxedFreeFunc) _gtk_animation_description_unref);