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:
DynamicShape()
Definition: DynamicShape.cpp:28
Definition: SWFMatrix.h:53
size_t addFillStyle(const FillStyle &stl)
Add a fill style, possibly reusing an existing one if existent.
Definition: DynamicShape.cpp:261
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
void setBounds(const SWFRect &bounds)
Definition: DynamicShape.h:77
const SWFRect & getBounds() const
Definition: DynamicShape.h:73
void add_path(const Path &pth)
Add a path, updating _currpath and recomputing bounds.
Definition: DynamicShape.cpp:55
Definition: GnashKey.h:152
Definition: ShapeRecord.h:41
Base class for render handlers.
Definition: Renderer.h:188
const VGfloat color[4]
Definition: testr_gtk.cpp:82
The DynamicShape class represents a mutable shape.
Definition: DynamicShape.h:44
bool pointTestLocal(std::int32_t x, std::int32_t y, const SWFMatrix &wm) const
Definition: DynamicShape.h:146
void moveTo(std::int32_t x, std::int32_t y)
Move pen to given coordinates.
Definition: DynamicShape.cpp:184
size_t add_line_style(const LineStyle &stl)
Add a line style, possibly reusing an existing one if existent.
Definition: DynamicShape.cpp:268
void beginFill(const FillStyle &f)
Start drawing with a solid fill.
Definition: DynamicShape.cpp:98
FillStyle describes the various fill styles for shapes.
Definition: FillStyle.h:281
A subset of a shape, a series of edges sharing a single set of styles.
Definition: Geometry.h:166
~DynamicShape()
Definition: DynamicShape.h:50
std::int32_t x
Definition: BitmapData_as.cpp:434
bool pointTest(std::int32_t x, std::int32_t y, const SWFMatrix &wm) const
Definition: ShapeRecord.h:183
Definition: LineStyle.h:44
void setBounds(const SWFRect &bounds)
Definition: ShapeRecord.h:179
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
For the outside of outline shapes, or just bare lines.
Definition: LineStyle.h:50
std::int32_t y
Definition: BitmapData_as.cpp:435
Rectangle class, see swf defined rectangle record.
Definition: SWFRect.h:44
void resetLineStyle()
Reset line style to no style and start a new path.
Definition: DynamicShape.cpp:177
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
void display(Renderer &renderer, const Transform &xform) const
Display a DynamicShape object.
Definition: DynamicShape.cpp:49
const SWFRect & getBounds() const
Definition: ShapeRecord.h:166
JoinStyle
Definition: LineStyle.h:43
void finalize() const
Always call this function before displaying !
Definition: DynamicShape.cpp:139
const SWF::ShapeRecord & shapeRecord() const
Definition: DynamicShape.h:153
void clear()
Remove all paths and style informations.
Definition: DynamicShape.cpp:39
Holds information needed to draw a shape.
Definition: ShapeRecord.h:126
CapStyle
Definition: LineStyle.h:37
Definition: LineStyle.h:38
The Transform class expresses a stage in a cumulative transformation.
Definition: Transform.h:33
void endFill()
Close an existing filled path, if any.
Definition: DynamicShape.cpp:63
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
A basic RGBA type.
Definition: RGBA.h:35