1 /*
2 Ming, an SWF output library
3 Copyright (C) 2002 Opaque Industries - http://www.opaque.net/
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 /* $Id$ */
21
22 #include <stdlib.h>
23
24 #include "character.h"
25 #include "blocktypes.h"
26 #include "morph.h"
27 #include "libming.h"
28
29
30 int SWF_gNumCharacters;
31
32
33 void
SWFCharacterInit(SWFCharacter character)34 SWFCharacterInit(SWFCharacter character)
35 {
36 SWFBlockInit((SWFBlock)character);
37
38 character->id = 0;
39 character->bounds = NULL;
40
41 character->dependencies = NULL;
42 character->nDependencies = 0;
43
44 character->isFinished = FALSE;
45
46 character->onPlace = NULL;
47 character->onFrame = NULL;
48 }
49
50
51 void
destroySWFCharacter(SWFCharacter character)52 destroySWFCharacter(SWFCharacter character)
53 {
54 if ( character->dependencies != NULL )
55 free(character->dependencies);
56
57 if ( character->bounds != NULL )
58 destroySWFRect(character->bounds);
59
60 // destroySWFBlock((SWFBlock)character);
61
62 free(character);
63 }
64
65
66 void
SWFCharacter_addDependency(SWFCharacter character,SWFCharacter dependency)67 SWFCharacter_addDependency(SWFCharacter character, SWFCharacter dependency)
68 {
69 #if 1
70 int n;
71 for(n = 0 ; n < character->nDependencies ; n++)
72 if(character->dependencies[n] == dependency)
73 return;
74 #endif
75 character->dependencies =
76 (SWFCharacter*)realloc(character->dependencies,
77 sizeof(SWFCharacter) * (character->nDependencies + 1));
78
79 character->dependencies[character->nDependencies] = dependency;
80 ++character->nDependencies;
81 }
82
83
SWFCharacter_setID(SWFCharacter character,int id)84 void SWFCharacter_setID(SWFCharacter character, int id)
85 {
86 character->id = id;
87 }
88
89
SWFCharacter_getID(SWFCharacter character)90 int SWFCharacter_getID(SWFCharacter character)
91 {
92 return character->id;
93 }
94
95
96 BOOL
SWFCharacter_getDependencies(SWFCharacter character,SWFCharacter ** depsPtr,int * nDepsPtr)97 SWFCharacter_getDependencies(SWFCharacter character,
98 SWFCharacter** depsPtr, int* nDepsPtr)
99 {
100 int i;
101 int nDeps = *nDepsPtr;
102 SWFCharacter* deps = *depsPtr;
103
104 if ( BLOCK(character)->type == SWF_DEFINEMORPHSHAPE )
105 character = (SWFCharacter)SWFMorph_getShape1((SWFMorph)character);
106
107 for ( i = 0; i < character->nDependencies; ++i )
108 {
109 SWFCharacter c = character->dependencies[i];
110
111 if ( !SWFBlock_isDefined((SWFBlock)c) )
112 {
113 deps = (SWFCharacter*) realloc(deps, sizeof(SWFCharacter) * (nDeps + 1));
114 deps[nDeps] = c;
115 ++nDeps;
116 }
117 }
118
119 if ( nDeps == *nDepsPtr )
120 return FALSE;
121
122 *depsPtr = deps;
123 *nDepsPtr = nDeps;
124
125 return TRUE;
126 }
127
128
129 int
SWFCharacter_getScaledWidth(SWFCharacter character)130 SWFCharacter_getScaledWidth(SWFCharacter character)
131 {
132 return SWFRect_getWidth(character->bounds);
133 }
134
135
136 int
SWFCharacter_getScaledHeight(SWFCharacter character)137 SWFCharacter_getScaledHeight(SWFCharacter character)
138 {
139 return SWFRect_getHeight(character->bounds);
140 }
141
142
143 SWFRect
SWFCharacter_getBounds(SWFCharacter character)144 SWFCharacter_getBounds(SWFCharacter character)
145 {
146 return character->bounds;
147 }
148
149
150 /* rather, should it go on the display list..
151 "character" is a bit of a sloppy category now */
152
153 BOOL
SWFBlock_isCharacter(SWFBlock block)154 SWFBlock_isCharacter(SWFBlock block)
155 {
156 SWFBlocktype type = block->type;
157
158 if ( type == SWF_DEFINETEXT || type == SWF_DEFINETEXT2 ||
159 type == SWF_DEFINESHAPE || type == SWF_DEFINESHAPE2 ||
160 type == SWF_DEFINESHAPE3 || type == SWF_DEFINESHAPE4 ||
161 type == SWF_DEFINEMORPHSHAPE ||
162 type == SWF_DEFINESPRITE || type == SWF_DEFINEBUTTON ||
163 type == SWF_DEFINEBUTTON2 || type == SWF_DEFINETEXT2 ||
164 type == SWF_DEFINEBITS ||
165 type == SWF_DEFINEBITSJPEG2 ||
166 type == SWF_DEFINEBITSJPEG3 ||
167 type == SWF_DEFINELOSSLESS ||
168 type == SWF_DEFINELOSSLESS2 ||
169 type == SWF_DEFINEFONT || type == SWF_DEFINEFONT2 ||
170 type == SWF_DEFINEEDITTEXT ||
171 type == SWF_DEFINEVIDEOSTREAM ||
172 type == SWF_PREBUILTCLIP ||
173 type == SWF_DEFINESOUND ||
174 type == SWF_BROWSERFONT)
175 {
176 return TRUE;
177 }
178 else
179 return FALSE;
180 }
181
182
183 void
SWFCharacter_setFinished(SWFCharacter character)184 SWFCharacter_setFinished(SWFCharacter character)
185 {
186 character->isFinished = TRUE;
187 }
188
189
190 BOOL
SWFCharacter_isFinished(SWFCharacter character)191 SWFCharacter_isFinished(SWFCharacter character)
192 {
193 return character->isFinished;
194 }
195
196
197 /*
198 * Local variables:
199 * tab-width: 2
200 * c-basic-offset: 2
201 * End:
202 */
203