2 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
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.
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.
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
18 #include "smart_ptr.h"
19 #include "DynamicShape.h"
20 #include "FillStyle.h"
22 #include "DisplayObject.h"
28 DynamicShape::DynamicShape()
43 _currfill
= _currline
= 0;
44 // TODO: worth setting _changed=true ?
48 DynamicShape::display(Renderer
& renderer
, const Transform
& xform
) const
50 renderer
.drawShape(_shape
, xform
);
54 DynamicShape::add_path(const Path
& pth
)
57 _currpath
= &_shape
.currentPath();
61 DynamicShape::endFill()
64 if ( _currpath
&& _currfill
)
66 // TODO: should not just close the last path
67 // but rather append the point where
68 // the fill actually begun (could be
69 // in a previous path).
71 // NOTE that doing so will require changing
72 // the hitTest code to do stop considering
73 // each path in isolation when doing PIP testing
78 // reset _x and _y to reflect closing point
83 // Remove reference to the "current" path, as
84 // next drawing will happen on a different one
86 // Remove fill information
91 DynamicShape::beginFill(const FillStyle
& f
)
96 _currfill
= addFillStyle(f
);
98 // TODO: how to know wheter the fill should be set
99 // as *left* or *right* fill ?
100 // A quick test shows that *left* always work fine !
101 Path
newPath(_x
, _y
, _currfill
, 0, _currline
, true);
106 DynamicShape::startNewPath(bool newShape
)
108 // Close any pending filled path
109 if ( _currpath
&& _currfill
)
111 // TODO: this is probably bogus
115 // The DrawingApiTest.swf file shows we should not
116 // end the current fill when starting a new path.
118 // A quick test shows that *left* always work fine !
119 // More than that, using a *right* fill seems to break the tests !
120 Path
newPath(_x
, _y
, _currfill
, 0, _currline
, newShape
);
125 DynamicShape::finalize() const
127 // Nothing to do if not changed
128 if ( ! _changed
) return;
130 // Close any pending filled path (_currpath should be last path)
131 if ( _currpath
&& _currfill
)
133 assert(!_shape
.paths().empty());
134 assert(_currpath
== &(_shape
.paths().back()));
138 // TODO: check consistency of fills and such !
144 DynamicShape::lineStyle(boost::uint16_t thickness
, const rgba
& color
,
145 bool vScale
, bool hScale
, bool pixelHinting
, bool noClose
,
146 CapStyle startCapStyle
, CapStyle endCapStyle
,
147 JoinStyle joinStyle
, float miterLimitFactor
)
149 LineStyle
style(thickness
, color
, vScale
, hScale
, pixelHinting
,
150 noClose
, startCapStyle
, endCapStyle
, joinStyle
,
153 _currline
= add_line_style(style
);
158 DynamicShape::resetLineStyle()
165 DynamicShape::moveTo(boost::int32_t x
, boost::int32_t y
)
167 // It was manually tested that a moveTo, even
168 // when moving to the same point of current cursor,
169 // will start a new path.
177 DynamicShape::lineTo(boost::int32_t x
, boost::int32_t y
, int swfVersion
)
179 if (!_currpath
) startNewPath(true);
182 _currpath
->drawLineTo(x
, y
);
185 SWFRect bounds
= _shape
.getBounds();
187 unsigned thickness
= _currline
?
188 _shape
.lineStyles().back().getThickness() : 0;
190 if (_currpath
->size() == 1) {
191 _currpath
->expandBounds(bounds
, thickness
, swfVersion
);
193 bounds
.expand_to_circle(x
, y
, swfVersion
< 8 ? thickness
:
197 _shape
.setBounds(bounds
);
199 // Update current pen position
208 DynamicShape::curveTo(boost::int32_t cx
, boost::int32_t cy
,
209 boost::int32_t ax
, boost::int32_t ay
, int swfVersion
)
211 if (!_currpath
) startNewPath(true);
214 _currpath
->drawCurveTo(cx
, cy
, ax
, ay
);
216 SWFRect bounds
= _shape
.getBounds();
218 unsigned thickness
= _currline
?
219 _shape
.lineStyles().back().getThickness() : 0;
221 if (_currpath
->size() == 1) {
222 _currpath
->expandBounds(bounds
, thickness
, swfVersion
);
225 bounds
.expand_to_circle(ax
, ay
,
226 swfVersion
< 8 ? thickness
: thickness
/ 2.0);
227 bounds
.expand_to_circle(cx
, cy
,
228 swfVersion
< 8 ? thickness
: thickness
/ 2.0);
231 _shape
.setBounds(bounds
);
233 // Update current pen position
242 DynamicShape::addFillStyle(const FillStyle
& stl
)
244 _shape
.addFillStyle(stl
);
245 return _shape
.fillStyles().size();
249 DynamicShape::add_line_style(const LineStyle
& stl
)
251 _shape
.addLineStyle(stl
);
252 return _shape
.lineStyles().size();
255 } // end namespace gnash
260 // indent-tabs-mode: t