[gedit/animation: 3/3] Add useful classes for future animations.



commit 81e728dec5bd0271abcb01b833838cef26bd7f2d
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sun Sep 5 15:29:20 2010 +0200

    Add useful classes for future animations.

 .../theatrics/gedit-theatrics-animation-drawable.c |  104 ++++++
 .../theatrics/gedit-theatrics-animation-drawable.h |   68 ++++
 gedit/theatrics/gedit-theatrics-animation.c        |  328 +++++++++++++++++
 gedit/theatrics/gedit-theatrics-animation.h        |   98 +++++
 .../gedit-theatrics-highlight-search-animation.c   |  376 ++++++++++++++++++++
 .../gedit-theatrics-highlight-search-animation.h   |   67 ++++
 6 files changed, 1041 insertions(+), 0 deletions(-)
---
diff --git a/gedit/theatrics/gedit-theatrics-animation-drawable.c b/gedit/theatrics/gedit-theatrics-animation-drawable.c
new file mode 100644
index 0000000..af796f7
--- /dev/null
+++ b/gedit/theatrics/gedit-theatrics-animation-drawable.c
@@ -0,0 +1,104 @@
+/*
+ * gedit-theatrics-animation-drawable.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Ignacio Casal Quinteiro
+ *
+ * Based on Mike Krüger <mkrueger novell com> work.
+ *
+ * gedit 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#include "gedit-theatrics-animation-drawable.h"
+
+G_DEFINE_INTERFACE (GeditTheatricsAnimationDrawable, gedit_theatrics_animation_drawable, G_TYPE_OBJECT)
+
+/* Default implementation */
+static GdkRectangle
+gedit_theatrics_animation_drawable_get_animation_bounds_default (GeditTheatricsAnimationDrawable *ad)
+{
+	GdkRectangle r = {0, };
+
+	g_return_val_if_reached (r);
+}
+
+static gdouble
+gedit_theatrics_animation_drawable_get_percent_default (GeditTheatricsAnimationDrawable *ad)
+{
+	g_return_val_if_reached (0.0);
+}
+
+static void
+gedit_theatrics_animation_drawable_set_percent_default (GeditTheatricsAnimationDrawable *ad,
+							gdouble                          percent)
+{
+	g_return_if_reached ();
+}
+
+static void
+gedit_theatrics_animation_drawable_draw_default (GeditTheatricsAnimationDrawable *ad,
+						 GdkDrawable                     *drawable)
+{
+	g_return_if_reached ();
+}
+
+static void 
+gedit_theatrics_animation_drawable_default_init (GeditTheatricsAnimationDrawableInterface *iface)
+{
+	static gboolean initialized = FALSE;
+
+	iface->get_animation_bounds = gedit_theatrics_animation_drawable_get_animation_bounds_default;
+	iface->get_percent = gedit_theatrics_animation_drawable_get_percent_default;
+	iface->set_percent = gedit_theatrics_animation_drawable_set_percent_default;
+	iface->draw = gedit_theatrics_animation_drawable_draw_default;
+
+	if (!initialized)
+	{
+		initialized = TRUE;
+	}
+}
+
+GdkRectangle
+gedit_theatrics_animation_drawable_get_animation_bounds (GeditTheatricsAnimationDrawable *ad)
+{
+	GdkRectangle r = {0, };
+
+	g_return_val_if_fail (GEDIT_THEATRICS_ANIMATION_DRAWABLE (ad), r);
+	return GEDIT_THEATRICS_ANIMATION_DRAWABLE_GET_INTERFACE (ad)->get_animation_bounds (ad);
+}
+
+gdouble
+gedit_theatrics_animation_drawable_get_percent (GeditTheatricsAnimationDrawable *ad)
+{
+	g_return_val_if_fail (GEDIT_THEATRICS_ANIMATION_DRAWABLE (ad), 0.0);
+	return GEDIT_THEATRICS_ANIMATION_DRAWABLE_GET_INTERFACE (ad)->get_percent (ad);
+}
+
+void
+gedit_theatrics_animation_drawable_set_percent (GeditTheatricsAnimationDrawable *ad,
+						gdouble                          percent)
+{
+	g_return_if_fail (GEDIT_THEATRICS_ANIMATION_DRAWABLE (ad));
+	GEDIT_THEATRICS_ANIMATION_DRAWABLE_GET_INTERFACE (ad)->set_percent (ad, percent);
+}
+
+void
+gedit_theatrics_animation_drawable_draw (GeditTheatricsAnimationDrawable *ad,
+					 GdkDrawable                     *drawable)
+{
+	g_return_if_fail (GEDIT_THEATRICS_ANIMATION_DRAWABLE (ad));
+	GEDIT_THEATRICS_ANIMATION_DRAWABLE_GET_INTERFACE (ad)->draw (ad, drawable);
+}
diff --git a/gedit/theatrics/gedit-theatrics-animation-drawable.h b/gedit/theatrics/gedit-theatrics-animation-drawable.h
new file mode 100644
index 0000000..653e9cb
--- /dev/null
+++ b/gedit/theatrics/gedit-theatrics-animation-drawable.h
@@ -0,0 +1,68 @@
+/*
+ * gedit-theatrics-animation-drawable.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Ignacio Casal Quinteiro
+ *
+ * Based on Mike Krüger <mkrueger novell com> work.
+ *
+ * gedit 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifndef __GEDIT_THEATRICS_ANIMATION_DRAWABLE_H__
+#define __GEDIT_THEATRICS_ANIMATION_DRAWABLE_H__
+
+#include <glib-object.h>
+#include <gdk/gdk.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_THEATRICS_ANIMATION_DRAWABLE			(gedit_theatrics_animation_drawable_get_type ())
+#define GEDIT_THEATRICS_ANIMATION_DRAWABLE(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_THEATRICS_ANIMATION_DRAWABLE, GeditTheatricsAnimationDrawable))
+#define GEDIT_IS_THEATRICS_ANIMATION_DRAWABLE(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_THEATRICS_ANIMATION_DRAWABLE))
+#define GEDIT_THEATRICS_ANIMATION_DRAWABLE_GET_INTERFACE(obj)	(G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEDIT_TYPE_THEATRICS_ANIMATION_DRAWABLE, GeditTheatricsAnimationDrawableInterface))
+
+typedef struct _GeditTheatricsAnimationDrawable			GeditTheatricsAnimationDrawable;
+typedef struct _GeditTheatricsAnimationDrawableInterface	GeditTheatricsAnimationDrawableInterface;
+
+struct _GeditTheatricsAnimationDrawableInterface
+{
+	GTypeInterface parent;
+
+	GdkRectangle (* get_animation_bounds) (GeditTheatricsAnimationDrawable *ad);
+
+	gdouble (* get_percent) (GeditTheatricsAnimationDrawable *ad);
+	void (* set_percent) (GeditTheatricsAnimationDrawable *ad,
+			      gdouble                          percent);
+
+	void (* draw) (GeditTheatricsAnimationDrawable *ad,
+	               GdkDrawable                     *drawable);
+};
+
+GType gedit_theatrics_animation_drawable_get_type (void) G_GNUC_CONST;
+
+GdkRectangle gedit_theatrics_animation_drawable_get_animation_bounds (GeditTheatricsAnimationDrawable *ad);
+
+gdouble gedit_theatrics_animation_drawable_get_percent (GeditTheatricsAnimationDrawable *ad);
+void gedit_theatrics_animation_drawable_set_percent (GeditTheatricsAnimationDrawable *ad,
+						     gdouble                          percent);
+
+void gedit_theatrics_animation_drawable_draw (GeditTheatricsAnimationDrawable *ad,
+					      GdkDrawable                     *drawable);
+
+G_END_DECLS
+
+#endif /* __GEDIT_THEATRICS_ANIMATION_DRAWABLE_H__ */
diff --git a/gedit/theatrics/gedit-theatrics-animation.c b/gedit/theatrics/gedit-theatrics-animation.c
new file mode 100644
index 0000000..e95febc
--- /dev/null
+++ b/gedit/theatrics/gedit-theatrics-animation.c
@@ -0,0 +1,328 @@
+/*
+ * gedit-theatrics-animation.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Ignacio Casal Quinteiro
+ *
+ * Based on Mike Krüger <mkrueger novell com> work.
+ *
+ * gedit 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301  USA
+ */
+
+#include "gedit-theatrics-animation.h"
+#include "gedit-theatrics-enum-types.h"
+
+
+#define GEDIT_THEATRICS_ANIMATION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_THEATRICS_ANIMATION, GeditTheatricsAnimationPrivate))
+
+struct _GeditTheatricsAnimationPrivate
+{
+	GeditTheatricsAnimationDrawable *drawable;
+	GeditTheatricsChoreographerEasing easing;
+	GeditTheatricsChoreographerBlocking blocking;
+	GeditTheatricsAnimationState animation_state;
+	guint duration;
+};
+
+enum
+{
+	PROP_0,
+	PROP_DRAWABLE,
+	PROP_EASING,
+	PROP_BLOCKING,
+	PROP_ANIMATION_STATE,
+	PROP_DURATION
+};
+
+G_DEFINE_TYPE (GeditTheatricsAnimation, gedit_theatrics_animation, G_TYPE_OBJECT)
+
+static void
+gedit_theatrics_animation_finalize (GObject *object)
+{
+	G_OBJECT_CLASS (gedit_theatrics_animation_parent_class)->finalize (object);
+}
+
+static void
+gedit_theatrics_animation_get_property (GObject    *object,
+					guint       prop_id,
+					GValue     *value,
+					GParamSpec *pspec)
+{
+	GeditTheatricsAnimation *anim = GEDIT_THEATRICS_ANIMATION (object);
+
+	switch (prop_id)
+	{
+		case PROP_DRAWABLE:
+			g_value_set_object (value, anim->priv->drawable);
+			break;
+		case PROP_EASING:
+			g_value_set_enum (value, anim->priv->easing);
+			break;
+		case PROP_BLOCKING:
+			g_value_set_enum (value, anim->priv->blocking);
+			break;
+		case PROP_ANIMATION_STATE:
+			g_value_set_enum (value, anim->priv->animation_state);
+			break;
+		case PROP_DURATION:
+			g_value_set_uint (value, anim->priv->duration);
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+			break;
+	}
+}
+
+static void
+gedit_theatrics_animation_set_property (GObject      *object,
+					guint         prop_id,
+					const GValue *value,
+					GParamSpec   *pspec)
+{
+	GeditTheatricsAnimation *anim = GEDIT_THEATRICS_ANIMATION (object);
+
+	switch (prop_id)
+	{
+		case PROP_DRAWABLE:
+		{
+			GeditTheatricsAnimationDrawable *ad;
+
+			ad = g_value_get_object (value);
+
+			if (ad != NULL)
+			{
+				gedit_theatrics_animation_set_drawable (anim, ad);
+			}
+
+			break;
+		}
+		case PROP_EASING:
+			gedit_theatrics_animation_set_easing (anim,
+			                                      g_value_get_enum (value));
+			break;
+		case PROP_BLOCKING:
+			gedit_theatrics_animation_set_blocking (anim,
+			                                        g_value_get_enum (value));
+			break;
+		case PROP_ANIMATION_STATE:
+			gedit_theatrics_animation_set_easing (anim,
+			                                      g_value_get_enum (value));
+			break;
+		case PROP_DURATION:
+			gedit_theatrics_animation_set_duration (anim,
+			                                        g_value_get_uint (value));
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+			break;
+	}
+}
+
+static void
+gedit_theatrics_animation_class_init (GeditTheatricsAnimationClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	object_class->finalize = gedit_theatrics_animation_finalize;
+	object_class->get_property = gedit_theatrics_animation_get_property;
+	object_class->set_property = gedit_theatrics_animation_set_property;
+
+	g_object_class_install_property (object_class, PROP_DRAWABLE,
+	                                 g_param_spec_object ("drawable",
+	                                                      "Drawable",
+	                                                      "The Drawable",
+	                                                      GEDIT_TYPE_THEATRICS_ANIMATION_DRAWABLE,
+	                                                      G_PARAM_READWRITE |
+	                                                      G_PARAM_CONSTRUCT |
+	                                                      G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (object_class, PROP_EASING,
+	                                 g_param_spec_enum ("easing",
+	                                                    "Easing",
+	                                                    "The Easing",
+	                                                    GEDIT_TYPE_THEATRICS_CHOREOGRAPHER_EASING,
+	                                                    GEDIT_THEATRICS_CHOREOGRAPHER_EASING_LINEAR,
+	                                                    G_PARAM_READWRITE |
+	                                                    G_PARAM_CONSTRUCT |
+	                                                    G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (object_class, PROP_BLOCKING,
+	                                 g_param_spec_enum ("blocking",
+	                                                    "Blocking",
+	                                                    "The Blocking",
+	                                                    GEDIT_TYPE_THEATRICS_CHOREOGRAPHER_BLOCKING,
+	                                                    GEDIT_THEATRICS_CHOREOGRAPHER_BLOCKING_DOWNSTAGE,
+	                                                    G_PARAM_READWRITE |
+	                                                    G_PARAM_CONSTRUCT |
+	                                                    G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (object_class, PROP_ANIMATION_STATE,
+	                                 g_param_spec_enum ("animation-state",
+	                                                    "Animation State",
+	                                                    "The Animation State",
+	                                                    GEDIT_TYPE_THEATRICS_ANIMATION_STATE,
+	                                                    GEDIT_THEATRICS_ANIMATION_STATE_COMING,
+	                                                    G_PARAM_READWRITE |
+	                                                    G_PARAM_CONSTRUCT |
+	                                                    G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (object_class, PROP_DURATION,
+	                                 g_param_spec_uint ("duration",
+	                                                    "Duration",
+	                                                    "The duration",
+	                                                    0,
+	                                                    G_MAXUINT,
+	                                                    0,
+	                                                    G_PARAM_READWRITE |
+	                                                    G_PARAM_CONSTRUCT |
+	                                                    G_PARAM_STATIC_STRINGS));
+
+	g_type_class_add_private (object_class, sizeof (GeditTheatricsAnimationPrivate));
+}
+
+static void
+gedit_theatrics_animation_init (GeditTheatricsAnimation *anim)
+{
+	anim->priv = GEDIT_THEATRICS_ANIMATION_GET_PRIVATE (anim);
+
+	anim->priv->animation_state = GEDIT_THEATRICS_ANIMATION_STATE_COMING;
+}
+
+GeditTheatricsAnimation *
+gedit_theatrics_animation_new (GeditTheatricsAnimationDrawable    *drawable,
+			       guint                               duration,
+			       GeditTheatricsChoreographerEasing   easing,
+			       GeditTheatricsChoreographerBlocking blocking)
+{
+	return g_object_new (GEDIT_TYPE_THEATRICS_ANIMATION,
+			     "drawable", drawable,
+			     "duration", duration,
+			     "easing", easing,
+			     "blocking", blocking,
+			     NULL);
+}
+
+GeditTheatricsAnimationDrawable *
+gedit_theatrics_animation_get_drawable (GeditTheatricsAnimation *anim)
+{
+	g_return_val_if_fail (GEDIT_IS_THEATRICS_ANIMATION (anim), NULL);
+
+	return anim->priv->drawable;
+}
+
+void
+gedit_theatrics_animation_set_drawable (GeditTheatricsAnimation         *anim,
+					GeditTheatricsAnimationDrawable *drawable)
+{
+	g_return_if_fail (GEDIT_IS_THEATRICS_ANIMATION (anim));
+
+	if (drawable != anim->priv->drawable)
+	{
+		anim->priv->drawable = drawable;
+
+		g_object_notify (G_OBJECT (anim), "drawable");
+	}
+}
+
+GeditTheatricsChoreographerEasing
+gedit_theatrics_animation_get_easing (GeditTheatricsAnimation *anim)
+{
+	g_return_val_if_fail (GEDIT_IS_THEATRICS_ANIMATION (anim), GEDIT_THEATRICS_CHOREOGRAPHER_EASING_LINEAR);
+
+	return anim->priv->easing;
+}
+
+void
+gedit_theatrics_animation_set_easing (GeditTheatricsAnimation          *anim,
+				      GeditTheatricsChoreographerEasing easing)
+{
+	g_return_if_fail (GEDIT_IS_THEATRICS_ANIMATION (anim));
+
+	if (anim->priv->easing != easing)
+	{
+		anim->priv->easing = easing;
+
+		g_object_notify (G_OBJECT (anim), "easing");
+	}
+}
+
+GeditTheatricsChoreographerBlocking
+gedit_theatrics_animation_get_blocking (GeditTheatricsAnimation *anim)
+{
+	g_return_val_if_fail (GEDIT_IS_THEATRICS_ANIMATION (anim), GEDIT_THEATRICS_CHOREOGRAPHER_BLOCKING_DOWNSTAGE);
+
+	return anim->priv->blocking;
+}
+
+void
+gedit_theatrics_animation_set_blocking (GeditTheatricsAnimation            *anim,
+					GeditTheatricsChoreographerBlocking blocking)
+{
+	g_return_if_fail (GEDIT_IS_THEATRICS_ANIMATION (anim));
+
+	if (anim->priv->blocking != blocking)
+	{
+		anim->priv->blocking = blocking;
+
+		g_object_notify (G_OBJECT (anim), "blocking");
+	}
+}
+
+GeditTheatricsAnimationState
+gedit_theatrics_animation_get_animation_state (GeditTheatricsAnimation *anim)
+{
+	g_return_val_if_fail (GEDIT_IS_THEATRICS_ANIMATION (anim), GEDIT_THEATRICS_ANIMATION_STATE_COMING);
+
+	return anim->priv->animation_state;
+}
+
+void
+gedit_theatrics_animation_set_animation_state (GeditTheatricsAnimation     *anim,
+					       GeditTheatricsAnimationState animation_state)
+{
+	g_return_if_fail (GEDIT_IS_THEATRICS_ANIMATION (anim));
+
+	if (anim->priv->animation_state != animation_state)
+	{
+		anim->priv->animation_state = animation_state;
+
+		g_object_notify (G_OBJECT (anim), "animation-state");
+	}
+}
+
+gdouble
+gedit_theatrics_animation_get_duration (GeditTheatricsAnimation *anim)
+{
+	g_return_val_if_fail (GEDIT_IS_THEATRICS_ANIMATION (anim), 0.0);
+
+	return anim->priv->duration;
+}
+
+void
+gedit_theatrics_animation_set_duration (GeditTheatricsAnimation *anim,
+					gdouble                  duration)
+{
+	g_return_if_fail (GEDIT_IS_THEATRICS_ANIMATION (anim));
+
+	if (anim->priv->duration != duration)
+	{
+		anim->priv->duration = duration;
+
+		g_object_notify (G_OBJECT (anim), "duration");
+	}
+}
+
+/* ex:ts=8:noet: */
diff --git a/gedit/theatrics/gedit-theatrics-animation.h b/gedit/theatrics/gedit-theatrics-animation.h
new file mode 100644
index 0000000..60881f5
--- /dev/null
+++ b/gedit/theatrics/gedit-theatrics-animation.h
@@ -0,0 +1,98 @@
+/*
+ * gedit-theatrics-animation.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Ignacio Casal Quinteiro
+ *
+ * Based on Mike Krüger <mkrueger novell com> work.
+ *
+ * gedit 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifndef __GEDIT_THEATRICS_ANIMATION_H__
+#define __GEDIT_THEATRICS_ANIMATION_H__
+
+#include <glib-object.h>
+#include "gedit-theatrics-animation-drawable.h"
+#include "gedit-theatrics-choreographer.h"
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_THEATRICS_ANIMATION			(gedit_theatrics_animation_get_type ())
+#define GEDIT_THEATRICS_ANIMATION(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_THEATRICS_ANIMATION, GeditTheatricsAnimation))
+#define GEDIT_THEATRICS_ANIMATION_CONST(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_THEATRICS_ANIMATION, GeditTheatricsAnimation const))
+#define GEDIT_THEATRICS_ANIMATION_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_THEATRICS_ANIMATION, GeditTheatricsAnimationClass))
+#define GEDIT_IS_THEATRICS_ANIMATION(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_THEATRICS_ANIMATION))
+#define GEDIT_IS_THEATRICS_ANIMATION_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_THEATRICS_ANIMATION))
+#define GEDIT_THEATRICS_ANIMATION_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_THEATRICS_ANIMATION, GeditTheatricsAnimationClass))
+
+typedef struct _GeditTheatricsAnimation		GeditTheatricsAnimation;
+typedef struct _GeditTheatricsAnimationClass	GeditTheatricsAnimationClass;
+typedef struct _GeditTheatricsAnimationPrivate	GeditTheatricsAnimationPrivate;
+
+struct _GeditTheatricsAnimation
+{
+	GObject parent;
+
+	GeditTheatricsAnimationPrivate *priv;
+};
+
+struct _GeditTheatricsAnimationClass
+{
+	GObjectClass parent_class;
+};
+
+GType			 gedit_theatrics_animation_get_type		(void) G_GNUC_CONST;
+
+GeditTheatricsAnimation *gedit_theatrics_animation_new			(GeditTheatricsAnimationDrawable    *drawable,
+									 guint                               duration,
+									 GeditTheatricsChoreographerEasing   easing,
+									 GeditTheatricsChoreographerBlocking blocking);
+
+GeditTheatricsAnimationDrawable *
+			gedit_theatrics_animation_get_drawable		(GeditTheatricsAnimation *anim);
+
+void			gedit_theatrics_animation_set_drawable		(GeditTheatricsAnimation         *anim,
+									 GeditTheatricsAnimationDrawable *drawable);
+
+GeditTheatricsChoreographerEasing
+			gedit_theatrics_animation_get_easing		(GeditTheatricsAnimation *anim);
+
+void			gedit_theatrics_animation_set_easing		(GeditTheatricsAnimation          *anim,
+									 GeditTheatricsChoreographerEasing easing);
+
+GeditTheatricsChoreographerBlocking
+			gedit_theatrics_animation_get_blocking		(GeditTheatricsAnimation *anim);
+
+void			gedit_theatrics_animation_set_blocking		(GeditTheatricsAnimation            *anim,
+									 GeditTheatricsChoreographerBlocking blocking);
+
+GeditTheatricsAnimationState
+			gedit_theatrics_animation_get_animation_state	(GeditTheatricsAnimation *anim);
+
+void			gedit_theatrics_animation_set_animation_state	(GeditTheatricsAnimation     *anim,
+									 GeditTheatricsAnimationState animation_state);
+
+gdouble			gedit_theatrics_animation_get_duration		(GeditTheatricsAnimation *anim);
+
+void			gedit_theatrics_animation_set_duration		(GeditTheatricsAnimation *anim,
+									 gdouble                  duration);
+
+G_END_DECLS
+
+#endif /* __GEDIT_THEATRICS_ANIMATION_H__ */
+
+/* ex:ts=8:noet: */
diff --git a/gedit/theatrics/gedit-theatrics-highlight-search-animation.c b/gedit/theatrics/gedit-theatrics-highlight-search-animation.c
new file mode 100644
index 0000000..91d81ca
--- /dev/null
+++ b/gedit/theatrics/gedit-theatrics-highlight-search-animation.c
@@ -0,0 +1,376 @@
+/*
+ * gedit-theatrics-highlight-search-animation.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Ignacio Casal Quinteiro
+ *
+ * Based on Mike Krüger <mkrueger novell com> work.
+ *
+ * gedit 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#include "gedit-theatrics-utils.h"
+#include "gedit-theatrics-highlight-search-animation.h"
+#include <gtk/gtk.h>
+#include <gdk/gdk.h>
+#include <gtksourceview/gtksourcebuffer.h>
+#include <math.h>
+
+
+#define GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION, GeditTheatricsHighlightSearchAnimationPrivate))
+
+struct _GeditTheatricsHighlightSearchAnimationPrivate
+{
+	GtkSourceView *view;
+	GtkTextIter start;
+	GtkTextIter end;
+	gdouble percent;
+
+	cairo_surface_t *surface;
+};
+
+enum
+{
+	PROP_0,
+	PROP_VIEW
+};
+
+static void gedit_theatrics_animation_drawable_iface_init (GeditTheatricsAnimationDrawableInterface *iface);
+
+G_DEFINE_TYPE_EXTENDED (GeditTheatricsHighlightSearchAnimation,
+			gedit_theatrics_highlight_search_animation,
+			G_TYPE_OBJECT,
+			0,
+			G_IMPLEMENT_INTERFACE (GEDIT_TYPE_THEATRICS_ANIMATION_DRAWABLE,
+					       gedit_theatrics_animation_drawable_iface_init))
+
+static void
+gedit_theatrics_highlight_search_animation_dispose (GObject *object)
+{
+	GeditTheatricsHighlightSearchAnimation *rpa = GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION (object);
+
+	if (rpa->priv->surface != NULL)
+	{
+		cairo_surface_finish (rpa->priv->surface);
+		cairo_surface_destroy (rpa->priv->surface);
+
+		rpa->priv->surface = NULL;
+	}
+
+	G_OBJECT_CLASS (gedit_theatrics_highlight_search_animation_parent_class)->dispose (object);
+}
+
+static void
+gedit_theatrics_highlight_search_animation_get_property (GObject    *object,
+							 guint       prop_id,
+							 GValue     *value,
+							 GParamSpec *pspec)
+{
+	GeditTheatricsHighlightSearchAnimation *rpa = GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION (object);
+
+	switch (prop_id)
+	{
+		case PROP_VIEW:
+			g_value_set_object (value, rpa->priv->view);
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+			break;
+	}
+}
+
+static void
+gedit_theatrics_highlight_search_animation_set_property (GObject      *object,
+							 guint         prop_id,
+							 const GValue *value,
+							 GParamSpec   *pspec)
+{
+	GeditTheatricsHighlightSearchAnimation *rpa = GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION (object);
+
+	switch (prop_id)
+	{
+		case PROP_VIEW:
+		{
+			GtkSourceView *view;
+
+			view = g_value_get_object (value);
+
+			if (view != NULL)
+			{
+				rpa->priv->view = view;
+			}
+
+			break;
+		}
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+			break;
+	}
+}
+
+static void
+gedit_theatrics_highlight_search_animation_class_init (GeditTheatricsHighlightSearchAnimationClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	
+	object_class->finalize = gedit_theatrics_highlight_search_animation_dispose;
+	object_class->get_property = gedit_theatrics_highlight_search_animation_get_property;
+	object_class->set_property = gedit_theatrics_highlight_search_animation_set_property;
+
+	g_object_class_install_property (object_class, PROP_VIEW,
+	                                 g_param_spec_object ("view",
+	                                                      "View",
+	                                                      "The Source View",
+	                                                      GTK_TYPE_SOURCE_VIEW,
+	                                                      G_PARAM_READWRITE |
+	                                                      G_PARAM_CONSTRUCT_ONLY |
+	                                                      G_PARAM_STATIC_STRINGS));
+
+	g_type_class_add_private (object_class, sizeof (GeditTheatricsHighlightSearchAnimationPrivate));
+}
+
+static void
+gedit_theatrics_highlight_search_animation_init (GeditTheatricsHighlightSearchAnimation *rpa)
+{
+	rpa->priv = GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION_GET_PRIVATE (rpa);
+}
+
+static GdkRectangle
+gedit_theatrics_highlight_search_animation_get_animation_bounds (GeditTheatricsAnimationDrawable *ad)
+{
+	/*GeditTheatricsHighlightSearchAnimation *rpa = GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION (ad); */
+	GdkRectangle bounds = {0, }; /* FIXME */
+
+	return bounds;
+}
+
+static gdouble
+gedit_theatrics_highlight_search_animation_get_percent (GeditTheatricsAnimationDrawable *ad)
+{
+	GeditTheatricsHighlightSearchAnimation *rpa = GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION (ad);
+
+	return rpa->priv->percent;
+}
+
+static void
+gedit_theatrics_highlight_search_animation_set_percent (GeditTheatricsAnimationDrawable *ad,
+						    gdouble                          percent)
+{
+	GeditTheatricsHighlightSearchAnimation *rpa = GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION (ad);
+
+	rpa->priv->percent = percent;
+}
+
+static void
+get_search_match_colors (GtkSourceBuffer *buffer,
+			 gboolean        *foreground_set,
+			 GdkColor        *foreground,
+			 gboolean        *background_set,
+			 GdkColor        *background)
+{
+	GtkSourceStyleScheme *style_scheme;
+	GtkSourceStyle *style;
+	gchar *fg, *bg;
+
+	style_scheme = gtk_source_buffer_get_style_scheme (buffer);
+	if (style_scheme == NULL)
+		goto fallback;
+
+	style = gtk_source_style_scheme_get_style (style_scheme,
+						   "search-match");
+	if (style == NULL)
+		goto fallback;
+
+	g_object_get (style,
+		      "foreground-set", foreground_set,
+		      "foreground", &fg,
+		      "background-set", background_set,
+		      "background", &bg,
+		      NULL);
+
+	if (*foreground_set)
+	{
+		if (fg == NULL ||
+		    !gdk_color_parse (fg, foreground))
+		{
+			*foreground_set = FALSE;
+		}
+	}
+
+	g_free (fg);
+
+	if (*background_set)
+	{
+		if (bg == NULL ||
+		    !gdk_color_parse (bg, background))
+		{
+			*background_set = FALSE;
+		}
+	}
+
+	g_free (bg);
+
+	return;
+
+fallback:
+	g_warning ("Falling back to hard-coded colors "
+		   "for the \"found\" text tag.");
+
+	gdk_color_parse ("#FFFF78", background);
+	*background_set = TRUE;
+
+	return;
+}
+
+static void
+gedit_theatrics_highlight_search_animation_draw (GeditTheatricsAnimationDrawable *ad,
+						 GdkDrawable                     *drawable)
+{
+	GeditTheatricsHighlightSearchAnimation *rpa = GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION (ad);
+	GdkRectangle pos_start, pos_end;
+	gint iw, ih;
+	gdouble scale;
+	cairo_t *cr;
+	gint x, y;
+
+	gtk_text_view_get_iter_location (GTK_TEXT_VIEW (rpa->priv->view),
+					 &rpa->priv->start, &pos_start);
+	gtk_text_view_get_iter_location (GTK_TEXT_VIEW (rpa->priv->view),
+					 &rpa->priv->end, &pos_end);
+
+	/* Width and height */
+	iw = pos_end.x - pos_start.x;
+	ih = MAX (pos_start.height, pos_end.height);
+
+	if (rpa->priv->surface == NULL)
+	{
+		GtkSourceBuffer *buffer;
+		PangoLayout *layout;
+		PangoContext *context;
+		PangoFontDescription *desc;
+		gchar *text;
+		gchar *markup;
+		gboolean foreground_set, background_set;
+		GdkColor fg_search_color, bg_search_color;
+
+		buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (rpa->priv->view)));
+
+		get_search_match_colors (buffer,
+					 &foreground_set, &fg_search_color,
+					 &background_set, &bg_search_color);
+
+		rpa->priv->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+								 iw,
+								 ih);
+
+		cr = cairo_create (rpa->priv->surface);
+
+		gedit_theatrics_utils_draw_round_rectangle (cr, TRUE, TRUE,
+							    TRUE, TRUE,
+							    0,
+							    0,
+							    4,
+							    iw,
+							    ih);
+
+		if (background_set)
+		{
+			cairo_set_source_rgb (cr,
+					      bg_search_color.red / 65535.,
+					      bg_search_color.green / 65535.,
+					      bg_search_color.blue / 65535.);
+		}
+
+		cairo_fill (cr);
+
+		cairo_move_to (cr, 0, 0);
+
+		if (foreground_set)
+		{
+			cairo_set_source_rgb (cr,
+					      fg_search_color.red / 65535.,
+					      fg_search_color.green / 65535.,
+					      fg_search_color.blue / 65535.);
+		}
+
+		context = gtk_widget_get_pango_context (GTK_WIDGET (rpa->priv->view));
+		layout = gtk_widget_create_pango_layout (GTK_WIDGET (rpa->priv->view),
+							 NULL);
+
+		desc = pango_context_get_font_description (context);
+		pango_layout_set_font_description (layout, desc);
+
+		text = gtk_text_iter_get_text (&rpa->priv->start,
+					       &rpa->priv->end);
+		markup = g_strdup_printf ("<b>%s</b>", text);
+
+		g_free (text);
+
+		pango_layout_set_markup (layout, markup, -1);
+		g_free (markup);
+
+		pango_cairo_show_layout (cr, layout);
+
+		cairo_destroy (cr);
+	}
+
+	scale = 1 + rpa->priv->percent / 12;
+	gtk_text_view_buffer_to_window_coords (GTK_TEXT_VIEW (rpa->priv->view),
+					       GTK_TEXT_WINDOW_TEXT,
+					       pos_start.x,
+					       pos_start.y,
+					       &x,
+					       &y);
+
+	cr = gdk_cairo_create (drawable);
+
+	cairo_translate (cr, x - scale / 2, y - scale / 2);
+
+	cairo_scale (cr, scale, scale);
+	cairo_set_source_surface (cr, rpa->priv->surface, 0, 0);
+
+	cairo_paint (cr);
+
+	cairo_destroy (cr);
+}
+
+static void
+gedit_theatrics_animation_drawable_iface_init (GeditTheatricsAnimationDrawableInterface *iface)
+{
+	iface->get_animation_bounds = gedit_theatrics_highlight_search_animation_get_animation_bounds;
+	iface->get_percent = gedit_theatrics_highlight_search_animation_get_percent;
+	iface->set_percent = gedit_theatrics_highlight_search_animation_set_percent;
+	iface->draw = gedit_theatrics_highlight_search_animation_draw;
+}
+
+GeditTheatricsAnimationDrawable *
+gedit_theatrics_highlight_search_animation_new (GtkSourceView *view,
+						GtkTextIter   *start,
+						GtkTextIter   *end)
+{
+	GeditTheatricsHighlightSearchAnimation *rpa;
+
+	g_return_val_if_fail (GTK_IS_SOURCE_VIEW (view), NULL);
+	g_return_val_if_fail (start != NULL && end != NULL, NULL);
+
+	rpa = g_object_new (GEDIT_TYPE_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION,
+			    "view", view, NULL);
+
+	rpa->priv->start = *start;
+	rpa->priv->end = *end;
+
+	return GEDIT_THEATRICS_ANIMATION_DRAWABLE (rpa);
+}
diff --git a/gedit/theatrics/gedit-theatrics-highlight-search-animation.h b/gedit/theatrics/gedit-theatrics-highlight-search-animation.h
new file mode 100644
index 0000000..5af9a07
--- /dev/null
+++ b/gedit/theatrics/gedit-theatrics-highlight-search-animation.h
@@ -0,0 +1,67 @@
+/*
+ * gedit-theatrics-highlight-search-animation.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Ignacio Casal Quinteiro
+ *
+ * Based on Mike Krüger <mkrueger novell com> work.
+ *
+ * gedit 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifndef __GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION_H__
+#define __GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION_H__
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksourceview.h>
+#include "gedit-theatrics-animation-drawable.h"
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION		(gedit_theatrics_highlight_search_animation_get_type ())
+#define GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION, GeditTheatricsHighlightSearchAnimation))
+#define GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION_CONST(obj)	(G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION, GeditTheatricsHighlightSearchAnimation const))
+#define GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION, GeditTheatricsHighlightSearchAnimationClass))
+#define GEDIT_IS_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION))
+#define GEDIT_IS_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION))
+#define GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION, GeditTheatricsHighlightSearchAnimationClass))
+
+typedef struct _GeditTheatricsHighlightSearchAnimation		GeditTheatricsHighlightSearchAnimation;
+typedef struct _GeditTheatricsHighlightSearchAnimationClass		GeditTheatricsHighlightSearchAnimationClass;
+typedef struct _GeditTheatricsHighlightSearchAnimationPrivate	GeditTheatricsHighlightSearchAnimationPrivate;
+
+struct _GeditTheatricsHighlightSearchAnimation
+{
+	GObject parent;
+
+	GeditTheatricsHighlightSearchAnimationPrivate *priv;
+};
+
+struct _GeditTheatricsHighlightSearchAnimationClass
+{
+	GObjectClass parent_class;
+};
+
+GType gedit_theatrics_highlight_search_animation_get_type (void) G_GNUC_CONST;
+
+GeditTheatricsAnimationDrawable *gedit_theatrics_highlight_search_animation_new (GtkSourceView *view,
+										 GtkTextIter   *start,
+										 GtkTextIter   *end);
+
+G_END_DECLS
+
+#endif /* __GEDIT_THEATRICS_HIGHLIGHT_SEARCH_ANIMATION_H__ */



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