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 <vector>
25 #include "LineStyle.h"
26 #include "ShapeRecord.h"
27 
28 namespace gnash {
29  class DisplayObject;
30  class Renderer;
31  class FillStyle;
32  class GradientRecord;
33  class Transform;
34 }
35 
36 namespace gnash {
37 
39 //
42 //
46 {
47 public:
48 
49  DynamicShape();
50 
52 
54  void clear();
55 
57  void moveTo(boost::int32_t x, boost::int32_t y);
58 
60  void lineTo(boost::int32_t x, boost::int32_t y, int swfVersion);
61 
65  void curveTo(boost::int32_t cx, boost::int32_t cy,
66  boost::int32_t ax, boost::int32_t ay, int swfVersion);
67 
69  void beginFill(const FillStyle& f);
70 
72  void endFill();
73 
74  const SWFRect& getBounds() const {
75  return _shape.getBounds();
76  }
77 
78  void setBounds(const SWFRect& bounds) {
79  _shape.setBounds(bounds);
80  }
81 
83  void display(Renderer& renderer, const Transform& xform) const;
84 
86  //
96  void lineStyle(boost::uint16_t thickness, const rgba& color,
97  bool vScale=true, bool hScale=true,
98  bool pixelHinting=false,
99  bool noClose=false,
100  CapStyle startCapStyle=CAP_ROUND,
101  CapStyle endCapStyle=CAP_ROUND,
102  JoinStyle joinStyle=JOIN_ROUND,
103  float miterLimitFactor=1.0f);
104 
106  void resetLineStyle();
107 
111  //
117  size_t addFillStyle(const FillStyle& stl);
118 
122  //
128  size_t add_line_style(const LineStyle& stl);
129 
130  // Override from DefineShapeTag to call ::finalize
131  // NOTE: this is not correct in that a call to hitTest should
132  // not force closing the path being drawn.
133  // Instead, the closeup should be "temporary" and in
134  // the pointTestLocal itself (but only for dynamic drawing).
135  // We need to add a testcase for this as we currently have none.
136  // The testcase would look like this:
137  //
138  // moveTo(0, 0); lineTo(10, 0); lineTo(10, 10); // an L shape so far
139  // hitTest(8, 2, true); !hitTest(2, 8, true); // imaginarly forming a closed triangle as hitTest is concerned
140  // lineTo(0, 10); lineTo(0, 0); // explicitly closed as a square now
141  // hitTest(8, 2, true); hitTest(2, 8, true); // effectively forming a closed square
142  //
143  // In the test above, permanently closing on hit-test (what this implementation does)
144  // would result in a triangle and a stroke, which should fail the last hitTest(2,8).
145  //
146  //
147  bool pointTestLocal(boost::int32_t x, boost::int32_t y,
148  const SWFMatrix& wm) const
149  {
150  finalize();
151  return geometry::pointTest(_shape.paths(), _shape.lineStyles(), x, y,
152  wm);
153  }
154 
155  const SWF::ShapeRecord& shapeRecord() const {
156  return _shape;
157  }
158 
160  //
165  void add_path(const Path& pth);
166 
168  //
171  void finalize() const;
172 
173 private:
174 
176  //
183  void startNewPath(bool newShape);
184 
185  Path* _currpath;
186 
187  size_t _currfill;
188 
189  size_t _currline;
190 
191  // Current pen X position
192  boost::int32_t _x;
193 
194  // Current pen Y position
195  boost::int32_t _y;
196 
197  mutable bool _changed;
198 
200  //
202  mutable SWF::ShapeRecord _shape;
203 };
204 
205 } // end namespace gnash
206 
207 
208 #endif // GNASH_DYNAMIC_SHAPE_H
209 
210 
211 // Local Variables:
212 // mode: C++
213 // c-basic-offset: 8
214 // tab-width: 8
215 // indent-tabs-mode: t
216 // End: