Add LaughActor
[laugh.git] / src / laugh-actor.c
blobd04500e21f6749cc96d705944f9795bddb93986d
1 /*
2 * Laugh.
4 * An glib SMIL library.
6 * Authored By Koos Vriezen <koos.vriezen@gmail.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 #include <string.h>
25 #include <glib/gprintf.h>
27 #include "laugh-actor.h"
28 #include "laugh-dom.h"
30 #define LAUGH_ACTOR_GET_PRIVATE(obj) \
31 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), LAUGH_TYPE_ACTOR, LaughActorPrivate))
34 enum
36 LOADED,
37 FINISHED,
39 LAST_SIGNAL
42 struct _LaughActorPrivate
44 LaughDocument *document;
45 guint width;
46 guint height;
49 static gpointer laugh_actor_parent_class = ((void *)0);
51 static guint laugh_actor_signals[LAST_SIGNAL] = { 0 };
53 static void laugh_actor_finalize (GObject *object)
55 LaughActor *self = LAUGH_ACTOR(object);
57 if (self->priv->document)
58 g_object_unref (G_OBJECT (self->priv->document));
60 G_OBJECT_CLASS (laugh_actor_parent_class)->finalize (object);
63 static void laugh_actor_dispose (GObject *object)
65 G_OBJECT_CLASS (laugh_actor_parent_class)->dispose (object);
68 static void
69 _laugh_actor_request_coords (ClutterActor *self, ClutterActorBox *box)
71 LaughActor *actor = LAUGH_ACTOR(self);
73 actor->priv->width =
74 CLUTTER_UNITS_TO_INT ((box->x2)) - CLUTTER_UNITS_TO_INT ((box->x1));
75 actor->priv->height =
76 CLUTTER_UNITS_TO_INT ((box->y2)) - CLUTTER_UNITS_TO_INT ((box->y1));
77 g_printf ("resizing %dx%d\n", actor->priv->width, actor->priv->height);
79 CLUTTER_ACTOR_CLASS (laugh_actor_parent_class)->request_coords (self, box);
82 static void laugh_actor_class_init (LaughActorClass *klass)
84 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
85 ClutterActorClass *actor_class = (ClutterActorClass *) klass;
87 laugh_actor_parent_class = g_type_class_peek_parent (klass);
89 gobject_class->finalize = laugh_actor_finalize;
90 gobject_class->dispose = laugh_actor_dispose;
91 actor_class->request_coords = _laugh_actor_request_coords;
93 laugh_actor_signals[LOADED] =
94 g_signal_new ("loaded",
95 G_TYPE_FROM_CLASS (gobject_class),
96 G_SIGNAL_RUN_LAST,
97 G_STRUCT_OFFSET (LaughActorClass, loaded),
98 NULL, NULL,
99 g_cclosure_marshal_VOID__VOID,
100 G_TYPE_NONE, 0);
102 laugh_actor_signals[FINISHED] =
103 g_signal_new ("finished",
104 G_TYPE_FROM_CLASS (gobject_class),
105 G_SIGNAL_RUN_LAST,
106 G_STRUCT_OFFSET (LaughActorClass, finished),
107 NULL, NULL,
108 g_cclosure_marshal_VOID__VOID,
109 G_TYPE_NONE, 0);
111 g_type_class_add_private (gobject_class, sizeof (LaughActorPrivate));
114 static
115 void laugh_actor_instance_init (GTypeInstance *instance, gpointer g_class)
117 LaughActor *self = (LaughActor *)instance;
119 self->priv = LAUGH_ACTOR_GET_PRIVATE (self);
122 GType laugh_actor_get_type (void)
124 static GType type = 0;
125 if (type == 0) {
126 static const GTypeInfo info = {
127 sizeof (LaughActorClass),
128 NULL, /* base_init */
129 NULL, /* base_finalize */
130 (GClassInitFunc) laugh_actor_class_init, /* class_init */
131 NULL, /* class_finalize */
132 NULL, /* class_data */
133 sizeof (LaughActor),
134 0, /* n_preallocs */
135 laugh_actor_instance_init /* instance_init */
137 type = g_type_register_static (CLUTTER_TYPE_GROUP,
138 "LaughActorType",
139 &info, 0);
141 return type;
144 ClutterActor *laugh_actor_new ()
146 ClutterActor *actor = (ClutterActor *)g_object_new(LAUGH_TYPE_ACTOR, NULL);
148 return actor;
151 void dump_timings (LaughRoleTiming *segment)
153 GSList *s = segment->sub_segments;
154 gboolean first = TRUE;
156 g_printf ("%s", laugh_tag_from_id (segment->node->id));
158 if (s) {
159 g_printf ("[");
160 for ( ; s; s = s->next) {
161 GSList *s1 = (GSList *) s->data;
162 gboolean sub_first = TRUE;
163 if (!first)
164 g_printf (", ");
165 else
166 first = FALSE;
167 for ( ; s1; s1 = s1->next) {
168 if (!sub_first)
169 g_printf ("->");
170 else
171 sub_first = FALSE;
172 dump_timings ((LaughRoleTiming *) s1->data);
175 g_printf ("]");
179 void _laugh_actor_initialized (LaughNode *node, gpointer d)
181 LaughActor *self = LAUGH_ACTOR (d);
182 gchar *xml = laugh_node_get_inner_xml (node);
184 g_printf ("LaughActor initialized\n%s\n", xml);
185 dump_timings (((LaughDocument *)node)->timing);
186 g_printf ("\n");
188 g_free (xml);
190 g_signal_emit (G_OBJECT (self), laugh_actor_signals[LOADED], 0);
193 void _laugh_actor_stopped (LaughNode *node, gpointer d)
195 g_printf ("LaughActor stopped\n");
198 void laugh_actor_uri_set (LaughActor *actor, const gchar *uri)
200 LaughActorPrivate *priv = actor->priv;
202 if (!priv->document) {
203 priv->document = laugh_document_new (uri);
205 g_signal_connect (G_OBJECT (priv->document), "initialized",
206 (GCallback) _laugh_actor_initialized, actor);
207 g_signal_connect (G_OBJECT (priv->document), "stopped",
208 (GCallback) _laugh_actor_stopped, actor);
209 } else {
210 laugh_document_set_uri (priv->document, uri);
214 void laugh_actor_start (LaughActor *actor)
216 LaughActorPrivate *priv = actor->priv;
218 laugh_document_open (priv->document, CLUTTER_CONTAINER (actor),
219 priv->width, priv->height);