[gtk+/gtk-style-context: 191/206] Add GtkAnimationDescription as a private boxed object.



commit 52c370062f7304e4f3b482f0a64a7349da9aa761
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Aug 19 21:45:30 2010 +0200

    Add GtkAnimationDescription as a private boxed object.
    
    This struct will be used to represent an animation in GtkStyleSet. It
    will only be used internally in GtkStyleContext in order to trigger
    animations, engines shouldn't need this.

 gtk/Makefile.am               |    2 +
 gtk/gtkanimationdescription.c |  123 +++++++++++++++++++++++++++++++++++++++++
 gtk/gtkanimationdescription.h |   47 ++++++++++++++++
 3 files changed, 172 insertions(+), 0 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 806a31c..ce66c32 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -365,6 +365,7 @@ gtk_private_h_sources =		\
 	gtksearchenginesimple.h	\
 	gtkdndcursors.h		\
 	gtkentryprivate.h	\
+	gtkanimationdescription.h \
 	gtkbuilderprivate.h 	\
 	gtkcustompaperunixdialog.h\
 	gtkfilechooserdefault.h	\
@@ -424,6 +425,7 @@ gtk_base_c_sources =            \
 	gtkadjustment.c		\
 	gtkalignment.c		\
 	gtkapplication.c \
+	gtkanimationdescription.c \
 	gtkarrow.c		\
 	gtkaspectframe.c	\
 	gtkassistant.c		\
diff --git a/gtk/gtkanimationdescription.c b/gtk/gtkanimationdescription.c
new file mode 100644
index 0000000..a0cc3be
--- /dev/null
+++ b/gtk/gtkanimationdescription.c
@@ -0,0 +1,123 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2010 Carlos Garnacho <carlosg gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include "gtkanimationdescription.h"
+#include "gtkintl.h"
+
+struct GtkAnimationDescription
+{
+  GtkTimelineProgressType progress_type;
+  gdouble duration;
+
+  guint ref_count;
+};
+
+GtkAnimationDescription *
+gtk_animation_description_new (gdouble                 duration,
+                               GtkTimelineProgressType progress_type)
+{
+  GtkAnimationDescription *desc;
+
+  desc = g_slice_new (GtkAnimationDescription);
+  desc->duration = duration;
+  desc->progress_type = progress_type;
+  desc->ref_count = 1;
+
+  return desc;
+}
+
+gdouble
+gtk_animation_description_get_duration (GtkAnimationDescription *desc)
+{
+  return desc->duration;
+}
+
+GtkTimelineProgressType
+gtk_animation_description_get_progress_type (GtkAnimationDescription *desc)
+{
+  return desc->progress_type;
+}
+
+GtkAnimationDescription *
+gtk_animation_description_ref (GtkAnimationDescription *desc)
+{
+  desc->ref_count++;
+  return desc;
+}
+
+void
+gtk_animation_description_unref (GtkAnimationDescription *desc)
+{
+  desc->ref_count--;
+
+  if (desc->ref_count == 0)
+    g_slice_free (GtkAnimationDescription, desc);
+}
+
+GtkAnimationDescription *
+gtk_animation_description_from_string (const gchar *str)
+{
+  gchar timing_function[16] = { 0, };
+  gchar duration_measurement[3] = { 0, };
+  GtkTimelineProgressType progress_type;
+  guint duration = 0;
+
+  if (sscanf (str, "%d%2s %15s", &duration, duration_measurement, timing_function) != 3)
+    return NULL;
+
+  if (strcmp (duration_measurement, "s") == 0)
+    duration *= 1000;
+  else if (strcmp (duration_measurement, "ms") != 0)
+    {
+      g_warning ("Unknown duration measurement: %s\n", duration_measurement);
+      return NULL;
+    }
+
+  if (strcmp (timing_function, "linear") == 0)
+    progress_type = GTK_TIMELINE_PROGRESS_LINEAR;
+  else if (strcmp (timing_function, "ease") == 0)
+    progress_type = GTK_TIMELINE_PROGRESS_EASE;
+  else if (strcmp (timing_function, "ease-in") == 0)
+    progress_type = GTK_TIMELINE_PROGRESS_EASE_IN;
+  else if (strcmp (timing_function, "ease-out") == 0)
+    progress_type = GTK_TIMELINE_PROGRESS_EASE_OUT;
+  else if (strcmp (timing_function, "ease-in-out") == 0)
+    progress_type = GTK_TIMELINE_PROGRESS_EASE_IN_OUT;
+  else
+    {
+      g_warning ("Unknown timing function: %s\n", timing_function);
+      return NULL;
+    }
+
+  return gtk_animation_description_new ((gdouble) duration, progress_type);
+}
+
+GType
+gtk_animation_description_get_type (void)
+{
+  static GType type = 0;
+
+  if (G_UNLIKELY (!type))
+    type = g_boxed_type_register_static (I_("GtkAnimationDescription"),
+					 (GBoxedCopyFunc) gtk_animation_description_ref,
+					 (GBoxedFreeFunc) gtk_animation_description_unref);
+
+  return type;
+}
diff --git a/gtk/gtkanimationdescription.h b/gtk/gtkanimationdescription.h
new file mode 100644
index 0000000..14537ed
--- /dev/null
+++ b/gtk/gtkanimationdescription.h
@@ -0,0 +1,47 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2010 Carlos Garnacho <carlosg gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTK_ANIMATION_DESCRIPTION_H__
+#define __GTK_ANIMATION_DESCRIPTION_H__
+
+#include "gtktimeline.h"
+
+G_BEGIN_DECLS
+
+/* Dummy typedefs */
+typedef struct GtkAnimationDescription GtkAnimationDescription;
+
+#define GTK_TYPE_ANIMATION_DESCRIPTION (gtk_animation_description_get_type ())
+
+GType gtk_animation_description_get_type (void) G_GNUC_CONST;
+
+GtkAnimationDescription * gtk_animation_description_new (gdouble                 duration,
+                                                         GtkTimelineProgressType progress_type);
+
+gdouble                   gtk_animation_description_get_duration      (GtkAnimationDescription *desc);
+GtkTimelineProgressType   gtk_animation_description_get_progress_type (GtkAnimationDescription *desc);
+
+GtkAnimationDescription * gtk_animation_description_ref   (GtkAnimationDescription *desc);
+void                      gtk_animation_description_unref (GtkAnimationDescription *desc);
+
+GtkAnimationDescription * gtk_animation_description_from_string (const gchar *str);
+
+G_END_DECLS
+
+#endif /* __GTK_ANIMATION_DESC_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]