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_get_type (void)
129 static GType type = 0;
131 if (G_UNLIKELY (!type))
132 type = g_boxed_type_register_static (I_("GtkAnimationDescription"),
133 (GBoxedCopyFunc) _gtk_animation_description_ref,
134 (GBoxedFreeFunc) _gtk_animation_description_unref);