Gnash  0.8.11dev
ShapeRecord.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 
20 #ifndef GNASH_SWF_SHAPERECORD_H
21 #define GNASH_SWF_SHAPERECORD_H
22 
23 #include "Geometry.h"
24 #include "LineStyle.h"
25 #include "FillStyle.h"
26 #include "SWFRect.h"
27 
28 #include <vector>
29 
30 
31 namespace gnash {
32  class movie_definition;
33  class RunResources;
34 }
35 
36 namespace gnash {
37 namespace SWF {
38 
39 
40 
41 class Subshape {
42 
43 public:
44  typedef std::vector<FillStyle> FillStyles;
45  typedef std::vector<LineStyle> LineStyles;
46  typedef std::vector<Path> Paths;
47 
48  const FillStyles& fillStyles() const {
49  return _fillStyles;
50  }
51 
53  return _fillStyles;
54  }
55 
56  const LineStyles& lineStyles() const {
57  return _lineStyles;
58  }
59 
61  return _lineStyles;
62  }
63 
64  const Paths& paths() const {
65  return _paths;
66  }
67 
68  Paths& paths() {
69  return _paths;
70  }
71 
73  //
77  return _paths.back();
78  }
79 
80  void addFillStyle(const FillStyle& fs);
81 
82  void addPath(const Path& path) {
83  _paths.push_back(path);
84  }
85 
86  void addLineStyle(const LineStyle& ls) {
87  _lineStyles.push_back(ls);
88  }
89 
90  void clear() {
91  _fillStyles.clear();
92  _lineStyles.clear();
93  _paths.clear();
94  }
95 
96  SWFRect computeBounds(int swfVersion) const;
97 
98 private:
99  FillStyles _fillStyles;
100  LineStyles _lineStyles;
101  Paths _paths;
102 };
103 
104 
105 
107 //
110 //
116 //
119 //
127 {
128 public:
132  typedef std::vector<Subshape> Subshapes;
133 
135  //
137  //
140  ShapeRecord();
141 
143  //
146  const RunResources& r);
147 
148 
149  ~ShapeRecord();
150 
152  //
155  void read(SWFStream& in, SWF::TagType tag, movie_definition& m,
156  const RunResources& r);
157 
158  const Subshapes& subshapes() const {
159  return _subshapes;
160  }
161 
162  void addSubshape(const Subshape& subshape) {
163  _subshapes.push_back(subshape);
164  }
165 
166  const SWFRect& getBounds() const {
167  return _bounds;
168  }
169 
171  //
173  void setLerp(const ShapeRecord& a, const ShapeRecord& b,
174  const double ratio);
175 
177  void clear();
178 
179  void setBounds(const SWFRect& bounds) {
180  _bounds = bounds;
181  }
182 
183  bool pointTest(std::int32_t x, std::int32_t y,
184  const SWFMatrix& wm) const {
185  for (const Subshape& subshape : _subshapes) {
186 
187  if (geometry::pointTest(subshape.paths(), subshape.lineStyles(), x, y, wm)) {
188  return true;
189  }
190  }
191  return false;
192  }
193 
194 private:
195 
196  unsigned readStyleChange(SWFStream& in, size_t num_fill_bits, size_t numStyles);
197 
199  enum ShapeRecordFlags {
200  SHAPE_END = 0x00,
201  SHAPE_MOVE = 0x01,
202  SHAPE_FILLSTYLE0_CHANGE = 0x02,
203  SHAPE_FILLSTYLE1_CHANGE = 0x04,
204  SHAPE_LINESTYLE_CHANGE = 0x08,
205  SHAPE_HAS_NEW_STYLES = 0x10
206  };
207 
208  SWFRect _bounds;
209  Subshapes _subshapes;
210 };
211 
212 std::ostream& operator<<(std::ostream& o, const ShapeRecord& sh);
213 
214 } // namespace SWF
215 } // namespace gnash
216 
217 #endif
gnash::SWF::ShapeRecord::pointTest
bool pointTest(std::int32_t x, std::int32_t y, const SWFMatrix &wm) const
Definition: ShapeRecord.h:183
path
VGPath path
Definition: testr_gtk.cpp:84
gnash::SWF::Subshape::clear
void clear()
Definition: ShapeRecord.h:90
gnash::SWF::Subshape::lineStyles
LineStyles & lineStyles()
Definition: ShapeRecord.h:60
gnash::Path::ap
point ap
Start point of the path.
Definition: Geometry.h:179
gnash::Path::size
size_t size() const
Return the number of edges in this path.
Definition: Geometry.h:517
gnash::SWFStream::ensureBits
void ensureBits(unsigned long needed)
Ensure the requested number of bits are available for a bitwise read in currently opened tag.
Definition: SWFStream.h:382
gnash::SWFStream::read_uint
unsigned read_uint(unsigned short bitcount)
Reads a bit-packed unsigned integer from the stream and returns it. The given bitcount determines the...
Definition: SWFStream.cpp:102
TypesParser.h
gnash::SWFStream::read_sint
int read_sint(unsigned short bitcount)
Reads a bit-packed little-endian signed integer from the stream. The given bitcount determines the nu...
Definition: SWFStream.cpp:191
gnash::log_swferror
void log_swferror(StringType msg, Args... args)
Definition: log.h:325
ShapeRecord.h
gnash::SWF::Subshape::computeBounds
SWFRect computeBounds(int swfVersion) const
Find the bounds of this subhape, and return them in a rectangle.
Definition: ShapeRecord.cpp:104
gnash::SWF::ShapeRecord::read
void read(SWFStream &in, SWF::TagType tag, movie_definition &m, const RunResources &r)
Parse path data from a SWFStream.
Definition: ShapeRecord.cpp:225
gnash::SWF::TagType
TagType
SWF tag types. Symbolic names copied from Ming.
Definition: SWF.h:31
gnash::Path::getLineStyle
unsigned getLineStyle() const
Definition: Geometry.h:511
gnash::Edge::ap
point ap
Definition: Geometry.h:50
gnash::SWF::operator<<
std::ostream & operator<<(std::ostream &o, const ShapeRecord &sh)
Definition: ShapeRecord.cpp:600
gnash::Path::getLeftFill
unsigned getLeftFill() const
Definition: Geometry.h:473
gnash::SWF::Subshape::fillStyles
const FillStyles & fillStyles() const
Definition: ShapeRecord.h:48
gnash::SWF::DEFINESHAPE
@ DEFINESHAPE
Definition: SWF.h:34
gnash::SWF::ShapeRecord::Subshapes
std::vector< Subshape > Subshapes
Definition: ShapeRecord.h:132
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
y
std::int32_t y
Definition: BitmapData_as.cpp:435
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::SWF::DEFINEFONT2
@ DEFINEFONT2
Definition: SWF.h:78
LOG_ONCE
#define LOG_ONCE(x)
Definition: log.h:49
gnash::SWF::Subshape::addFillStyle
void addFillStyle(const FillStyle &fs)
Definition: ShapeRecord.cpp:96
gnash::OptionalFillPair
std::pair< FillStyle, boost::optional< FillStyle > > OptionalFillPair
Either a single or a morph-pair FillStyle.
Definition: TypesParser.h:52
gnash::Path::empty
bool empty() const
Return true if this path contains no edges.
Definition: Geometry.h:454
_
#define _(String)
Definition: log.h:44
gnash::SWF::ShapeRecord::subshapes
const Subshapes & subshapes() const
Definition: ShapeRecord.h:158
gnash::SWFRect::expand_to_rect
DSOEXPORT void expand_to_rect(const SWFRect &r)
Makes union of the given and the current SWFRect.
Definition: SWFRect.cpp:56
Geometry.h
gnash::FillStyle
FillStyle describes the various fill styles for shapes.
Definition: FillStyle.h:282
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::SWF::ShapeRecord::getBounds
const SWFRect & getBounds() const
Definition: ShapeRecord.h:166
gnash::SWF::Subshape::paths
const Paths & paths() const
Definition: ShapeRecord.h:64
gnash::key::m
@ m
Definition: GnashKey.h:159
utility.h
gnash::SWF::Subshape::paths
Paths & paths()
Definition: ShapeRecord.h:68
gnash::Path::setRightFill
void setRightFill(unsigned f)
Set the fill to use on the left side.
Definition: Geometry.h:487
gnash::key::n
@ n
Definition: GnashKey.h:160
gnash::SWF::ShapeRecord::ShapeRecord
ShapeRecord()
Construct a ShapeRecord.
Definition: ShapeRecord.cpp:80
gnash::SWF::ShapeRecord::Paths
Subshape::Paths Paths
Definition: ShapeRecord.h:131
SWFRect.h
gnash::SWF::Subshape
Definition: ShapeRecord.h:41
UNUSED
#define UNUSED(x)
Definition: utility.h:113
gnash::movie_definition
Client program's interface to the definition of a movie or sprite.
Definition: movie_definition.h:96
gnash::SWF::Subshape::LineStyles
std::vector< LineStyle > LineStyles
Definition: ShapeRecord.h:45
gnash::Path::setLeftFill
void setLeftFill(unsigned f)
Set the fill to use on the left side.
Definition: Geometry.h:468
gnash::SWF::Subshape::lineStyles
const LineStyles & lineStyles() const
Definition: ShapeRecord.h:56
gnash::key::k
@ k
Definition: GnashKey.h:157
gnash::SWF::Subshape::Paths
std::vector< Path > Paths
Definition: ShapeRecord.h:46
IF_VERBOSE_MALFORMED_SWF
#define IF_VERBOSE_MALFORMED_SWF(x)
Definition: log.h:404
gnash::SWF::ShapeRecord::LineStyles
Subshape::LineStyles LineStyles
Definition: ShapeRecord.h:130
gnash::SWFRect
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:45
gnash::key::r
@ r
Definition: GnashKey.h:164
gnash::SWF::ShapeRecord::FillStyles
Subshape::FillStyles FillStyles
Definition: ShapeRecord.h:129
gnash::renderer::opengl::for_each
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
gnash::Path::getRightFill
unsigned getRightFill() const
Definition: Geometry.h:492
gnash::key::a
@ a
Definition: GnashKey.h:147
gnash::geometry::Point2d::x
std::int32_t x
The x coordinate.
Definition: Point2d.h:43
gnash::Path::drawLineTo
void drawLineTo(std::int32_t dx, std::int32_t dy)
Draw a straight line.
Definition: Geometry.h:325
gnash::SWF::Subshape::FillStyles
std::vector< FillStyle > FillStyles
Definition: ShapeRecord.h:44
gnash::SWF::DEFINESHAPE2
@ DEFINESHAPE2
Definition: SWF.h:54
gnash::Path
A subset of a shape, a series of edges sharing a single set of styles.
Definition: Geometry.h:167
gnash::LineStyle
For the outside of outline shapes, or just bare lines.
Definition: LineStyle.h:51
gnash::SWF::DEFINESHAPE4_
@ DEFINESHAPE4_
Definition: SWF.h:97
gnash::SWF::ShapeRecord::addSubshape
void addSubshape(const Subshape &subshape)
Definition: ShapeRecord.h:162
gnash::key::p
@ p
Definition: GnashKey.h:162
gnash::setLerp
void setLerp(FillStyle &f, const FillStyle &a, const FillStyle &b, double t)
Set the FillStyle to a lerp of a and b.
Definition: FillStyle.cpp:221
gnash::SWF::Subshape::fillStyles
FillStyles & fillStyles()
Definition: ShapeRecord.h:52
GnashNumeric.h
gnash::RunResources
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:54
gnash::SWFMatrix
Definition: SWFMatrix.h:54
gnash::SWFRect::set_lerp
void set_lerp(const SWFRect &a, const SWFRect &b, float t)
Definition: SWFRect.cpp:107
gnash::SWF::DEFINEFONT3
@ DEFINEFONT3
Definition: SWF.h:105
gnash::key::j
@ j
Definition: GnashKey.h:156
gnash::SWF::Subshape::currentPath
Path & currentPath()
For DynamicShape.
Definition: ShapeRecord.h:76
gnash::geometry::pointTest
bool pointTest(const std::vector< Path > &paths, const std::vector< LineStyle > &lineStyles, std::int32_t x, std::int32_t y, const SWFMatrix &wm)
Definition: Geometry.cpp:125
IF_VERBOSE_PARSE
#define IF_VERBOSE_PARSE(x)
Definition: log.h:378
gnash::readFills
OptionalFillPair readFills(SWFStream &in, SWF::TagType t, movie_definition &md, bool readMorph)
Read FillStyles from a stream.
Definition: TypesParser.cpp:161
gnash::log_parse
void log_parse(StringType msg, Args... args)
Definition: log.h:313
log.h
gnash::SWF::DEFINESHAPE4
@ DEFINESHAPE4
Definition: SWF.h:110
gnash::SWF::Subshape::addPath
void addPath(const Path &path)
Definition: ShapeRecord.h:82
gnash::image::end
pixel_iterator< T > end(GnashImage &im)
Definition: ImageIterators.h:198
SWF.h
gnash::SWFStream::read_u16
std::uint16_t read_u16()
Read a aligned unsigned 16-bit value from the stream.
Definition: SWFStream.cpp:332
LineStyle.h
gnash::SWF::DEFINESHAPE3
@ DEFINESHAPE3
Definition: SWF.h:62
gnash::Path::setLineStyle
void setLineStyle(unsigned i)
Set the line style to use for this path.
Definition: Geometry.h:506
gnash::Edge::cp
point cp
Definition: Geometry.h:49
gnash::SWFStream::read_u8
std::uint8_t read_u8()
Read a aligned unsigned 8-bit value from the stream.
Definition: SWFStream.cpp:319
gnash::SWFStream::read_bit
bool read_bit()
Reads a single bit off the stream and returns it.
Definition: SWFStream.cpp:88
gnash::geometry::Point2d::y
std::int32_t y
The y coordinate.
Definition: Point2d.h:46
movie_definition.h
gnash::SWF::ShapeRecord
Holds information needed to draw a shape.
Definition: ShapeRecord.h:127
gnash::SWFStream
SWF stream wrapper class.
Definition: SWFStream.h:59
FillStyle.h
gnash::readRect
SWFRect readRect(SWFStream &in)
Read a bit-packed rectangle from an SWF stream.
Definition: TypesParser.cpp:130
gnash::Edge
Defines an edge with a control point and an anchor point.
Definition: Geometry.h:45
gnash::SWFStream::ensureBytes
void ensureBytes(unsigned long needed)
Ensure the requested number of bytes are available for an aligned read in the currently opened tag.
Definition: SWFStream.cpp:50
gnash::key::o
@ o
Definition: GnashKey.h:161
gnash::key::SWF
@ SWF
Definition: GnashKey.h:331
gnash::log_unimpl
void log_unimpl(StringType msg, Args... args)
Definition: log.h:289
gnash::Path::m_edges
std::vector< Edge > m_edges
Edges forming the path.
Definition: Geometry.h:182
gnash::SWFRect::toString
std::string toString() const
Return a string representation for this rectangle.
Definition: SWFRect.cpp:128
gnash::Path::clear
void clear()
Remove all edges and reset style infomation.
Definition: Geometry.h:354
gnash::Path::drawCurveTo
void drawCurveTo(std::int32_t cdx, std::int32_t cdy, std::int32_t adx, std::int32_t ady)
Draw a curve.
Definition: Geometry.h:348
x
std::int32_t x
Definition: BitmapData_as.cpp:434
gnash::SWF::Subshape::addLineStyle
void addLineStyle(const LineStyle &ls)
Definition: ShapeRecord.h:86
SWFStream.h
gnash::key::b
@ b
Definition: GnashKey.h:148
gnash::SWF::ShapeRecord::setLerp
void setLerp(const ShapeRecord &a, const ShapeRecord &b, const double ratio)
Set to the lerp of two ShapeRecords.
Definition: ShapeRecord.cpp:132
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::SWF::ShapeRecord::~ShapeRecord
~ShapeRecord()
Definition: ShapeRecord.cpp:84
gnash::SWF::ShapeRecord::setBounds
void setBounds(const SWFRect &bounds)
Definition: ShapeRecord.h:179
gnash::SWFRect::set_null
void set_null()
set the rectangle to the NULL value
Definition: SWFRect.h:81
gnash::SWF::DEFINEFONT
@ DEFINEFONT
Definition: SWF.h:42
gnash::SWF::ShapeRecord::clear
void clear()
Reset all shape data.
Definition: ShapeRecord.cpp:89