Gnash  0.8.11dev
DynamicShape.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 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 
21 #ifndef GNASH_DYNAMIC_SHAPE_H
22 #define GNASH_DYNAMIC_SHAPE_H
23 
24 #include "LineStyle.h"
25 #include "ShapeRecord.h"
26 
27 namespace gnash {
28  class DisplayObject;
29  class Renderer;
30  class FillStyle;
31  class GradientRecord;
32  class Transform;
33 }
34 
35 namespace gnash {
36 
38 //
41 //
45 {
46 public:
47 
48  DynamicShape();
49 
51 
53  void clear();
54 
56  void moveTo(std::int32_t x, std::int32_t y);
57 
59  void lineTo(std::int32_t x, std::int32_t y, int swfVersion);
60 
64  void curveTo(std::int32_t cx, std::int32_t cy,
65  std::int32_t ax, std::int32_t ay, int swfVersion);
66 
68  void beginFill(const FillStyle& f);
69 
71  void endFill();
72 
73  const SWFRect& getBounds() const {
74  return _shape.getBounds();
75  }
76 
77  void setBounds(const SWFRect& bounds) {
78  _shape.setBounds(bounds);
79  }
80 
82  void display(Renderer& renderer, const Transform& xform) const;
83 
85  //
95  void lineStyle(std::uint16_t thickness, const rgba& color,
96  bool vScale=true, bool hScale=true,
97  bool pixelHinting=false,
98  bool noClose=false,
99  CapStyle startCapStyle=CAP_ROUND,
100  CapStyle endCapStyle=CAP_ROUND,
101  JoinStyle joinStyle=JOIN_ROUND,
102  float miterLimitFactor=1.0f);
103 
105  void resetLineStyle();
106 
110  //
116  size_t addFillStyle(const FillStyle& stl);
117 
121  //
127  size_t add_line_style(const LineStyle& stl);
128 
129  // Override from DefineShapeTag to call ::finalize
130  // NOTE: this is not correct in that a call to hitTest should
131  // not force closing the path being drawn.
132  // Instead, the closeup should be "temporary" and in
133  // the pointTestLocal itself (but only for dynamic drawing).
134  // We need to add a testcase for this as we currently have none.
135  // The testcase would look like this:
136  //
137  // moveTo(0, 0); lineTo(10, 0); lineTo(10, 10); // an L shape so far
138  // hitTest(8, 2, true); !hitTest(2, 8, true); // imaginarly forming a closed triangle as hitTest is concerned
139  // lineTo(0, 10); lineTo(0, 0); // explicitly closed as a square now
140  // hitTest(8, 2, true); hitTest(2, 8, true); // effectively forming a closed square
141  //
142  // In the test above, permanently closing on hit-test (what this implementation does)
143  // would result in a triangle and a stroke, which should fail the last hitTest(2,8).
144  //
145  //
146  bool pointTestLocal(std::int32_t x, std::int32_t y,
147  const SWFMatrix& wm) const
148  {
149  finalize();
150  return _shape.pointTest(x, y, wm);
151  }
152 
153  const SWF::ShapeRecord& shapeRecord() const {
154  return _shape;
155  }
156 
158  //
163  void add_path(const Path& pth);
164 
166  //
169  void finalize() const;
170 
171 private:
172 
174  //
181  void startNewPath(bool newShape);
182 
183 
184 
185  Path* _currpath;
186 
187  size_t _currfill;
188 
189  size_t _currline;
190 
191  // Current pen X position
192  std::int32_t _x;
193 
194  // Current pen Y position
195  std::int32_t _y;
196 
197  mutable bool _changed;
198 
199  mutable SWF::Subshape _currsubshape;
200 
202  //
204  mutable SWF::ShapeRecord _shape;
205 };
206 
207 } // end namespace gnash
208 
209 
210 #endif // GNASH_DYNAMIC_SHAPE_H
211 
212 
213 // Local Variables:
214 // mode: C++
215 // c-basic-offset: 8
216 // tab-width: 8
217 // indent-tabs-mode: t
218 // End:
gnash::SWF::ShapeRecord::pointTest
bool pointTest(std::int32_t x, std::int32_t y, const SWFMatrix &wm) const
Definition: ShapeRecord.h:183
gnash::LogFile::getDefaultInstance
static LogFile & getDefaultInstance()
Definition: log.cpp:77
optind
int optind
gnash::DynamicShape::moveTo
void moveTo(std::int32_t x, std::int32_t y)
Move pen to given coordinates.
Definition: DynamicShape.cpp:184
gnash::SWF::Subshape::clear
void clear()
Definition: ShapeRecord.h:90
gnash::DynamicShape::addFillStyle
size_t addFillStyle(const FillStyle &stl)
Add a fill style, possibly reusing an existing one if existent.
Definition: DynamicShape.cpp:261
gnash::DynamicShape::add_line_style
size_t add_line_style(const LineStyle &stl)
Add a line style, possibly reusing an existing one if existent.
Definition: DynamicShape.cpp:268
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
LINELEN
const int LINELEN
Definition: dumpshm.cpp:96
gnash::DynamicShape::~DynamicShape
~DynamicShape()
Definition: DynamicShape.h:50
list_lcs
key_t list_lcs()
gnash::SWFRect::expand_to_circle
void expand_to_circle(std::int32_t x, std::int32_t y, std::int32_t radius)
Expand this rectangle to enclose the given circle.
Definition: SWFRect.h:186
DynamicShape.h
gnash::DynamicShape::clear
void clear()
Remove all paths and style informations.
Definition: DynamicShape.cpp:39
ShapeRecord.h
gnash::DynamicShape::add_path
void add_path(const Path &pth)
Add a path, updating _currpath and recomputing bounds.
Definition: DynamicShape.cpp:55
gnash::DynamicShape::finalize
void finalize() const
Always call this function before displaying !
Definition: DynamicShape.cpp:139
dump_ctrl
void dump_ctrl(void *ptr)
Dumps the internal data of the found ShmControl block. We do our own dumping, rather than letting Shm...
Definition: dumpshm.cpp:356
gnash::SWF::Subshape::fillStyles
const FillStyles & fillStyles() const
Definition: ShapeRecord.h:48
dbglogfile
#define dbglogfile
Definition: gtkext.cpp:48
gnash::DynamicShape::DynamicShape
DynamicShape()
Definition: DynamicShape.cpp:28
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::LogFile
Definition: log.h:64
gnash::SWF::Subshape::addFillStyle
void addFillStyle(const FillStyle &fs)
Definition: ShapeRecord.cpp:96
gnash::rgba
A basic RGBA type.
Definition: RGBA.h:36
rc.h
_
#define _(String)
Definition: log.h:44
Renderer.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
PIDSTART
const int PIDSTART
Definition: dumpshm.cpp:94
gnash::SWF::Subshape::paths
const Paths & paths() const
Definition: ShapeRecord.h:64
gnash::Renderer
Base class for render handlers.
Definition: Renderer.h:189
boost
Definition: gui.h:74
PACKAGE
#define PACKAGE
Definition: gnashconfig.h:556
gnash::Path::close
void close()
Close this path with a straight line, if not already closed.
Definition: Geometry.h:371
dump_shm
void dump_shm(bool convert, bool out)
Definition: dumpshm.cpp:222
gnash::DynamicShape::pointTestLocal
bool pointTestLocal(std::int32_t x, std::int32_t y, const SWFMatrix &wm) const
Definition: DynamicShape.h:146
SHM_INFO
const int SHM_INFO
Definition: dumpshm.cpp:102
DUMPSHM_VERSION
const char * DUMPSHM_VERSION
Definition: dumpshm.cpp:110
gnash::SWF::Subshape
Definition: ShapeRecord.h:41
gnash::SWF::Subshape::lineStyles
const LineStyles & lineStyles() const
Definition: ShapeRecord.h:56
gnash::DynamicShape::display
void display(Renderer &renderer, const Transform &xform) const
Display a DynamicShape object.
Definition: DynamicShape.cpp:49
gnash::SWFRect
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:45
bindtextdomain
#define bindtextdomain(Domainname, Dirname)
Definition: gettext.h:66
gnash::DynamicShape::endFill
void endFill()
Close an existing filled path, if any.
Definition: DynamicShape.cpp:63
color
const VGfloat color[4]
Definition: testr_gtk.cpp:82
gnash::amf::write
void write(SimpleBuffer &buf, const std::string &str)
Write a string to an AMF buffer.
Definition: AMF.cpp:161
textdomain
#define textdomain(Domainname)
Definition: gettext.h:65
gnash::geometry::Point2d::x
std::int32_t x
The x coordinate.
Definition: Point2d.h:43
gnash::CAP_ROUND
@ CAP_ROUND
Definition: LineStyle.h:38
gnash::Path::drawLineTo
void drawLineTo(std::int32_t dx, std::int32_t dy)
Draw a straight line.
Definition: Geometry.h:325
gnash::DynamicShape::lineStyle
void lineStyle(std::uint16_t thickness, const rgba &color, bool vScale=true, bool hScale=true, bool pixelHinting=false, bool noClose=false, CapStyle startCapStyle=CAP_ROUND, CapStyle endCapStyle=CAP_ROUND, JoinStyle joinStyle=JOIN_ROUND, float miterLimitFactor=1.0f)
Set current line style and start a new path.
Definition: DynamicShape.cpp:163
PIDEND
const int PIDEND
Definition: dumpshm.cpp:95
gnash::DynamicShape
The DynamicShape class represents a mutable shape.
Definition: DynamicShape.h:45
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::ShapeRecord::addSubshape
void addSubshape(const Subshape &subshape)
Definition: ShapeRecord.h:162
gnash::DynamicShape::lineTo
void lineTo(std::int32_t x, std::int32_t y, int swfVersion)
Draw a straight line from current position to given one.
Definition: DynamicShape.cpp:196
GnashSystemIOHeaders.h
gnash::JOIN_ROUND
@ JOIN_ROUND
Definition: LineStyle.h:44
gnash::SWFMatrix
Definition: SWFMatrix.h:54
main
int main(int argc, char *argv[])
Definition: dumpshm.cpp:113
gnash::SWF::Subshape::currentPath
Path & currentPath()
For DynamicShape.
Definition: ShapeRecord.h:76
DisplayObject.h
log.h
gnash::Renderer::drawShape
virtual void drawShape(const SWF::ShapeRecord &shape, const Transform &xform)=0
gnash::CapStyle
CapStyle
Definition: LineStyle.h:37
gnash::SWF::Subshape::addPath
void addPath(const Path &path)
Definition: ShapeRecord.h:82
gnash::key::f
@ f
Definition: GnashKey.h:152
gnash::DynamicShape::curveTo
void curveTo(std::int32_t cx, std::int32_t cy, std::int32_t ax, std::int32_t ay, int swfVersion)
Draw a curve from current position to given one using given control points.
Definition: DynamicShape.cpp:227
gnashconfig.h
gnash::RcInitFile::getDefaultInstance
static RcInitFile & getDefaultInstance()
Return the default instance of RC file.
Definition: rc.cpp:61
gnash::key::c
@ c
Definition: GnashKey.h:149
gnash::DynamicShape::resetLineStyle
void resetLineStyle()
Reset line style to no style and start a new path.
Definition: DynamicShape.cpp:177
LineStyle.h
gnash::DynamicShape::setBounds
void setBounds(const SWFRect &bounds)
Definition: DynamicShape.h:77
gnash::JoinStyle
JoinStyle
Definition: LineStyle.h:43
gnash::DynamicShape::getBounds
const SWFRect & getBounds() const
Definition: DynamicShape.h:73
VERSION
#define VERSION
Definition: gnashconfig.h:731
gnash::geometry::Point2d::y
std::int32_t y
The y coordinate.
Definition: Point2d.h:46
gnash::DynamicShape::beginFill
void beginFill(const FillStyle &f)
Start drawing with a solid fill.
Definition: DynamicShape.cpp:98
getopt
int getopt(int, char *const *, const char *)
gnash::SWF::ShapeRecord
Holds information needed to draw a shape.
Definition: ShapeRecord.h:127
SHM_STAT
const int SHM_STAT
Definition: dumpshm.cpp:101
optarg
char * optarg
LOOPCNT
const unsigned int LOOPCNT
Definition: dumpshm.cpp:97
gnash::DynamicShape::shapeRecord
const SWF::ShapeRecord & shapeRecord() const
Definition: DynamicShape.h:153
FillStyle.h
gnash::Transform
The Transform class expresses a stage in a cumulative transformation.
Definition: Transform.h:34
gnash::Path::expandBounds
void expandBounds(SWFRect &r, unsigned int thickness, int swfVersion) const
Expand given SWFRect to include bounds of this path.
Definition: Geometry.h:276
gnash::hexify
std::string hexify(const unsigned char *p, size_t length, bool ascii)
Convert a sequence of bytes to hex or ascii format.
Definition: log.cpp:48
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
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::SWF::ShapeRecord::setBounds
void setBounds(const SWFRect &bounds)
Definition: ShapeRecord.h:179
gnash::RcInitFile
Definition: rc.h:44
DEFAULT_SHM_SIZE
const int DEFAULT_SHM_SIZE
Definition: dumpshm.cpp:98
gnash::SWF::ShapeRecord::clear
void clear()
Reset all shape data.
Definition: ShapeRecord.cpp:89