reduce verbosity
[gnash.git] / libcore / DynamicShape.h
blobb510def0f46a11914934bd85178e90cc17ff5838
1 //
2 // Copyright (C) 2007, 2008, 2009, 2010 Free Software 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
20 #ifndef GNASH_DYNAMIC_SHAPE_H
21 #define GNASH_DYNAMIC_SHAPE_H
23 #include <vector>
24 #include "LineStyle.h"
25 #include "ShapeRecord.h"
27 namespace gnash {
28 class DisplayObject;
29 class Renderer;
30 class FillStyle;
31 class GradientRecord;
32 class Transform;
35 namespace gnash {
37 /// The DynamicShape class represents a mutable shape.
39 /// It is provides mutating functions for the SWF::ShapeRecord class that
40 /// are used in the Flash drawing API.
42 /// DynamicShape objects are not refcounted, so must be stack-allocated or
43 /// wrapped in smart pointers.
44 class DynamicShape
46 public:
48 DynamicShape();
50 ~DynamicShape() {}
52 /// Remove all paths and style informations
53 void clear();
55 /// Move pen to given coordinates
56 void moveTo(boost::int32_t x, boost::int32_t y);
58 /// Draw a straight line from current position to given one
59 void lineTo(boost::int32_t x, boost::int32_t y, int swfVersion);
61 /// \brief
62 /// Draw a curve from current position to given one
63 /// using given control points.
64 void curveTo(boost::int32_t cx, boost::int32_t cy,
65 boost::int32_t ax, boost::int32_t ay, int swfVersion);
67 /// Start drawing with a solid fill
68 void beginFill(const FillStyle& f);
70 /// Close an existing filled path, if any.
71 void endFill();
73 const SWFRect& getBounds() const {
74 return _shape.getBounds();
77 void setBounds(const SWFRect& bounds) {
78 _shape.setBounds(bounds);
81 /// Display a DynamicShape object.
82 void display(Renderer& renderer, const Transform& xform) const;
84 /// Set current line style and start a new path.
86 /// @param thickness
87 /// @param color
88 /// @param vScale
89 /// @param hScale
90 /// @param noClose
91 /// @param startCapStyle
92 /// @param endCapStyle
93 /// @param joinStyle
94 /// @param miterLimitFactor
95 void lineStyle(boost::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);
104 /// Reset line style to no style and start a new path.
105 void resetLineStyle();
107 /// \brief
108 /// Add a fill style, possibly reusing an existing
109 /// one if existent.
111 /// @return the 1-based offset of the fill style,
112 /// either added or found.
113 /// This offset is the one required to properly
114 /// reference it in gnash::path instances.
116 size_t addFillStyle(const FillStyle& stl);
118 /// \brief
119 /// Add a line style, possibly reusing an existing
120 /// one if existent.
122 /// @return the 1-based offset of the line style,
123 /// either added or found.
124 /// This offset is the one required to properly
125 /// reference it in gnash::path instances.
127 size_t add_line_style(const LineStyle& stl);
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:
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
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).
146 bool pointTestLocal(boost::int32_t x, boost::int32_t y,
147 const SWFMatrix& wm) const
149 finalize();
150 return geometry::pointTest(_shape.paths(), _shape.lineStyles(), x, y,
151 wm);
154 const SWF::ShapeRecord& shapeRecord() const {
155 return _shape;
158 /// Add a path, updating _currpath and recomputing bounds
160 /// TODO: make private? Only current user is BitmapMovieDefinition.
161 /// It needs this function unless we provide a mean to add a
162 /// Bitmap-Filled path
164 void add_path(const Path& pth);
166 /// Always call this function before displaying !
168 /// It will take care of cleaning up the drawing
169 /// and setting up correct fill styles
170 void finalize() const;
172 private:
174 /// Initialize a new path
176 /// Used when changing style or moving the pen
178 /// The newly added path will use current values
179 /// for origin, fill and line styles.
181 /// If newShape is true the new shape will start a new subshape.
182 void startNewPath(bool newShape);
184 Path* _currpath;
186 size_t _currfill;
188 size_t _currline;
190 // Current pen X position
191 boost::int32_t _x;
193 // Current pen Y position
194 boost::int32_t _y;
196 mutable bool _changed;
198 /// The actual SWF::ShapeRecord wrapped by this class.
200 /// Mutable for lazy finalization.
201 mutable SWF::ShapeRecord _shape;
204 } // end namespace gnash
207 #endif // GNASH_DYNAMIC_SHAPE_H
210 // Local Variables:
211 // mode: C++
212 // c-basic-offset: 8
213 // tab-width: 8
214 // indent-tabs-mode: t
215 // End: