remove revno.h for distclean
[gnash.git] / libcore / swf / ShapeRecord.h
blobe6b9a8aaa814da550277c1ae2b3c743e88b88c7f
1 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
2 // Foundation, Inc
3 //
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.
8 //
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.
13 //
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
22 #include "Geometry.h"
23 #include "LineStyle.h"
24 #include "SWFRect.h"
26 #include <vector>
29 namespace gnash {
30 class movie_definition;
31 class RunResources;
32 class FillStyle;
35 namespace gnash {
36 namespace SWF {
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.
51 class ShapeRecord
53 public:
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.
65 ShapeRecord();
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);
73 /// Copy constructor
74 ShapeRecord(const ShapeRecord& other);
76 /// Assignment operator
77 ShapeRecord& operator=(const ShapeRecord& other);
79 ~ShapeRecord();
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 {
89 return _fillStyles;
92 const LineStyles& lineStyles() const {
93 return _lineStyles;
96 const Paths& paths() const {
97 return _paths;
100 const SWFRect& getBounds() const {
101 return _bounds;
104 /// For DynamicShape
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,
116 const double ratio);
118 /// Reset all shape data.
119 void clear();
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) {
132 _bounds = bounds;
135 private:
137 /// Shape record flags for use in parsing.
138 enum ShapeRecordFlags {
139 SHAPE_END = 0x00,
140 SHAPE_MOVE = 0x01,
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;
149 Paths _paths;
150 SWFRect _bounds;
154 std::ostream& operator<<(std::ostream& o, const ShapeRecord& sh);
156 } // namespace SWF
157 } // namespace gnash
159 #endif