content: Make vfuncs optional

The virtual functions on the ClutterContent interface should provide
hooks for application code, not be the actual implementation.
This commit is contained in:
Emmanuele Bassi 2012-02-04 12:49:49 +00:00
parent f4d8fb054a
commit 2f0d29ad75
2 changed files with 47 additions and 47 deletions

View File

@ -70,57 +70,17 @@ static void
clutter_content_real_attached (ClutterContent *content,
ClutterActor *actor)
{
GObject *obj = G_OBJECT (content);
GHashTable *actors;
actors = g_object_get_qdata (obj, quark_content_actors);
if (actors == NULL)
{
actors = g_hash_table_new (NULL, NULL);
g_object_set_qdata_full (obj, quark_content_actors,
actors,
(GDestroyNotify) g_hash_table_unref);
}
g_hash_table_insert (actors, actor, actor);
}
static void
clutter_content_real_detached (ClutterContent *content,
ClutterActor *actor)
{
GObject *obj = G_OBJECT (content);
GHashTable *actors;
actors = g_object_get_qdata (obj, quark_content_actors);
g_assert (actors != NULL);
g_hash_table_remove (actors, actor);
if (g_hash_table_size (actors) == 0)
g_object_set_qdata (obj, quark_content_actors, NULL);
}
static void
clutter_content_real_invalidate (ClutterContent *content)
{
GHashTable *actors;
GHashTableIter iter;
gpointer key_p, value_p;
actors = g_object_get_qdata (G_OBJECT (content), quark_content_actors);
if (actors == NULL)
return;
g_hash_table_iter_init (&iter, actors);
while (g_hash_table_iter_next (&iter, &key_p, &value_p))
{
ClutterActor *actor = key_p;
g_assert (actor != NULL);
clutter_actor_queue_redraw (actor);
}
}
static void
@ -157,8 +117,26 @@ clutter_content_default_init (ClutterContentInterface *iface)
void
clutter_content_invalidate (ClutterContent *content)
{
GHashTable *actors;
GHashTableIter iter;
gpointer key_p, value_p;
g_return_if_fail (CLUTTER_IS_CONTENT (content));
actors = g_object_get_qdata (G_OBJECT (content), quark_content_actors);
if (actors == NULL)
return;
g_hash_table_iter_init (&iter, actors);
while (g_hash_table_iter_next (&iter, &key_p, &value_p))
{
ClutterActor *actor = key_p;
g_assert (actor != NULL);
clutter_actor_queue_redraw (actor);
}
CLUTTER_CONTENT_GET_IFACE (content)->invalidate (content);
}
@ -180,6 +158,20 @@ void
_clutter_content_attached (ClutterContent *content,
ClutterActor *actor)
{
GObject *obj = G_OBJECT (content);
GHashTable *actors;
actors = g_object_get_qdata (obj, quark_content_actors);
if (actors == NULL)
{
actors = g_hash_table_new (NULL, NULL);
g_object_set_qdata_full (obj, quark_content_actors,
actors,
(GDestroyNotify) g_hash_table_unref);
}
g_hash_table_insert (actors, actor, actor);
CLUTTER_CONTENT_GET_IFACE (content)->attached (content, actor);
}
@ -200,6 +192,17 @@ void
_clutter_content_detached (ClutterContent *content,
ClutterActor *actor)
{
GObject *obj = G_OBJECT (content);
GHashTable *actors;
actors = g_object_get_qdata (obj, quark_content_actors);
g_assert (actors != NULL);
g_hash_table_remove (actors, actor);
if (g_hash_table_size (actors) == 0)
g_object_set_qdata (obj, quark_content_actors, NULL);
CLUTTER_CONTENT_GET_IFACE (content)->detached (content, actor);
}

View File

@ -3,7 +3,7 @@
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2011 Intel Corporation.
* Copyright (C) 2012 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -56,14 +56,11 @@ typedef struct _ClutterContentIface ClutterContentIface;
* @paint_content: virtual function; called each time the content needs to
* paint itself
* @attached: virtual function; called each time a #ClutterContent is attached
* to a #ClutterActor. If overridden, the subclass must chain up to the
* parent class implementation.
* to a #ClutterActor.
* @detached: virtual function; called each time a #ClutterContent is detached
* from a #ClutterActor. If overridden, the subclass must chain up to the
* parent class implementation.
* from a #ClutterActor.
* @invalidate: virtual function; called each time a #ClutterContent state
* is changed. If overridden, the subclass must chain up to the parent
* class implementation.
* is changed.
*
* The <structname>ClutterContentIface</structname> structure contains only
* private data.