1 // sprite_definition.cpp: for Gnash.
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011 Free Software Foundation, Inc
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "RunResources.h"
21 #include "smart_ptr.h"
22 #include "MovieClip.h"
23 #include "sprite_definition.h"
24 #include "ControlTag.h" // for dtor visibility
25 #include "as_function.h"
26 #include "SWFStream.h"
27 #include "GnashAlgorithm.h"
28 #include "SWFParser.h"
29 #include "namedStrings.h"
30 #include "Global_as.h"
40 sprite_definition::createDisplayObject(Global_as
& gl
, DisplayObject
* parent
)
43 // Should not call MovieClip constructor (probably), but should
44 // attach MovieClip.prototype
45 as_object
* obj
= getObjectWithPrototype(gl
, NSV::CLASS_MOVIE_CLIP
);
46 DisplayObject
* mc
= new MovieClip(obj
, this, parent
->get_root(), parent
);
50 sprite_definition::~sprite_definition()
55 // only called from constructors
57 sprite_definition::read(SWFStream
& in
, const RunResources
& runResources
)
59 const size_t tag_end
= in
.get_tag_end_position();
62 m_frame_count
= in
.read_u16();
65 log_parse(_(" frames = %d"), m_frame_count
);
70 SWFParser
parser(in
, this, runResources
);
72 // This can throw a ParserException; we will let the SWFMovieDefintion
73 // catch it, as a failure means the whole stream is invalid.
74 parser
.read(tag_end
- in
.tell());
76 if (m_frame_count
> m_loading_frame
) {
77 IF_VERBOSE_MALFORMED_SWF(
78 log_swferror(_("%d frames advertised in header, but "
79 "only %d SHOWFRAME tags found in define "
80 "sprite."), m_frame_count
, m_loading_frame
);
83 // this should be safe
84 m_loading_frame
= m_frame_count
;
88 log_parse(_(" -- sprite END --"));
93 sprite_definition::add_frame_name(const std::string
& name
)
96 // It's fine for loaded frames to exceed frame count. Should be
97 // adjusted at the end of parsing.
98 _namedFrames
.insert(std::make_pair(name
, m_loading_frame
));
102 sprite_definition::get_labeled_frame(const std::string
& label
,
103 size_t& frame_number
) const
105 NamedFrameMap::const_iterator it
= _namedFrames
.find(label
);
106 if ( it
== _namedFrames
.end() ) return false;
107 frame_number
= it
->second
;
111 sprite_definition::sprite_definition(movie_definition
& m
, SWFStream
& in
,
112 const RunResources
& runResources
, boost::uint16_t id
)
114 movie_definition(id
),
119 _loadingSoundStream(-1)
121 read(in
, runResources
);
125 sprite_definition::registerClass(as_function
* the_class
)
127 registeredClass
= the_class
;
131 sprite_definition::markReachableResources() const
133 if (registeredClass
) registeredClass
->setReachable();