1 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program 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
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef GNASH_SWF_SHAPERECORD_H
20 #define GNASH_SWF_SHAPERECORD_H
23 #include "LineStyle.h"
30 class movie_definition
;
38 /// Holds information needed to draw a shape.
40 /// This does not correspond exactly to parsed record in a SWF file, but
41 /// is used to create both mutable and immutable shapes.
43 /// A ShapeRecord should have enough methods to implement the AS3 Graphics
44 /// object (the drawing API of Shape and Sprite). This is restricted to
45 /// adding fills, paths and line styles (which must be constructed outside
46 /// this ShapeRecord before being added) and clearing everything. There
47 /// is no support for removing single elements.
49 /// ShapeRecord objects are not ref-counted, so they may be stack-allocated
50 /// or used in smart pointers.
55 typedef std::vector
<FillStyle
> FillStyles
;
56 typedef std::vector
<LineStyle
> LineStyles
;
57 typedef std::vector
<Path
> Paths
;
59 /// Construct a ShapeRecord.
61 /// This should only really be used for DynamicShapes.
63 /// Ideally all immutable ShapeRecords should be constructed with the
64 /// ctor taking an SWFStream, but some tag formats do not allow this.
67 /// Construct a ShapeRecord from a SWFStream.
69 /// This is useful for constructing immutable tags.
70 ShapeRecord(SWFStream
& in
, SWF::TagType tag
, movie_definition
& m
,
71 const RunResources
& r
);
74 ShapeRecord(const ShapeRecord
& other
);
76 /// Assignment operator
77 ShapeRecord
& operator=(const ShapeRecord
& other
);
81 /// Parse path data from a SWFStream.
83 /// This is used by DefineMorphShapeTag as part of parsing its
84 /// more complex ShapeRecords.
85 void read(SWFStream
& in
, SWF::TagType tag
, movie_definition
& m
,
86 const RunResources
& r
);
88 const FillStyles
& fillStyles() const {
92 const LineStyles
& lineStyles() const {
96 const Paths
& paths() const {
100 const SWFRect
& getBounds() const {
106 /// TODO: rewrite DynamicShape to push paths when they're
107 /// finished and drop this.
108 Path
& currentPath() {
109 return _paths
.back();
112 /// Set to the lerp of two ShapeRecords.
114 /// Used in shape morphing.
115 void setLerp(const ShapeRecord
& a
, const ShapeRecord
& b
,
118 /// Reset all shape data.
121 void addFillStyle(const FillStyle
& fs
);
123 void addPath(const Path
& path
) {
124 _paths
.push_back(path
);
127 void addLineStyle(const LineStyle
& ls
) {
128 _lineStyles
.push_back(ls
);
131 void setBounds(const SWFRect
& bounds
) {
137 /// Shape record flags for use in parsing.
138 enum ShapeRecordFlags
{
141 SHAPE_FILLSTYLE0_CHANGE
= 0x02,
142 SHAPE_FILLSTYLE1_CHANGE
= 0x04,
143 SHAPE_LINESTYLE_CHANGE
= 0x08,
144 SHAPE_HAS_NEW_STYLES
= 0x10
147 FillStyles _fillStyles
;
148 LineStyles _lineStyles
;
154 std::ostream
& operator<<(std::ostream
& o
, const ShapeRecord
& sh
);