SWF/Util.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 65 CC 2 SCAR 11.0
CC
2
Cov
0%
get_coordinates
6.0
rgb2ary
2.0
button_shape
2.0
CRAP 3.0
1 package Alzabo::Display::SWF::Util;
2  
3 use strict;
4 use warnings;
5 use base qw/Exporter/;
6  
7 use SWF::Shape;
8 our $VERSION = '0.01';
9 our @EXPORT_OK = qw/rgb2ary button_shape get_coordinates/;
10  
11 sub rgb2ary {
12 local $_ = shift;
13 my $h = '[0-9A-F]';
14 /^x($h$h)($h$h)($h$h)$/ or die "Wrong RGB Color Specification $_!";
15 my @r = map hex, $1, $2, $3;
16 return @r;
17 }
18  
19 sub button_shape {
20 my $bs = new SWF::Shape;
21 my $w = $_[0] + 2;
22 $bs->setLeftFill($bs->addFill(@_[1..3]));
23 $bs->movePenTo(0, 0);
24 $bs->drawLine(0, 16);
25 $bs->drawLine($w, 0);
26 $bs->drawLine(0, -16);
27 $bs->drawLine(-$w, 0);
28 return $bs;
29 }
30  
31 sub get_coordinates {
32 my ($t, $x, $y) = @_;
33 my (@p, $x0, $y0);
34 my $min = 99;
35 my $e = 3;
36 for my $w ( 0 - $e .. $t->{width} + $e ) {
37 push @p, [ $t->{dx} + $w, $t->{dy} - $e ];
38 push @p, [ $t->{dx} + $w, $t->{dy} + $t->{height} + $e ];
39 }
40 for my $h ( 1 - $e .. $t->{height} - 1 + $e ) {
41 push @p, [ $t->{dx} - $e , $t->{dy} + $h ];
42 push @p, [ $t->{dx} + $t->{width} + $e, $t->{dy} + $h ];
43 }
44 for my $p ( @p ) {
45 my $d = sqrt( ($p->[0] - $x)**2 + ($p->[1] - $y)**2 );
46 if ( $d < $min ) {
47 $x0 = $p->[0];
48 $y0 = $p->[1];
49 $min = $d;
50 }
51 }
52 return ($x0, $y0);
53 }
54  
55 1;