add debugging messages for memory (de)allocation
[swfdec.git] / libswfdec / swfdec_stage_as.c
blob15975b7cf0c70aa46587c829e333757b4650ce7e
1 /* Swfdec
2 * Copyright (C) 2007 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 <string.h>
25 #include "swfdec_as_internal.h"
26 #include "swfdec_as_strings.h"
27 #include "swfdec_debug.h"
28 #include "swfdec_player_internal.h"
30 /*** AS CODE ***/
32 SWFDEC_AS_NATIVE (666, 1, get_scaleMode)
33 void
34 get_scaleMode (SwfdecAsContext *cx, SwfdecAsObject *object,
35 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
37 SwfdecPlayer *player = SWFDEC_PLAYER (cx);
39 switch (player->scale_mode) {
40 case SWFDEC_SCALE_SHOW_ALL:
41 SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_showAll);
42 break;
43 case SWFDEC_SCALE_NO_BORDER:
44 SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_noBorder);
45 break;
46 case SWFDEC_SCALE_EXACT_FIT:
47 SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_exactFit);
48 break;
49 case SWFDEC_SCALE_NONE:
50 SWFDEC_AS_VALUE_SET_STRING (ret, SWFDEC_AS_STR_noScale);
51 break;
52 default:
53 g_assert_not_reached ();
54 break;
58 SWFDEC_AS_NATIVE (666, 2, set_scaleMode)
59 void
60 set_scaleMode (SwfdecAsContext *cx, SwfdecAsObject *object,
61 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
63 SwfdecPlayer *player = SWFDEC_PLAYER (cx);
64 const char *s;
65 SwfdecScaleMode mode;
67 if (argc == 0)
68 return;
69 s = swfdec_as_value_to_string (cx, &argv[0]);
70 if (g_ascii_strcasecmp (s, SWFDEC_AS_STR_noBorder) == 0) {
71 mode = SWFDEC_SCALE_NO_BORDER;
72 } else if (g_ascii_strcasecmp (s, SWFDEC_AS_STR_exactFit) == 0) {
73 mode = SWFDEC_SCALE_EXACT_FIT;
74 } else if (g_ascii_strcasecmp (s, SWFDEC_AS_STR_noScale) == 0) {
75 mode = SWFDEC_SCALE_NONE;
76 } else {
77 mode = SWFDEC_SCALE_SHOW_ALL;
79 swfdec_player_set_scale_mode (player, mode);
82 SWFDEC_AS_NATIVE (666, 3, get_align)
83 void
84 get_align (SwfdecAsContext *cx, SwfdecAsObject *object,
85 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
87 SwfdecPlayer *player = SWFDEC_PLAYER (cx);
88 char s[5];
89 guint i = 0;
91 if (player->align_flags & SWFDEC_ALIGN_FLAG_LEFT)
92 s[i++] = 'L';
93 if (player->align_flags & SWFDEC_ALIGN_FLAG_TOP)
94 s[i++] = 'T';
95 if (player->align_flags & SWFDEC_ALIGN_FLAG_RIGHT)
96 s[i++] = 'R';
97 if (player->align_flags & SWFDEC_ALIGN_FLAG_BOTTOM)
98 s[i++] = 'B';
99 s[i] = 0;
100 SWFDEC_AS_VALUE_SET_STRING (ret, swfdec_as_context_get_string (cx, s));
103 SWFDEC_AS_NATIVE (666, 4, set_align)
104 void
105 set_align (SwfdecAsContext *cx, SwfdecAsObject *object,
106 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
108 SwfdecPlayer *player = SWFDEC_PLAYER (cx);
109 guint flags = 0;
110 const char *s;
112 if (argc == 0)
113 return;
115 s = swfdec_as_value_to_string (cx, &argv[0]);
116 if (strchr (s, 'l') || strchr (s, 'L'))
117 flags |= SWFDEC_ALIGN_FLAG_LEFT;
118 if (strchr (s, 't') || strchr (s, 'T'))
119 flags |= SWFDEC_ALIGN_FLAG_TOP;
120 if (strchr (s, 'r') || strchr (s, 'R'))
121 flags |= SWFDEC_ALIGN_FLAG_RIGHT;
122 if (strchr (s, 'b') || strchr (s, 'B'))
123 flags |= SWFDEC_ALIGN_FLAG_BOTTOM;
125 if (flags != player->align_flags) {
126 player->align_flags = flags;
127 g_object_notify (G_OBJECT (player), "alignment");
131 SWFDEC_AS_NATIVE (666, 5, get_width)
132 void
133 get_width (SwfdecAsContext *cx, SwfdecAsObject *object,
134 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
136 SwfdecPlayer *player = SWFDEC_PLAYER (cx);
138 SWFDEC_AS_VALUE_SET_INT (ret, player->internal_width);
141 SWFDEC_AS_NATIVE (666, 7, get_height)
142 void
143 get_height (SwfdecAsContext *cx, SwfdecAsObject *object,
144 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
146 SwfdecPlayer *player = SWFDEC_PLAYER (cx);
148 SWFDEC_AS_VALUE_SET_INT (ret, player->internal_height);
151 /* FIXME: do this smarter */
152 SWFDEC_AS_NATIVE (666, 6, set_width)
153 void
154 set_width (SwfdecAsContext *cx, SwfdecAsObject *object,
155 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)
159 SWFDEC_AS_NATIVE (666, 8, set_height)
160 void
161 set_height (SwfdecAsContext *cx, SwfdecAsObject *object,
162 guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret)