back to development
[swfdec.git] / swfdec / swfdec_graphic_movie.c
blob7fa7842be6d830e2abd862b03c6525a7b2caac21
1 /* Swfdec
2 * Copyright (C) 2006 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include "swfdec_graphic_movie.h"
25 #include "swfdec_button.h"
26 #include "swfdec_debug.h"
27 #include "swfdec_movie.h"
28 #include "swfdec_player_internal.h"
29 #include "swfdec_shape.h"
30 #include "swfdec_sprite.h"
31 #include "swfdec_swf_decoder.h"
32 #include "swfdec_resource.h"
33 #include "swfdec_text.h"
34 #include "swfdec_text_field.h"
36 G_DEFINE_TYPE (SwfdecGraphicMovie, swfdec_graphic_movie, SWFDEC_TYPE_MOVIE)
38 static void
39 swfdec_graphic_movie_update_extents (SwfdecMovie *movie,
40 SwfdecRect *extents)
42 swfdec_rect_union (extents, extents,
43 &movie->graphic->extents);
46 static void
47 swfdec_graphic_movie_render (SwfdecMovie *movie, cairo_t *cr,
48 const SwfdecColorTransform *trans)
50 swfdec_graphic_render (movie->graphic, cr, trans);
53 static void
54 swfdec_graphic_movie_invalidate (SwfdecMovie *movie, const cairo_matrix_t *matrix, gboolean last)
56 SwfdecRect rect;
58 swfdec_rect_transform (&rect, &movie->graphic->extents, matrix);
59 swfdec_player_invalidate (SWFDEC_PLAYER (swfdec_gc_object_get_context (movie)), &rect);
62 static SwfdecMovie *
63 swfdec_graphic_movie_contains (SwfdecMovie *movie, double x, double y,
64 gboolean events)
66 if (swfdec_graphic_mouse_in (movie->graphic, x, y))
67 return movie;
68 else
69 return NULL;
72 static void
73 swfdec_graphic_movie_replace (SwfdecMovie *movie, SwfdecGraphic *graphic)
75 if (SWFDEC_IS_SHAPE (graphic) ||
76 SWFDEC_IS_TEXT (graphic)) {
77 /* nothing to do here, please move along */
78 } else if (SWFDEC_IS_SPRITE (graphic) ||
79 SWFDEC_IS_BUTTON (graphic) ||
80 SWFDEC_IS_TEXT_FIELD (graphic)) {
81 SWFDEC_INFO ("can't replace with scriptable objects");
82 return;
83 } else {
84 SWFDEC_FIXME ("Can we replace with %s objects?", G_OBJECT_TYPE_NAME (graphic));
85 return;
87 if (movie->graphic == graphic)
88 return;
89 swfdec_movie_invalidate_next (movie);
90 SWFDEC_LOG ("replacing %u with %u", SWFDEC_CHARACTER (movie->graphic)->id,
91 SWFDEC_CHARACTER (graphic)->id);
92 swfdec_movie_queue_update (movie, SWFDEC_MOVIE_INVALID_EXTENTS);
93 g_object_unref (movie->graphic);
94 movie->graphic = g_object_ref (graphic);
97 static void
98 swfdec_graphic_movie_class_init (SwfdecGraphicMovieClass * g_class)
100 SwfdecMovieClass *movie_class = SWFDEC_MOVIE_CLASS (g_class);
102 movie_class->update_extents = swfdec_graphic_movie_update_extents;
103 movie_class->replace = swfdec_graphic_movie_replace;
104 movie_class->render = swfdec_graphic_movie_render;
105 movie_class->invalidate = swfdec_graphic_movie_invalidate;
106 movie_class->contains = swfdec_graphic_movie_contains;
109 static void
110 swfdec_graphic_movie_init (SwfdecGraphicMovie * graphic_movie)