1# ====================================================================
2# Copyright (c) 2000-2003 by Soheil Seyfaie. All rights reserved.
3#           (c) 2009 A.Kleine
4# This program is free software; you can redistribute it and/or modify
5# it under the same terms as Perl itself.
6# ====================================================================
7
8# $Author$
9# $Id$
10
11package SWF::Shape;
12use SWF ();
13
14$SWF::Shape::VERSION = $SWF::VERSION;
15
16sub setLeftFill{
17    my $self = shift;
18
19    return $self->xs_setLeftFill() unless scalar @_;
20    return $self->xs_setLeftFill($_[0]) if ( ref($_[0]) eq 'SWF::Fill');
21    return $self->xs_setLeftFill($self->addSolidFill(@_));
22}
23
24sub setRightFill{
25    my $self = shift;
26
27    return $self->xs_setRightFill() unless scalar @_;
28    return $self->xs_setRightFill($_[0]) if ( ref($_[0]) eq 'SWF::Fill');
29    return $self->xs_setRightFill($self->addSolidFill(@_));
30}
31
321;
33
34__END__
35
36=head1 NAME
37
38SWF::Shape - Shape class
39
40=head1 SYNOPSIS
41
42	use SWF::Shape;
43	$shape = new SWF::Shape();
44	$dispitem = $movie->add($shape);
45
46=head1 DESCRIPTION
47
48SWF::Shape is the fundamental object of a flash movie.
49
50=head1 METHODS
51
52=over 4
53
54=item new SWF::Shape()
55
56Creates a new Shape object.
57
58=item $shape->movePenTo($x, $y)
59
60Move the Shape's (imaginary) pen location to ($x, $y) in the Shape's coordinate space.
61
62=item $shape->movePen($dx, $dy)
63
64Add ($dx, $dy) to the Shape's pen current location.
65
66=item $x = $shape->getPenX()
67
68Returns Pen's x-coordinates
69
70=item $y = $shape->getPenY()
71
72Returns Pen's y-coordinates
73
74=item ($x, $y) = $shape->getPen()
75
76Returns Pen's (x,y) coordinates
77
78=item $shape->drawLineTo($x, $y)
79
80Draw a line (using current line style, set by one of the setLine...() methods) from the current position to ($x, $y).
81
82=item $shape->drawLine($dx, $dy)
83
84Draw a line (using current line style set by one of the setLine...() methods) from the current position to displacement ($dx, $dy).
85
86=item $shape->drawCurveTo($controlx, $controly, $anchorx, $anchory)
87
88Draw a quadratic curve (using current line style, set by one of the setLine...() methods)
89from current pen position to ($anchorx, $anchory) using control point ($controlx, $controly).
90
91=item $shape->drawCurve($controldx, $controly, $anchorx, $anchory)
92
93Draw a quadratic curve (using current line style, set by one of the setLine...() methods)
94from current pen position to displacement ($anchordx, $anchordy) using displacement control point ($controldx, $controldy).
95
96=item $shape->drawCubicTo($bx,$by,$cx,$cx,$dx,$dy)
97
98=item $shape->drawCubic($bx,$by,$cx,$cx,$dx,$dy)
99
100Draw a cubic curve (using current line style).
101[ToDo: Add some more details and demo code]
102
103=item $shape->setLine($width, $r, $g, $b [,$a])
104
105Sets Shape's line width and color (RGB). To remove the Shape's line style call $shape->hideLine().
106The used line width for drawing is a product of $width argument and scale value set, see SWF::setScale($scale).
107Arguments $r, $g, $b stand for red, green and blue color parts, optional $a for alpha value.
108
109=item $shape->setLineStyle($width, $r, $g, $b [,$a])
110
111This OLD deprecated method is documented here only for compatibility reason.
112The line width -in TWIPS units- is independent of Ming scale value (more bug than feature).
113
114=item $shape->setLine2($width, $r, $g, $b ,$a, $flags, $miterLimit)
115
116A new method available for SWF version >=8 setting shape's line width and color (RGBA) with additional
117control flags (see below) and miter limit. To remove the Shape's line style call $shape->hideLine().
118The used line width for drawing is a product of $width argument and scale value set, see SWF::setScale($scale).
119Arguments $r, $g, $b, $a stand for red, green, blue and alpha color parts. $a is not optional here.
120
121Available flags are:
122Line cap style: select one of the following flags (default is round cap style)
123
124	SWF_LINESTYLE_CAP_ROUND
125	SWF_LINESTYLE_CAP_NONE
126	SWF_LINESTYLE_CAP_SQUARE
127
128Line join style: select one of the following flags (default is round join style)
129
130	SWF_LINESTYLE_JOIN_ROUND
131	SWF_LINESTYLE_JOIN_BEVEL
132	SWF_LINESTYLE_JOIN_MITER
133
134Scaling flags: disable horizontal / vertical scaling
135
136	SWF_LINESTYLE_FLAG_NOHSCALE
137	SWF_LINESTYLE_FLAG_NOVSCALE
138
139Enable pixel hinting to correct blurry vertical / horizontal lines:  all anchors will be aligned to full pixels
140
141	SWF_LINESTYLE_FLAG_HINTING
142
143Disable stroke closure: if no-close flag is set caps will be applied instead of joins.
144
145	SWF_LINESTYLE_FLAG_NOCLOSE
146
147End-cap style: default round
148
149	SWF_LINESTYLE_FLAG_ENDCAP_ROUND
150	SWF_LINESTYLE_FLAG_ENDCAP_NONE
151	SWF_LINESTYLE_FLAG_ENDCAP_SQUARE
152
153If join style is SWF_LINESTYLE_JOIN_MITER a miter limit factor must be set. Miter max length is then calculated as:
154max miter len = miter limit * width. If join style is not miter, this value will be ignored.
155
156=item $shape->setLineStyle2($width, $r, $g, $b ,$a, $flags, $miterLimit)
157
158This OLD deprecated method is mentioned here only for compatibility reason, you'd better use setLine2().
159
160=item $shape->setLine2Filled($width, $fill, $flags, $miterLimit)
161
162A new method available for SWF version >=8 setting shape's line width and fill style, $fill is an object
163of SWF::Fill class. For other argument details see item $shape->setLine2().
164
165=item $shape->setLine2StyleFilled($width, $fill, $flags, $miterLimit)
166
167This OLD deprecated method is mentioned here only for compatibility reason, you'd better use setLine2Filled().
168
169=item $shape->hideLine()
170
171Remove the Shape's line, i.e. make lines painted after this method call invisible.
172
173=item $fill = $shape->addSolidFill($r, $g, $b [,$a])
174
175=item $fill = $shape->addFill($r, $g, $b [,$a])
176
177Adds a solid fill to $shape list of fill styles and returns an SWF::Fill object. This object is used with the "setLine()" method described below. The default value of $a is 0.
178
179=item $fill = $shape->addBitmapFill($bitmap [,FLAG])
180
181=item $fill = $shape->addFill($bitmap [,FLAG])
182
183Adds a bitmap fill to $shape list of fill styles and returns an SWF::Fill object. This object is used with the "setLine()" method described below.
184
185$bitmap is an SWF::Bitmap object while FLAG argument can be SWFFILL_TILED_BITMAP or SWFFILL_CLIPPED_BITMAP. Make sure to import these constants to your package before useing it, i.e. use the following statement:
186
187     use SWF::Fill <list of constants>;
188
189The default value of FLAG is SWFFILL_TILED_BITMAP.
190
191=item $fill = $shape->addGradientFill($gradient [,FLAG])
192
193=item $fill = $shape->addFill($gradient [,FLAG])
194
195Adds a gradient fill to $shape list of fill styles and returns an SWF::Fill object. This object is used with the "setLine()" method described below.
196
197$gradient is an SWF::Gradient object while FLAG argument can be SWFFILL_LINEAR_GRADIENT or SWFFILL_RADIAL_GRADIENT, plus SWFFILL_FOCAL_GRADIENT for V8.
198Make sure to import these constants to your package before useing it, i.e. use the following statement:
199
200     use SWF::Fill <list of constants>;
201
202The default value of FLAG is SWFFILL_LINEAR_GRADIENT.
203
204=item $shape->xs_setLeftFill($fill)
205
206=item $shape->setLeftFill($fill)
207
208Sets the fill on the left side of the edge. $fill is an SWF::Fill object returned from "addFill" method.
209
210=item $shape->setLeftFill($r, $g, $b [,$a])
211
212This is another way of saying:
213
214     my $fill = $shape->addSolidFill($r, $g, $b [,$a]);
215     $shape->setLeftFill($fill);
216
217=item $shape->xs_setRightFill($fill)
218
219=item $shape->setRightFill($fill)
220
221Sets the fill on the right side of the edge. $fill is an SWF::Fill object returned from "addFill" method.
222
223=item $shape->setRightFill($r, $g, $b [,$a])
224
225This is another way of saying:
226
227     my $fill = $shape->addSolidFill($r, $g, $b [,$a]);
228     $shape->setRightFill($fill);
229
230=item $shape->drawCircle($r)
231
232Draws a circle with radious $r, also changes current position.
233
234=item $shape->drawArc($r, $startAngle, $endAngle)
235
236Draws an arc with radious $r form start to end.
237
238=item $shape->useVersion(version)
239
240This function allows to set the shapes version information. The version is only
241a hint. If necessary the version is upgraded. Valid values: are 3 and 4.
242Value of 3 is default, but 4 if linestyle2 is used.
243Some shape features are available only for shape version 4 and
244SWF file version>=8. One example is the usage of focal gradients:
245
246	$g = new SWF::Gradient();
247	$g->setFocalPoint(-0.9);
248	$g->addEntry(0.000000,0xff,0x00,0x00,0xff);
249	$g->addEntry(1.000000,0x00,0xff,0x00,0xff);
250	$shape->useVersion(4);
251	$shape->addGradientFill($g,SWFFILL_FOCAL_GRADIENT);
252
253=item $version = $shape->getVersion()
254
255Gets the current shape object version.
256
257=item $shape->dumpOutline()
258
259Returns a string describing shape's outline. After drawing in a shape
260expect getting a multi-line string like:
261
262	moveto 368,5
263	curveto 348,5 327,1
264	curveto 307,-3 284,-15
265etc. etc.
266
267=item $shape->end()
268
269Stops drawing on this shape and make the shape complete.
270Further method calls won't produce any lines, circles etc.
271By using this demo code later no circle is painted:
272
273	$shape->drawLineTo(300,300);
274	$shape->end();
275	$shape->drawCircle(200);
276
277=item $shape->drawGlyph($font, $cnumber [, $size])
278
279Draws character of $cnumber of $font. Also Unicode fonts are possible, if the font does provide that, just like next example:
280
281	$font=new SWF::Font("Thai-Bold.fdb");
282	$sh->drawGlyph($font, 0x0E44, 44);
283
284=item $shape->drawCharacterBounds($character)
285
286Draws an outer rectangle fitting for $character, an object of SWF::Character.
287
288=item $shape->setRenderHintingFlags(flags)
289
290Set render hinting flags. Possible values are
291	SWF::Constants::SWF_SHAPE_USESCALINGSTROKES and
292	SWF::Constants::SWF_SHAPE_USENONSCALINGSTROKES
293
294This method also will set version of this SWF::Shape object to 4.
295
296=back
297
298=head1 AUTHOR
299
300Soheil Seyfaie (soheil at users.sourceforge.net), Albrecht Kleine
301
302=head1 SEE ALSO
303
304SWF, SWF::Bitmap, SWF::Button, SWF::Constants, SWF::DisplayItem,
305SWF::Fill, SWF::Font, SWF::Gradient, SWF::Morph, SWF::Movie, SWF::MovieClip,
306SWF::TextField, SWF::Text, SWF::Character
307
308=cut
309