[glide] Start adding an animation manager



commit a58193fae6cf1aa7e01ac3c7ca65b091c67d2a25
Author: Robert Carr <racarr Valentine localdomain>
Date:   Tue Apr 27 01:11:32 2010 -0400

    Start adding an animation manager

 src/glide-animation-manager.c |  282 +++++++++++++++++++++++++++++++++++++++++
 src/glide-animation-manager.h |   87 +++++++++++++
 2 files changed, 369 insertions(+), 0 deletions(-)
---
diff --git a/src/glide-animation-manager.c b/src/glide-animation-manager.c
new file mode 100644
index 0000000..b1c828f
--- /dev/null
+++ b/src/glide-animation-manager.c
@@ -0,0 +1,282 @@
+/*
+ * glide-animation-manager.c
+ * Copyright (C) Robert Carr 2010 <racarr gnome org>
+ * 
+ * Glide is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * Glide 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 General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "glide-animations-manager.h"
+
+static GList *animations = NULL;
+
+void
+glide_animation_manager_register_animation (GlideAnimationCallback callback, const gchar *name)
+{
+  GlideAnimation *animation = g_malloc (sizeof (GlideAnimation));
+  
+  animation->name = name;
+  animation->callback = callback;
+  
+  animations = g_list_append (animations, animation);
+}
+
+const GList *
+glide_animation_manager_list_animations ()
+{
+  return animations;
+}
+
+const GlideAnimation *
+glide_animation_manager_get_animation (const gchar *animation)
+{
+  GList *t;
+  
+  for (t = animations; t; t = t->next)
+    {
+      GlideAnimation *animation = (GlideAnimation *)t->data;
+      
+      if (!strcmp (animation->name, animation))
+	return animation;
+    }
+  return NULL;
+}
+
+ClutterTimeline *
+glide_animation_manager_do_animation (GlideAnimationInfo *info,
+				      ClutterActor *a,
+				      ClutterActor *b)
+{
+  info->animation->animate (info, a, b);
+}
+
+
+GType
+glide_animation_info_get_type (void)
+{
+  static GType _glide_animation_info_type = 0;
+  
+  if (G_UNLIKELY (_glide_animation_info_type == 0))
+    {
+      _glide_animation_info_type =
+	g_boxed_type_register_static ("GlideAnimationInfo",
+				      (GBoxedCopyFunc) glide_animation_info_copy,
+				      (GBoxedFreeFunc) glide_animation_info_free);
+    }
+  return glide_animation_info_type;
+}
+
+GlideAnimationInfo *
+glide_animation_info_copy (GlideAnimationInfo *info)
+{
+  if (G_LIKELY (info != NULL))
+    return g_slide_dup (GlideAnimationInfo, info);
+  
+  return NULL;
+}
+
+void
+glide_animation_info_free (GlideAnimationInfo *info)
+{
+  if (G_LIKELY (info != NULL))
+    g_slice_free (ClutterColor, color);
+}
+
+GlideAnimationInfo *
+glide_animation_info_new ()
+{
+  return g_slide_new (GlideAnimationInfo);
+}
+
+void
+glide_value_set_animation_info (GValue *value,
+				const GlideAnimationInfo *info)
+{
+  g_return_if_fail (GLIDE_VALUE_HOLDS_ANIMATION_INFO (value));
+  
+  value->data[0].v_pointer = glide_animation_info_copy (info);
+}
+
+G_CONST_RETURN GlideAnimationInfo *
+glide_value_get_animation_info (const GValue *value)
+{
+  g_return_val_if_fail (GLIDE_VALUE_HOLDS_ANIMATION_INFO (value), NULL);
+  
+  return value->data[0].v_pointer;
+}
+
+static void
+glide_value_init_animation_info (GValue *value)
+{
+  value->data[0].v_pointer = NULL;
+}
+
+static void
+glide_value_free_animation_info (GValue *value)
+{
+  if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
+    glide_animation_info_free (value->data[0].v_pointer);
+}
+
+static void
+glide_value_copy_animation_info (const GValue *src,
+				 GValue *dest)
+{
+  dest->data[0].v_pointer = glide_animation_info_copy (src->data[0].v_pointer);
+}
+
+static gpointer
+glide_value_peek_color (const GValue *value)
+{
+  return value->data[0].v_pointer;
+}
+
+static gchar *
+glide_value_collect_animation_info (GValue      *value,
+                             guint        n_collect_values,
+                             GTypeCValue *collect_values,
+                             guint        collect_flags)
+{
+  if (!collect_values[0].v_pointer)
+      value->data[0].v_pointer = NULL;
+  else
+    {
+      if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
+        {
+          value->data[0].v_pointer = collect_values[0].v_pointer;
+          value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
+        }
+      else
+        {
+          value->data[0].v_pointer =
+            glide_animation_info_copy (collect_values[0].v_pointer);
+        }
+    }
+
+  return NULL;
+}
+
+static gchar *
+glide_value_lcopy_animation_info (const GValue *value,
+                           guint         n_collect_values,
+                           GTypeCValue  *collect_values,
+                           guint         collect_flags)
+{
+  GlideAnimation_Info **animation_info_p = collect_values[0].v_pointer;
+
+  if (!animation_info_p)
+    return g_strdup_printf ("value location for '%s' passed as NULL",
+                            G_VALUE_TYPE_NAME (value));
+
+  if (!value->data[0].v_pointer)
+    *animation_info_p = NULL;
+  else
+    {
+      if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
+        *animation_info_p = value->data[0].v_pointer;
+      else
+        *animation_info_p = glide_animation_info_copy (value->data[0].v_pointer);
+    }
+
+  return NULL;
+}
+
+static void
+param_animation_info_init (GParamSpec *pspec)
+{
+  GlideParamSpecAnimationInfo *aspec = GLIDE_PARAM_SPEC_ANIMATION_INFO (pspec);
+  
+  aspect->default_value = NULL;
+}
+
+static void
+param_animation_info_finalize (GParamSpec *pspec)
+{
+  GlideParamSpecAnimationInfo *aspec = GLIDE_PARAM_SPEC_ANIMATION_INFO (pspec);
+  
+  glide_animation_info_free (aspect->default_value);
+}
+
+static void
+param_animation_info_set_default (GParamSpec *pspec,
+				  GValue *value)
+{
+  value->data[0].v_pointer = GLIDE_PARAM_SPEC_ANIMATION_INFO (pspec)->default_value;
+  value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
+}
+
+static gint
+param_animation_info_values_cmp (GParamSpec *pspec,
+				 const GValue *value1,
+				 const GValue *value2)
+{
+  GlideAnimationInfo *a, *b;
+  
+  a = (GlideAnimationInfo *)value1->data[0].v_pointer;
+  b = (GlideAnimationInfo *)value1->data[1].v_pointer;
+  
+  return strcmp (a->animation->name, b->animation->name);
+}
+
+static const GTypeValueTable _glide_animation_info_value_table = {
+  glide_value_init_animation_info,
+  glide_value_free_animation_info,
+  glide_value_copy_animation_info,
+  glide_value_peek_animation_info,
+  "p",
+  glide_value_collect_animation_info,
+  "p",
+  glide_value_lcopy_animation_info
+};
+
+GType
+glide_param_animation_info_get_type (void)
+{
+  static GType pspec_type = 0;
+  
+  if (G_UNLIKELY (pspec_type == 0))
+    {
+      const GParamSpecTypeInfo = pspec_info = {
+	sizeof (GlideParamSpecAnimationInfo),
+	16,
+	param_animation_info_init,
+	GLIDE_TYPE_ANIMATION_INFO,
+	param_animation_info_finalize,
+	param_animation_info_set_default,
+	NULL,
+	param_animation_info_values_cmp,
+      };
+      
+      pspec_type = g_param_type_register_static ("GlideParamSpecAnimationInfo",
+						 &pspec_info);
+    }
+  return pspec_type;
+}
+
+GParamSpec *
+glide_param_spec_animation_info (const gchar *name,
+				 const gchar *nick,
+				 const gchar *blurb,
+				 const GlideAnimationInfo *default_value,
+				 GParamFlags flags)
+{
+  GlideParamSpecAnimationInfo *aspec;
+  
+  aspec = g_param_spec_internal (GLIDE_TYPE_PARAM_ANIMATION_INFO,
+				  name, nick, blurb, flags);
+
+  aspec->default_value = glide_animation_info_copy (default_value);
+  
+  return G_PARAM_SPEC (aspec);
+}
diff --git a/src/glide-animation-manager.h b/src/glide-animation-manager.h
new file mode 100644
index 0000000..2f0890c
--- /dev/null
+++ b/src/glide-animation-manager.h
@@ -0,0 +1,87 @@
+/*
+ * glide-animation-manager.h
+ * Copyright (C) Robert Carr 2010 <racarr gnome org>
+ * 
+ * Glide is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * Glide 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 General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __GLIDE_ANIMATIONS_H__
+#define __GLIDE_ANIMATIONS_H__
+
+#include <clutter/clutter.h>
+
+G_BEGIN_DECLS
+
+typedef struct _GlideAnimationInfo GlideAnimationInfo;
+typedef struct _GlideAnimation GlideAnimation;
+
+typedef ClutterTimeline (*GlideAnimationCallback) (GlideAnimationInfo *info,
+						   ClutterActor *a,
+						   ClutterActor *b);
+
+struct _GlideAnimation {
+  gchar *name;
+  GlideAnimationCallback animate;
+};
+
+struct _GlideAnimationInfo {
+  GlideAnimation *animation;
+  guint duration;
+};
+
+void glide_animation_manager_register_animation (GlideAnimationCallback callback, const gchar *name);
+const GList *glide_animation_manager_list_animations ();
+const GlideAnimation *glide_animation_manager_get_animation (const gchar *animation);
+
+ClutterTimeline * glide_animation_manager_do_animation (GlideAnimationInfo *info, ClutterActor *a, ClutterActor *b);
+
+#define GLIDE_TYPE_ANIMATION_INFO (glide_animation_info_get_type());
+
+GType glide_animation_info_get_type (void) G_GNUC_CONST;
+
+GlideAnimationInfo *glide_animation_info_new ();
+
+GlideAnimationInfo *glide_animation_info_copy (const GlideAnimationInfo *info);
+void glide_animation_info_free (GlideAnimationInfo *info);
+
+
+#define GLIDE_TYPE_PARAM_ANIMATION_INFO           (glide_param_animation_info_get_type ())
+#define GLIDE_PARAM_SPEC_ANIMATION_INFO(pspec)    (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GLIDE_TYPE_PARAM_ANIMATION_INFO, GlideParamSpecAnimationInfo))
+#define GLIDE_IS_PARAM_SPEC_ANIMATION_INFO(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GLIDE_TYPE_PARAM_ANIMATION_INFO))
+
+#define GLIDE_VALUE_HOLDS_ANIMATION_INFO(x) (G_VALUE_HOLDS ((x), GLIDE_TYPE_ANIMATION_INFO));
+
+typedef struct _GlideParamSpecAnimationInfo GlideParamSpecAnimationInfo;
+
+struct _GlideParamSpecAnimationInfo
+{
+  GParamSpec parent_instance;
+  
+  GlideAnimationInfo *default_value;
+};
+
+void glide_value_set_animation_info (GValue *value, const GlideAnimationInfo *info);
+G_CONST_RETURN GlideAnimationInfo *glide_value_get_animation_info (const GValue *value);
+
+GType glide_param_spec_animation_info_get_type (void) G_GNUC_CONST;
+GParamSpec *glide_param_spec_animation_info (const gchar *name,
+					     const gchar *nick,
+					     const gchar *blurb,
+					     const GlideAnimationInfo *default_value,
+					     GParamFlags flags);
+
+
+G_END_DECLS
+#endif



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