Alzabo-Display-SWF
view release on metacpan or search on metacpan
lib/Alzabo/Display/SWF/Key.pm view on Meta::CPAN
package Alzabo::Display::SWF::Key;
use strict;
use warnings;
use fields qw/r segments name linestyle_up linestyle_over fill1 fill2 opac/;
use SWF::Sprite;
use SWF::Shape;
use SWF::Button;
use SWF::Action;
our $VERSION = '0.01';
my $PI = 3.1415926535;
sub new {
my $pkg = shift;
my $self = { @_ };
bless $self, $pkg;
return $self;
}
sub indicator {
my ($self, $fk) = @_;
our ($r, $segments) = ($self->{r}, $self->{segments});
my $c = new SWF::Sprite();
my $b = new SWF::Button();
my $s = new SWF::Shape();
$s->setLineStyle( @{ $self->{linestyle_up} } );
$s->movePenTo($r, 0);
my $start = 0;
#print STDERR "drawing BUTTON_UP shape ...\n";
for ( my $end = 360/$segments; $end <= 360; $end += 360/$segments ) {
# Calculate the midpoint angle. The control point
# lies on this line
my $midpoint = $start+($end-$start)/2;
# draw_arc() draws a circular arc between 2 points
draw_arc(
$s,
$r*cos(radians($start)), $r*sin(radians($start)),
$r*cos(radians($end )), $r*sin(radians($end )),
radians($midpoint)
);
$start = $end;
}
$b->addShape($s, SWF::Button::SWFBUTTON_UP);
my $t = new SWF::Shape();
$t->setLineStyle( @{ $self->{linestyle_over} } ); #, $self->{opac} );
$t->movePenTo($r, 0);
$start = 0;
#print STDERR "drawing my BUTTON_OVER circle ...\n";
for ( my $end = 360/$segments; $end <= 360; $end += 360/$segments ) {
# Calculate the midpoint angle. The control point
# lies on this line
my $midpoint = $start+($end-$start)/2;
# draw_arc() draws a circular arc between 2 points
draw_arc(
$t,
$r*cos(radians($start)), $r*sin(radians($start)),
$r*cos(radians($end )), $r*sin(radians($end )),
radians($midpoint)
);
$start = $end;
}
scalar @{ $fk } ? $b->addShape($t, SWF::Button::SWFBUTTON_OVER)
: $b->addShape($s, SWF::Button::SWFBUTTON_OVER);
my $fks = new SWF::Shape();
$fks->setLineStyle( @{ $self->{linestyle_over} } , $self->{opac} );
for my $fk ( @{ $fk } ) {
my ($x, $y) = @{ $fk->{xy} };
my $l = sqrt( $x*$x + $y*$y);
my $z = $r+4;
$fks->movePenTo($x*$z/$l, $y*$z/$l);
#print STDERR "drawing Line to $fk->{name} ($x, $y)\n";
$fks->drawLineTo($x*($l-$z)/$l, $y*($l-$z)/$l);
#$fks->movePenTo($x+$r, $y);
( run in 2.221 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )