[Swfdec] Branch 'as' - libswfdec/swfdec_graphic_movie.c libswfdec/swfdec_movie.c libswfdec/swfdec_movie.h libswfdec/swfdec_sprite_movie.c

Benjamin Otte company at kemper.freedesktop.org
Wed Jun 20 02:26:47 PDT 2007


 libswfdec/swfdec_graphic_movie.c |   35 +++++++++++++++++++++++++++++++++++
 libswfdec/swfdec_movie.c         |    3 +++
 libswfdec/swfdec_movie.h         |    2 ++
 libswfdec/swfdec_sprite_movie.c  |   13 ++++++++-----
 4 files changed, 48 insertions(+), 5 deletions(-)

New commits:
diff-tree 255d2e184bae07fbcd9db8a906450a21e0f687c7 (from 9ed04d23be28c9dd349a2f5024546c465d09da96)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Jun 20 11:28:05 2007 +0200

    allow movies to replace their contents with a new Graphic

diff --git a/libswfdec/swfdec_graphic_movie.c b/libswfdec/swfdec_graphic_movie.c
index b043b21..b3cfd73 100644
--- a/libswfdec/swfdec_graphic_movie.c
+++ b/libswfdec/swfdec_graphic_movie.c
@@ -22,6 +22,15 @@
 #endif
 
 #include "swfdec_graphic_movie.h"
+#include "swfdec_button.h"
+#include "swfdec_debug.h"
+#include "swfdec_edittext.h"
+#include "swfdec_movie.h"
+#include "swfdec_shape.h"
+#include "swfdec_sprite.h"
+#include "swfdec_swf_decoder.h"
+#include "swfdec_swf_instance.h"
+#include "swfdec_text.h"
 
 G_DEFINE_TYPE (SwfdecGraphicMovie, swfdec_graphic_movie, SWFDEC_TYPE_MOVIE)
 
@@ -51,6 +60,31 @@ swfdec_graphic_movie_mouse_in (SwfdecMov
 }
 
 static void
+swfdec_graphic_movie_replace (SwfdecMovie *movie, SwfdecGraphic *graphic)
+{
+  SwfdecGraphicMovie *gmovie = SWFDEC_GRAPHIC_MOVIE (movie);
+
+  if (SWFDEC_IS_SHAPE (graphic) ||
+      SWFDEC_IS_TEXT (graphic)) {
+    /* wtf? */
+    if (SWFDEC_SWF_DECODER (movie->swf->decoder)->version == 6)
+      return;
+  } else if (SWFDEC_IS_SPRITE (graphic) ||
+      SWFDEC_IS_BUTTON (graphic) ||
+      SWFDEC_IS_EDIT_TEXT (graphic)) {
+    SWFDEC_INFO ("can't replace with scriptable objects");
+    return;
+  } else {
+    SWFDEC_FIXME ("Can we replace with %s objects?", G_OBJECT_TYPE_NAME (graphic));
+    return;
+  }
+  swfdec_movie_invalidate (movie);
+  g_object_unref (gmovie->graphic);
+  gmovie->graphic = g_object_ref (graphic);
+  swfdec_movie_queue_update (movie, SWFDEC_MOVIE_INVALID_EXTENTS);
+}
+
+static void
 swfdec_graphic_movie_dispose (GObject *object)
 {
   SwfdecGraphicMovie *movie = SWFDEC_GRAPHIC_MOVIE (object);
@@ -69,6 +103,7 @@ swfdec_graphic_movie_class_init (SwfdecG
   object_class->dispose = swfdec_graphic_movie_dispose;
 
   movie_class->update_extents = swfdec_graphic_movie_update_extents;
+  movie_class->replace = swfdec_graphic_movie_replace;
   movie_class->render = swfdec_graphic_movie_render;
   movie_class->mouse_in = swfdec_graphic_movie_mouse_in;
 }
diff --git a/libswfdec/swfdec_movie.c b/libswfdec/swfdec_movie.c
index 1b09906..c66d5be 100644
--- a/libswfdec/swfdec_movie.c
+++ b/libswfdec/swfdec_movie.c
@@ -331,6 +331,7 @@ swfdec_movie_destroy (SwfdecMovie *movie
     klass->finish_movie (movie);
   player->movies = g_list_remove (player->movies, movie);
   movie->state = SWFDEC_MOVIE_STATE_DESTROYED;
+  g_print ("destroying movie %p %s\n", movie, movie->name);
   g_object_unref (movie);
 }
 
@@ -936,6 +937,8 @@ swfdec_movie_new (SwfdecPlayer *player, 
   /* emit the new-movie signal */
   if (SWFDEC_IS_DEBUGGER (player))
     g_signal_emit_by_name (player, "movie-added", movie);
+  g_print ("new movie %p %s for %p %s @ %u\n", movie, movie->name, parent, 
+      parent ? parent->name : "", movie->depth);
   return movie;
 }
 
diff --git a/libswfdec/swfdec_movie.h b/libswfdec/swfdec_movie.h
index 418236a..2d3f20d 100644
--- a/libswfdec/swfdec_movie.h
+++ b/libswfdec/swfdec_movie.h
@@ -135,6 +135,8 @@ struct _SwfdecMovieClass {
   /* general vfuncs */
   void			(* init_movie)		(SwfdecMovie *		movie);
   void			(* finish_movie)	(SwfdecMovie *		movie);
+  void			(* replace)		(SwfdecMovie *		movie,
+						 SwfdecGraphic *	graphic);
   void			(* update_extents)	(SwfdecMovie *		movie,
 						 SwfdecRect *   	extents);
   void			(* render)		(SwfdecMovie *		movie, 
diff --git a/libswfdec/swfdec_sprite_movie.c b/libswfdec/swfdec_sprite_movie.c
index 89b076f..cbbc8b7 100644
--- a/libswfdec/swfdec_sprite_movie.c
+++ b/libswfdec/swfdec_sprite_movie.c
@@ -96,6 +96,7 @@ swfdec_sprite_movie_perform_place (Swfde
   guint ratio, id, version;
   SwfdecEventList *events;
   const char *name;
+  SwfdecGraphic *graphic;
 
   version = SWFDEC_SWF_DECODER (mov->swf->decoder)->version;
 
@@ -238,20 +239,24 @@ swfdec_sprite_movie_perform_place (Swfde
 
   /* 3) perform the actions depending on the set properties */
   cur = swfdec_movie_find (mov, depth);
+  graphic = swfdec_swf_decoder_get_character (SWFDEC_SWF_DECODER (mov->swf->decoder), id);
   if (move) {
     if (cur == NULL) {
       SWFDEC_INFO ("no movie at depth %d, ignoring move command", depth);
       return TRUE;
     }
+    if (graphic) {
+      SwfdecMovieClass *klass = SWFDEC_MOVIE_GET_CLASS (cur);
+      if (klass->replace)
+	klass->replace (cur, graphic);
+    }
     swfdec_movie_set_static_properties (cur, has_transform ? &transform : NULL, 
 	has_ctrans ? &ctrans : NULL, ratio, clip_depth, events);
   } else {
-    SwfdecGraphic *graphic;
     if (cur != NULL && version > 5) {
       SWFDEC_INFO ("depth %d is already occupied by movie %s, not placing", depth, cur->name);
       return TRUE;
     }
-    graphic = swfdec_swf_decoder_get_character (SWFDEC_SWF_DECODER (mov->swf->decoder), id);
     if (!SWFDEC_IS_GRAPHIC (graphic)) {
       SWFDEC_FIXME ("character %u is not a graphic (does it even exist?), aborting", id);
       return FALSE;
@@ -332,10 +337,8 @@ swfdec_movie_is_compatible (SwfdecMovie 
   if (movie->original_ratio != with->original_ratio)
     return FALSE;
 
-  if (G_OBJECT_TYPE (movie) != G_OBJECT_TYPE (with)) {
-    SWFDEC_FIXME ("this should work, shouldn't it?");
+  if (G_OBJECT_TYPE (movie) != G_OBJECT_TYPE (with))
     return FALSE;
-  }
 
   return TRUE;
 }


More information about the Swfdec mailing list