[Swfdec] 8 commits - libswfdec/swfdec_movie.c libswfdec/swfdec_movie.h libswfdec/swfdec_player.c libswfdec/swfdec_player_internal.h libswfdec/swfdec_sprite_movie_as.c vivified/core

Benjamin Otte company at kemper.freedesktop.org
Wed Aug 22 12:22:19 PDT 2007


 libswfdec/swfdec_movie.c            |   91 ++++++++++++++++++++++++++++++------
 libswfdec/swfdec_movie.h            |    7 ++
 libswfdec/swfdec_player.c           |   57 ++++++++++++++++------
 libswfdec/swfdec_player_internal.h  |   12 +++-
 libswfdec/swfdec_sprite_movie_as.c  |   75 +++++++----------------------
 vivified/core/vivi_application.c    |   37 ++++++--------
 vivified/core/vivi_application.h    |    1 
 vivified/core/vivi_application_as.c |    2 
 8 files changed, 169 insertions(+), 113 deletions(-)

New commits:
diff-tree 10d4cc43986ce88bb43cb7bf96712846c962ed86 (from d752275f3f23d91ea0e3e7aa03fadce6ae8bef34)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Aug 22 21:14:55 2007 +0200

    make swfdec_movie_mouse_in() check children
    
    This makes kittencannon work

diff --git a/libswfdec/swfdec_movie.c b/libswfdec/swfdec_movie.c
index eb1e2e5..ca76cc5 100644
--- a/libswfdec/swfdec_movie.c
+++ b/libswfdec/swfdec_movie.c
@@ -480,11 +480,22 @@ gboolean
 swfdec_movie_mouse_in (SwfdecMovie *movie, double x, double y)
 {
   SwfdecMovieClass *klass;
+  GList *walk;
 
   klass = SWFDEC_MOVIE_GET_CLASS (movie);
-  if (klass->mouse_in == NULL)
-    return FALSE;
-  return klass->mouse_in (movie, x, y);
+  if (klass->mouse_in != NULL &&
+      klass->mouse_in (movie, x, y))
+    return TRUE;
+
+  for (walk = movie->list; walk; walk = walk->next) {
+    double tmp_x = x;
+    double tmp_y = y;
+    SwfdecMovie *cur = walk->data;
+    cairo_matrix_transform_point (&cur->inverse_matrix, &tmp_x, &tmp_y);
+    if (swfdec_movie_mouse_in (cur, tmp_x, tmp_y))
+      return TRUE;
+  }
+  return FALSE;
 }
 
 void
diff-tree d752275f3f23d91ea0e3e7aa03fadce6ae8bef34 (from ef1ab031ce43c3cc300ebdc2150f0959dc0efc92)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Aug 22 21:09:51 2007 +0200

    implement hitTest in a much nicer form

diff --git a/libswfdec/swfdec_sprite_movie_as.c b/libswfdec/swfdec_sprite_movie_as.c
index 0722f4c..2a39cb0 100644
--- a/libswfdec/swfdec_sprite_movie_as.c
+++ b/libswfdec/swfdec_sprite_movie_as.c
@@ -160,9 +160,8 @@ swfdec_sprite_movie_hitTest (SwfdecAsCon
   SwfdecMovie *movie = SWFDEC_MOVIE (obj);
   
   if (argc == 1) {
-    SwfdecMovie *other, *tmp;
+    SwfdecMovie *other;
     SwfdecRect movie_rect, other_rect;
-    guint movie_depth, other_depth;
     if (!SWFDEC_AS_VALUE_IS_OBJECT (&argv[0]) ||
         !SWFDEC_IS_MOVIE (other = (SwfdecMovie *) SWFDEC_AS_VALUE_GET_OBJECT (&argv[0]))) {
       SWFDEC_ERROR ("FIXME: what happens now?");
@@ -170,70 +169,29 @@ swfdec_sprite_movie_hitTest (SwfdecAsCon
     }
     swfdec_movie_update (movie);
     swfdec_movie_update (other);
-    if (movie->parent != other->parent) {
-      movie_rect = movie->original_extents;
-      other_rect = other->original_extents;
-      swfdec_movie_update (other);
-      tmp = movie;
-      for (movie_depth = 0; tmp->parent; movie_depth++)
-	tmp = tmp->parent;
-      tmp = other;
-      for (other_depth = 0; tmp->parent; other_depth++)
-	tmp = tmp->parent;
-      while (movie_depth > other_depth) {
-	swfdec_rect_transform (&movie_rect, &movie_rect, &movie->matrix);
-	movie = movie->parent;
-	movie_depth--;
-      }
-      while (other_depth > movie_depth) {
-	swfdec_rect_transform (&other_rect, &other_rect, &other->matrix);
-	other = other->parent;
-	other_depth--;
-      }
-      while (other != movie && other->parent) {
-	swfdec_rect_transform (&movie_rect, &movie_rect, &movie->matrix);
-	movie = movie->parent;
-	swfdec_rect_transform (&other_rect, &other_rect, &other->matrix);
-	other = other->parent;
-      }
-    } else {
-      movie_rect = movie->extents;
-      other_rect = other->extents;
-    }
-#if 0
-    g_print ("%g %g  %g %g --- %g %g  %g %g\n", 
-	SWFDEC_OBJECT (movie)->extents.x0, SWFDEC_OBJECT (movie)->extents.y0,
-	SWFDEC_OBJECT (movie)->extents.x1, SWFDEC_OBJECT (movie)->extents.y1,
-	SWFDEC_OBJECT (other)->extents.x0, SWFDEC_OBJECT (other)->extents.y0,
-	SWFDEC_OBJECT (other)->extents.x1, SWFDEC_OBJECT (other)->extents.y1);
-#endif
+    movie_rect = movie->extents;
+    if (movie->parent)
+      swfdec_movie_rect_local_to_global (movie->parent, &movie_rect);
+    other_rect = other->extents;
+    if (other->parent)
+      swfdec_movie_rect_local_to_global (other->parent, &other_rect);
     SWFDEC_AS_VALUE_SET_BOOLEAN (rval, swfdec_rect_intersect (NULL, &movie_rect, &other_rect));
   } else if (argc >= 2) {
-    SwfdecRect movie_rect;
     double x, y;
+    gboolean shape, ret;
 
-    x = swfdec_as_value_to_number (cx, &argv[0]);
-    y = swfdec_as_value_to_number (cx, &argv[1]);
+    x = swfdec_as_value_to_number (cx, &argv[0]) * SWFDEC_TWIPS_SCALE_FACTOR;
+    y = swfdec_as_value_to_number (cx, &argv[1]) * SWFDEC_TWIPS_SCALE_FACTOR;
+    shape = (argc >= 3 && swfdec_as_value_to_boolean (cx, &argv[2]));
 
-    if (argc >= 3) {
-      if (swfdec_as_value_to_boolean (cx, &argv[2])) {
-	SWFDEC_FIXME ("hitTest's shapeFlag parameter not supported");
-	// just continue...
-      }
-    }
+    swfdec_movie_global_to_local (movie, &x, &y);
 
-    swfdec_movie_update (movie);
-    movie_rect = movie->original_extents;
-    while (movie->parent) {
-      swfdec_rect_transform (&movie_rect, &movie_rect, &movie->matrix);
-      movie = movie->parent;
+    if (shape && FALSE) {
+      ret = swfdec_movie_mouse_in (movie, x, y);
+    } else {
+      ret = swfdec_rect_contains (&movie->original_extents, x, y);
     }
-
-    g_print ("%d %d in { %g %g  %g %g }?\n", SWFDEC_DOUBLE_TO_TWIPS (x), 
-	SWFDEC_DOUBLE_TO_TWIPS (y), movie->extents.x0, movie->extents.y0,
-	movie->extents.x1, movie->extents.y1);
-    SWFDEC_AS_VALUE_SET_BOOLEAN (rval, swfdec_rect_contains (&movie->extents, 
-	  SWFDEC_DOUBLE_TO_TWIPS (x), SWFDEC_DOUBLE_TO_TWIPS (y)));
+    SWFDEC_AS_VALUE_SET_BOOLEAN (rval, ret);
   } else {
     SWFDEC_FIXME ("hitTest with 0 parameters, what to do?");
   }
diff-tree ef1ab031ce43c3cc300ebdc2150f0959dc0efc92 (from a7762e6746189c482fabf240bfcbfb5d5532c687)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Aug 22 21:09:35 2007 +0200

    add swfdec_movie_rect_global_to_local/local_to_global()

diff --git a/libswfdec/swfdec_movie.c b/libswfdec/swfdec_movie.c
index 96a7af1..eb1e2e5 100644
--- a/libswfdec/swfdec_movie.c
+++ b/libswfdec/swfdec_movie.c
@@ -476,7 +476,7 @@ swfdec_movie_set_variables (SwfdecMovie 
 
 /* NB: coordinates are in movie's coordiante system. Use swfdec_movie_get_mouse
  * if you have global coordinates */
-static gboolean
+gboolean
 swfdec_movie_mouse_in (SwfdecMovie *movie, double x, double y)
 {
   SwfdecMovieClass *klass;
@@ -490,14 +490,42 @@ swfdec_movie_mouse_in (SwfdecMovie *movi
 void
 swfdec_movie_local_to_global (SwfdecMovie *movie, double *x, double *y)
 {
+  g_return_if_fail (SWFDEC_IS_MOVIE (movie));
+  g_return_if_fail (x != NULL);
+  g_return_if_fail (y != NULL);
+
   do {
     cairo_matrix_transform_point (&movie->matrix, x, y);
   } while ((movie = movie->parent));
 }
 
 void
+swfdec_movie_rect_local_to_global (SwfdecMovie *movie, SwfdecRect *rect)
+{
+  g_return_if_fail (SWFDEC_IS_MOVIE (movie));
+  g_return_if_fail (rect != NULL);
+
+  swfdec_movie_local_to_global (movie, &rect->x0, &rect->y0);
+  swfdec_movie_local_to_global (movie, &rect->x1, &rect->y1);
+  if (rect->x0 > rect->x1) {
+    double tmp = rect->x1;
+    rect->x1 = rect->x0;
+    rect->x0 = tmp;
+  }
+  if (rect->y0 > rect->y1) {
+    double tmp = rect->y1;
+    rect->y1 = rect->y0;
+    rect->y0 = tmp;
+  }
+}
+
+void
 swfdec_movie_global_to_local (SwfdecMovie *movie, double *x, double *y)
 {
+  g_return_if_fail (SWFDEC_IS_MOVIE (movie));
+  g_return_if_fail (x != NULL);
+  g_return_if_fail (y != NULL);
+
   if (movie->parent) {
     swfdec_movie_global_to_local (movie->parent, x, y);
   }
@@ -506,6 +534,26 @@ swfdec_movie_global_to_local (SwfdecMovi
   cairo_matrix_transform_point (&movie->inverse_matrix, x, y);
 }
 
+void
+swfdec_movie_rect_global_to_local (SwfdecMovie *movie, SwfdecRect *rect)
+{
+  g_return_if_fail (SWFDEC_IS_MOVIE (movie));
+  g_return_if_fail (rect != NULL);
+
+  swfdec_movie_global_to_local (movie, &rect->x0, &rect->y0);
+  swfdec_movie_global_to_local (movie, &rect->x1, &rect->y1);
+  if (rect->x0 > rect->x1) {
+    double tmp = rect->x1;
+    rect->x1 = rect->x0;
+    rect->x0 = tmp;
+  }
+  if (rect->y0 > rect->y1) {
+    double tmp = rect->y1;
+    rect->y1 = rect->y0;
+    rect->y0 = tmp;
+  }
+}
+
 /**
  * swfdec_movie_get_mouse:
  * @movie: a #SwfdecMovie
diff --git a/libswfdec/swfdec_movie.h b/libswfdec/swfdec_movie.h
index 1e83f6b..41e99fa 100644
--- a/libswfdec/swfdec_movie.h
+++ b/libswfdec/swfdec_movie.h
@@ -192,6 +192,10 @@ void		swfdec_movie_local_to_global	(Swfd
 void		swfdec_movie_global_to_local	(SwfdecMovie *		movie,
 						 double *		x,
 						 double *		y);
+void		swfdec_movie_rect_local_to_global (SwfdecMovie *	movie,
+						 SwfdecRect *		rect);
+void		swfdec_movie_rect_global_to_local (SwfdecMovie *	movie,
+						 SwfdecRect *		rect);
 void		swfdec_movie_set_depth		(SwfdecMovie *		movie,
 						 int			depth);
 void		swfdec_movie_get_mouse		(SwfdecMovie *		movie,
@@ -199,6 +203,9 @@ void		swfdec_movie_get_mouse		(SwfdecMov
 						 double *		y);
 void		swfdec_movie_send_mouse_change	(SwfdecMovie *		movie,
 						 gboolean		release);
+gboolean	swfdec_movie_mouse_in		(SwfdecMovie *		movie,
+						 double			x,
+						 double			y);
 SwfdecMovie *	swfdec_movie_get_movie_at	(SwfdecMovie *		movie,
 						 double			x,
 						 double			y);
diff-tree a7762e6746189c482fabf240bfcbfb5d5532c687 (from 2433143ef3aed8179907702b434043878abe7c0c)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Aug 22 20:44:23 2007 +0200

    fix coordinate systems
    
    Swfdec now has 4 types of coordinate systems:
    - Stage (unique)
    - global (unique)
    - movie (one per movie)
    - parent (one per movie)
    
    The Stage coordinate system is what the user of the API sees and interacts with.
    It's what coordinates in _handle_mouse() are given in and what the invalidate
    signal uses for its rectangle. The Flash movie itself has no possibility to get
    to this coordinate system.
    
    The global coordinate system is the system all root movies live in. It's what
    you get after applying the Stage transformations. The two functions
    swfdec_player_stage_to_global() and swfdec_player_global_to_stage() transform
    between this and the previous coordinate system. Various Flash functions (like
    for example hitTest when using coordinates) expect coordinates from this system.
    
    The there is one coordinate system per movie. It's what you get after applying
    the movie's matrix to the parent's coordinate system. This coordinate system is
    used for the _x, _y, _height and _width properties of the movie's children.
    Drawing operations in the Flash file format are specified in this coordinate
    system, too. The functions swfdec_movie_global_to_local() and
    swfdec_movie_local_to_global() convert between a movie's and the global
    coordinate systems. You can of course chain these functions with the stage
    conversion functions to transform stage coordinates to movie coordinates and
    vice versa.
    
    Another coordinate system often used in Swfdec terminology is the parent system.
    This is not actually a different coordinate system but just refers to the
    coordinate system of a movie's parent or in the root movie case the global
    coordinate system. Since quite some Actionscript variables and  functions
    require coorinates in this system, it is useful to have a simple term for it.

diff --git a/libswfdec/swfdec_movie.c b/libswfdec/swfdec_movie.c
index 03cc00c..96a7af1 100644
--- a/libswfdec/swfdec_movie.c
+++ b/libswfdec/swfdec_movie.c
@@ -490,16 +490,9 @@ swfdec_movie_mouse_in (SwfdecMovie *movi
 void
 swfdec_movie_local_to_global (SwfdecMovie *movie, double *x, double *y)
 {
-  SwfdecPlayer *player = SWFDEC_PLAYER (SWFDEC_AS_OBJECT (movie)->context);
-
   do {
     cairo_matrix_transform_point (&movie->matrix, x, y);
   } while ((movie = movie->parent));
-
-  *x /= player->scale_x;
-  *y /= player->scale_y;
-  *x += SWFDEC_TWIPS_TO_DOUBLE (player->offset_x);
-  *y += SWFDEC_TWIPS_TO_DOUBLE (player->offset_y);
 }
 
 void
@@ -507,12 +500,6 @@ swfdec_movie_global_to_local (SwfdecMovi
 {
   if (movie->parent) {
     swfdec_movie_global_to_local (movie->parent, x, y);
-  } else {
-    SwfdecPlayer *player = SWFDEC_PLAYER (SWFDEC_AS_OBJECT (movie)->context);
-    *x -= SWFDEC_TWIPS_TO_DOUBLE (player->offset_x);
-    *y -= SWFDEC_TWIPS_TO_DOUBLE (player->offset_y);
-    *x *= player->scale_x;
-    *y *= player->scale_y;
   }
   if (movie->cache_state >= SWFDEC_MOVIE_INVALID_MATRIX)
     swfdec_movie_update (movie);
@@ -539,6 +526,7 @@ swfdec_movie_get_mouse (SwfdecMovie *mov
   player = SWFDEC_PLAYER (SWFDEC_AS_OBJECT (movie)->context);
   *x = player->mouse_x;
   *y = player->mouse_y;
+  swfdec_player_stage_to_global (player, x, y);
   swfdec_movie_global_to_local (movie, x, y);
 }
 
@@ -563,6 +551,18 @@ swfdec_movie_send_mouse_change (SwfdecMo
   klass->mouse_change (movie, x, y, mouse_in, button);
 }
 
+/**
+ * swfdec_movie_get_movie_at:
+ * @movie: a #SwfdecMovie
+ * @x: x coordinate in parent's coordinate space
+ * @y: y coordinate in the parent's coordinate space
+ *
+ * Gets the child at the given coordinates. The coordinates are in the 
+ * coordinate system of @movie's parent (or the global coordinate system for
+ * root movies).
+ *
+ * Returns: the child of @movie at the given coordinates or %NULL if none
+ **/
 SwfdecMovie *
 swfdec_movie_get_movie_at (SwfdecMovie *movie, double x, double y)
 {
diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index 8175219..98a1086 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -729,6 +729,7 @@ swfdec_player_update_drag_movie (SwfdecP
   g_assert (movie->cache_state == SWFDEC_MOVIE_UP_TO_DATE);
   x = player->mouse_x;
   y = player->mouse_y;
+  swfdec_player_stage_to_global (player, &x, &y);
   if (movie->parent)
     swfdec_movie_global_to_local (movie->parent, &x, &y);
   if (player->mouse_drag_center) {
@@ -740,7 +741,7 @@ swfdec_player_update_drag_movie (SwfdecP
   }
   x = CLAMP (x, player->mouse_drag_rect.x0, player->mouse_drag_rect.x1);
   y = CLAMP (y, player->mouse_drag_rect.y0, player->mouse_drag_rect.y1);
-  SWFDEC_LOG ("mouse is at %g %g, orighinally (%g %g)", x, y, player->mouse_x, player->mouse_y);
+  SWFDEC_LOG ("mouse is at %g %g, originally (%g %g)", x, y, player->mouse_x, player->mouse_y);
   if (x != movie->matrix.x0 || y != movie->matrix.y0) {
     movie->matrix.x0 = x;
     movie->matrix.y0 = y;
@@ -772,6 +773,7 @@ swfdec_player_set_drag_movie (SwfdecPlay
   if (drag && !center) {
     player->mouse_drag_x = player->mouse_x;
     player->mouse_drag_y = player->mouse_y;
+    swfdec_player_stage_to_global (player, &player->mouse_drag_x, &player->mouse_drag_y);
     if (drag->parent)
       swfdec_movie_global_to_local (drag->parent, &player->mouse_drag_x, &player->mouse_drag_y);
     player->mouse_drag_x -= drag->matrix.x0;
@@ -805,9 +807,13 @@ swfdec_player_update_mouse_position (Swf
   if (player->mouse_button) {
     mouse_grab = player->mouse_grab;
   } else {
+    double x, y;
     /* if the mouse button is pressed the grab widget stays the same (I think) */
+    x = player->mouse_x;
+    y = player->mouse_y;
+    swfdec_player_stage_to_global (player, &x, &y);
     for (walk = g_list_last (player->roots); walk; walk = walk->prev) {
-      mouse_grab = swfdec_movie_get_movie_at (walk->data, player->mouse_x, player->mouse_y);
+      mouse_grab = swfdec_movie_get_movie_at (walk->data, x, y);
       if (mouse_grab)
 	break;
     }
@@ -868,14 +874,12 @@ swfdec_player_emit_signals (SwfdecPlayer
     /* FIXME: currently we clamp the rectangle to the visible area, it might
      * be useful to allow out-of-bounds drawing. In that case this needs to be
      * changed */
-    x = SWFDEC_TWIPS_TO_DOUBLE (player->invalid.x0) * player->scale_x + player->offset_x;
-    x = MAX (x, 0.0);
-    y = SWFDEC_TWIPS_TO_DOUBLE (player->invalid.y0) * player->scale_y + player->offset_y;
-    y = MAX (y, 0.0);
-    width = SWFDEC_TWIPS_TO_DOUBLE (player->invalid.x1 - player->invalid.x0) * player->scale_x;
-    width = MIN (width, player->stage_width - x);
-    height = SWFDEC_TWIPS_TO_DOUBLE (player->invalid.y1 - player->invalid.y0) * player->scale_y;
-    height = MIN (height, player->stage_height - y);
+    swfdec_player_global_to_stage (player, &player->invalid.x0, &player->invalid.y0);
+    swfdec_player_global_to_stage (player, &player->invalid.x1, &player->invalid.y1);
+    x = MAX (player->invalid.x0, 0.0);
+    y = MAX (player->invalid.y0, 0.0);
+    width = MIN (player->invalid.x1, player->stage_width) - x;
+    height = MIN (player->invalid.y1, player->stage_height) - y;
     g_signal_emit (player, signals[INVALIDATE], 0, x, y, width, height);
     swfdec_rect_init_empty (&player->invalid);
   }
@@ -914,10 +918,6 @@ swfdec_player_do_handle_mouse (SwfdecPla
     double x, double y, int button)
 {
   swfdec_player_lock (player);
-  x -= player->offset_x;
-  y -= player->offset_y;
-  x = x * SWFDEC_TWIPS_SCALE_FACTOR / player->scale_x;
-  y = y * SWFDEC_TWIPS_SCALE_FACTOR / player->scale_y;
   SWFDEC_LOG ("handling mouse at %g %g %d", x, y, button);
   if (player->mouse_x != x || player->mouse_y != y) {
     player->mouse_x = x;
@@ -942,8 +942,8 @@ swfdec_player_global_to_stage (SwfdecPla
   g_return_if_fail (x != NULL);
   g_return_if_fail (y != NULL);
 
-  *x = *x / player->scale_x + player->offset_x;
-  *y = *y / player->scale_y + player->offset_y;
+  *x = *x / SWFDEC_TWIPS_SCALE_FACTOR * player->scale_x + player->offset_x;
+  *y = *y / SWFDEC_TWIPS_SCALE_FACTOR * player->scale_y + player->offset_y;
 }
 
 void
@@ -953,8 +953,8 @@ swfdec_player_stage_to_global (SwfdecPla
   g_return_if_fail (x != NULL);
   g_return_if_fail (y != NULL);
 
-  *x = (*x - player->offset_x) * player->scale_x;
-  *y = (*y - player->offset_y) * player->scale_y;
+  *x = (*x - player->offset_x) / player->scale_x * SWFDEC_TWIPS_SCALE_FACTOR;
+  *y = (*y - player->offset_y) / player->scale_y * SWFDEC_TWIPS_SCALE_FACTOR;
 }
 
 static void
@@ -1043,6 +1043,7 @@ swfdec_player_perform_actions (SwfdecPla
 {
   GList *walk;
   SwfdecRect old_inval;
+  double x, y;
 
   g_return_if_fail (SWFDEC_IS_PLAYER (player));
 
@@ -1053,7 +1054,10 @@ swfdec_player_perform_actions (SwfdecPla
       swfdec_movie_update (walk->data);
     }
     /* update the state of the mouse when stuff below it moved */
-    if (swfdec_rect_contains (&player->invalid, player->mouse_x, player->mouse_y)) {
+    x = player->mouse_x;
+    y = player->mouse_y;
+    swfdec_player_stage_to_global (player, &x, &y);
+    if (swfdec_rect_contains (&player->invalid, x, y)) {
       SWFDEC_INFO ("=== NEED TO UPDATE mouse post-iteration ===");
       swfdec_player_update_mouse_position (player);
       for (walk = player->roots; walk; walk = walk->next) {
@@ -1356,6 +1360,7 @@ swfdec_player_stop_all_sounds (SwfdecPla
   }
 }
 
+/* rect is in global coordinates */
 void
 swfdec_player_invalidate (SwfdecPlayer *player, const SwfdecRect *rect)
 {
diff --git a/libswfdec/swfdec_player_internal.h b/libswfdec/swfdec_player_internal.h
index 00c893f..858c6eb 100644
--- a/libswfdec/swfdec_player_internal.h
+++ b/libswfdec/swfdec_player_internal.h
@@ -82,13 +82,13 @@ struct _SwfdecPlayer
   SwfdecAsObject *	Video;			/* Video object */
 
   /* rendering */
-  SwfdecRect		invalid;      		/* area that needs a rredraw */
+  SwfdecRect		invalid;      		/* area that needs a redraw in global coordinates */
 
   /* mouse */
   gboolean		mouse_visible;	  	/* show the mouse (actionscriptable) */
   SwfdecMouseCursor	mouse_cursor;		/* cursor that should be shown */
-  double      		mouse_x;		/* in twips */
-  double		mouse_y;		/* in twips */
+  double      		mouse_x;		/* in stage coordinates */
+  double		mouse_y;		/* in stage coordinates */
   int			mouse_button; 		/* 0 for not pressed, 1 for pressed */
   SwfdecMovie *		mouse_grab;		/* movie that currently has the mouse */
   SwfdecMovie *		mouse_drag;		/* current movie activated by startDrag */
diff --git a/libswfdec/swfdec_sprite_movie_as.c b/libswfdec/swfdec_sprite_movie_as.c
index dddd4ce..0722f4c 100644
--- a/libswfdec/swfdec_sprite_movie_as.c
+++ b/libswfdec/swfdec_sprite_movie_as.c
@@ -229,10 +229,13 @@ swfdec_sprite_movie_hitTest (SwfdecAsCon
       movie = movie->parent;
     }
 
-    SWFDEC_AS_VALUE_SET_BOOLEAN (rval, swfdec_rect_contains (&movie_rect,
-	  SWFDEC_PLAYER (cx)->mouse_x, SWFDEC_PLAYER (cx)->mouse_y));
+    g_print ("%d %d in { %g %g  %g %g }?\n", SWFDEC_DOUBLE_TO_TWIPS (x), 
+	SWFDEC_DOUBLE_TO_TWIPS (y), movie->extents.x0, movie->extents.y0,
+	movie->extents.x1, movie->extents.y1);
+    SWFDEC_AS_VALUE_SET_BOOLEAN (rval, swfdec_rect_contains (&movie->extents, 
+	  SWFDEC_DOUBLE_TO_TWIPS (x), SWFDEC_DOUBLE_TO_TWIPS (y)));
   } else {
-    SWFDEC_FIXME ("hitText with 0 parameters, what to do?");
+    SWFDEC_FIXME ("hitTest with 0 parameters, what to do?");
   }
 }
 
diff-tree 2433143ef3aed8179907702b434043878abe7c0c (from 17de193746f320b9307eff2613404aa8548e2e5d)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Aug 22 19:44:13 2007 +0200

    add swfdec_player_stage_to_global/global_to_stage()

diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index 1f9b2a3..8175219 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -935,6 +935,28 @@ swfdec_player_do_handle_mouse (SwfdecPla
   return TRUE;
 }
 
+void
+swfdec_player_global_to_stage (SwfdecPlayer *player, double *x, double *y)
+{
+  g_return_if_fail (SWFDEC_IS_PLAYER (player));
+  g_return_if_fail (x != NULL);
+  g_return_if_fail (y != NULL);
+
+  *x = *x / player->scale_x + player->offset_x;
+  *y = *y / player->scale_y + player->offset_y;
+}
+
+void
+swfdec_player_stage_to_global (SwfdecPlayer *player, double *x, double *y)
+{
+  g_return_if_fail (SWFDEC_IS_PLAYER (player));
+  g_return_if_fail (x != NULL);
+  g_return_if_fail (y != NULL);
+
+  *x = (*x - player->offset_x) * player->scale_x;
+  *y = (*y - player->offset_y) * player->scale_y;
+}
+
 static void
 swfdec_player_iterate (SwfdecTimeout *timeout)
 {
diff --git a/libswfdec/swfdec_player_internal.h b/libswfdec/swfdec_player_internal.h
index bce9e4a..00c893f 100644
--- a/libswfdec/swfdec_player_internal.h
+++ b/libswfdec/swfdec_player_internal.h
@@ -200,6 +200,12 @@ SwfdecLoader *	swfdec_player_load		(Swfd
 void		swfdec_player_launch		(SwfdecPlayer *         player,
 						 const char *		url,
 						 const char *		target);
+void		swfdec_player_stage_to_global	(SwfdecPlayer *		player,
+						 double *		x,
+						 double *		y);
+void		swfdec_player_global_to_stage	(SwfdecPlayer *		player,
+						 double *		x,
+						 double *		y);
 
 
 G_END_DECLS
diff-tree 17de193746f320b9307eff2613404aa8548e2e5d (from bd1f7a67b87e053796d017c7c3d0e8da4c71112a)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Aug 22 18:31:45 2007 +0200

    don't have our own init function, ut call it from _check()
    
    Since the init function can potentially call back into the Flash engine, this
    is a dangerous thing to call.

diff --git a/vivified/core/vivi_application.c b/vivified/core/vivi_application.c
index 0805396..b9b2811 100644
--- a/vivified/core/vivi_application.c
+++ b/vivified/core/vivi_application.c
@@ -157,26 +157,6 @@ vivi_application_new (void)
 }
 
 void
-vivi_application_init_player (ViviApplication *app)
-{
-  SwfdecLoader *loader;
-
-  g_return_if_fail (VIVI_IS_APPLICATION (app));
-
-  if (app->player_inited)
-    return;
-  
-  if (app->filename == NULL) {
-    vivi_application_error (app, "no file set to play.");
-    return;
-  }
-
-  app->player_inited = TRUE;
-  loader = swfdec_file_loader_new (app->filename);
-  swfdec_player_set_loader_with_variables (app->player, loader, app->variables);
-}
-
-void
 vivi_application_reset (ViviApplication *app)
 {
   gboolean audio;
@@ -310,6 +290,23 @@ vivi_application_check (ViviApplication 
   /* leave breakpoint unless stopped */
   if (is_breakpoint && app->playback_state != VIVI_APPLICATION_STOPPED)
     g_main_loop_quit (app->loop);
+
+  /* init player if playing */
+  if ((app->playback_state == VIVI_APPLICATION_PLAYING ||
+       app->playback_state == VIVI_APPLICATION_STEPPING) &&
+      !app->player_inited) {
+    if (app->filename == NULL) {
+      vivi_application_error (app, "no file set to play.");
+      app->playback_state = VIVI_APPLICATION_STOPPED;
+      vivi_application_check (app);
+    } else {
+      SwfdecLoader *loader;
+
+      app->player_inited = TRUE;
+      loader = swfdec_file_loader_new (app->filename);
+      swfdec_player_set_loader_with_variables (app->player, loader, app->variables);
+    }
+  }
 }
 
 void
diff --git a/vivified/core/vivi_application.h b/vivified/core/vivi_application.h
index 1a8c68a..d5d0c2b 100644
--- a/vivified/core/vivi_application.h
+++ b/vivified/core/vivi_application.h
@@ -99,7 +99,6 @@ SwfdecPlayer *	      	vivi_application_g
 gboolean	      	vivi_application_get_interrupted(ViviApplication *	app);
 gboolean	      	vivi_application_is_quit	(ViviApplication *	app);
 
-void			vivi_application_init_player	(ViviApplication *	app);
 void			vivi_application_reset		(ViviApplication *	app);
 void			vivi_application_play		(ViviApplication *	app);
 void			vivi_application_stop		(ViviApplication *	app);
diff --git a/vivified/core/vivi_application_as.c b/vivified/core/vivi_application_as.c
index 6e2c011..2f9ec6e 100644
--- a/vivified/core/vivi_application_as.c
+++ b/vivified/core/vivi_application_as.c
@@ -41,7 +41,6 @@ vivi_application_as_run (SwfdecAsContext
 {
   ViviApplication *app = VIVI_APPLICATION (cx);
 
-  vivi_application_init_player (app);
   vivi_application_play (app);
 }
 
@@ -63,7 +62,6 @@ vivi_application_as_step (SwfdecAsContex
   ViviApplication *app = VIVI_APPLICATION (cx);
   int steps;
 
-  vivi_application_init_player (app);
   if (argc > 0) {
     steps = swfdec_as_value_to_integer (cx, &argv[0]);
     if (steps <= 1)
diff-tree bd1f7a67b87e053796d017c7c3d0e8da4c71112a (from 357a6593f7125e8518bd65d7f058105ebe7c78a2)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Aug 22 17:26:40 2007 +0200

    copy x0 and y0 immediately or their values will get lost
    
    This can happen when the modified flag gets set before the first update of the
    matrix.

diff --git a/libswfdec/swfdec_movie.c b/libswfdec/swfdec_movie.c
index 0f3cb91..03cc00c 100644
--- a/libswfdec/swfdec_movie.c
+++ b/libswfdec/swfdec_movie.c
@@ -1044,6 +1044,8 @@ swfdec_movie_set_static_properties (Swfd
   }
   if (transform) {
     movie->original_transform = *transform;
+    movie->matrix.x0 = movie->original_transform.x0;
+    movie->matrix.y0 = movie->original_transform.y0;
     movie->xscale = swfdec_matrix_get_xscale (&movie->original_transform);
     movie->yscale = swfdec_matrix_get_yscale (&movie->original_transform);
     movie->rotation = swfdec_matrix_get_rotation (&movie->original_transform);
diff-tree 357a6593f7125e8518bd65d7f058105ebe7c78a2 (from 66f34d06d0ea7226f8f1e5d39af392a10de556c0)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Aug 22 16:40:27 2007 +0200

    set to inited before initing, because initing can cause breakpoints to happen
    
    We of course don't want to run init twice

diff --git a/vivified/core/vivi_application.c b/vivified/core/vivi_application.c
index 19be22d..0805396 100644
--- a/vivified/core/vivi_application.c
+++ b/vivified/core/vivi_application.c
@@ -171,9 +171,9 @@ vivi_application_init_player (ViviApplic
     return;
   }
 
+  app->player_inited = TRUE;
   loader = swfdec_file_loader_new (app->filename);
   swfdec_player_set_loader_with_variables (app->player, loader, app->variables);
-  app->player_inited = TRUE;
 }
 
 void


More information about the Swfdec mailing list