SWF/Table.pm untested

filter: Statementstmt 0.0% 0 / 71 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 87 CC 4 SCAR 17.0
CC
4
Cov
0%
new
12.0
moveTo
6.0
BEGIN
2.0
CRAP 5.5
1 package Alzabo::Display::SWF::Table;
2  
3 use strict;
4 use warnings;
5 use SWF qw(:ALL);
6 use Alzabo::Display::SWF::Util qw/rgb2ary/;
7 use Alzabo::Display::SWF::Text;
8 use Alzabo::Display::SWF::Column;
9 our $VERSION = '0.01';
10  
11 sub new {
12 my ($pkg, $t, $m, $scale, $cfg ) = @_;
13 my $tfdb = $cfg->{fdb_dir} . '/' . $cfg->{table}{fdb} .'.fdb';
14  
15 my $self = { columns => [], text => undef , head => undef , body => undef,
16 dx => undef, dy => undef, keys => [], column_by_name => {} };
17 bless $self, $pkg;
18  
19 my $f = new SWF::Font $tfdb;
20 my $txt = new Alzabo::Display::SWF::Text
21 $t->name, $f, rgb2ary( $cfg->{table}{color}{fg} );
22 my $w = 0;
23 my $dx = 14;
24 my $dy = 0;
25 for my $c ( $t->columns ) {
26 my $co = new Alzabo::Display::SWF::Column $c->name, $cfg;
27 $self->{column_by_name}{$c->name} = $co;
28 $co->{dy} = $dy;
29 $w = $_ > $w ? $_ : $w for $co->{width} + $dx;
30 $dy+=20;
31 }
32 $w = $_ > $w ? $_ : $w for $txt->getStringWidth($t->name) + 14;
33 $w += 10;
34 $dy += 3;
35  
36 my $th = new SWF::Shape;
37 $th->setLineStyle($scale*2, rgb2ary( $cfg->{table}{linestyle}{color} ));
38 $th->setLeftFill($th->addFill( rgb2ary( $cfg->{table}{color}{bg} )));
39 $th->movePenTo(0, 6);
40 $th->drawLine(0, 13);
41 $th->drawLine($w, 0);
42 $th->drawLine(0, -13);
43 $th->drawCurve(0, -6, -6, 0);
44 $th->drawLine(-$w+12, 0);
45 $th->drawCurve(-6, 0, 0, 6);
46 my $tb = new SWF::Shape;
47 $tb->setLineStyle($scale*2, rgb2ary( $cfg->{table}{linestyle}{color} ) );
48 $tb->setLeftFill($tb->addFill(rgb2ary( $cfg->{column}{color}{bg} )));
49 $tb->movePenTo(0, 19);
50 $tb->drawLine(0, $dy);
51 $tb->drawLine($w, 0);
52 $tb->drawLine(0, -$dy);
53 $tb->drawLine(-$w, 0);
54  
55 $self->{head} = $m->add($th);
56 $self->{body} = $m->add($tb);
57 $self->{text} = $m->add($txt);
58 $self->{width} = $w;
59 $self->{height} = $dy + 19;
60  
61 return $self;
62 }
63  
64 sub moveTo {
65 my ($self, $x, $y) = @_;
66 $self->{head}->moveTo($x, $y+6);
67 $self->{body}->moveTo($x, $y+6);
68 $self->{text}->moveTo($x+19, $y+19);
69 my $dy = 33;
70 for ( 0 .. $#{ $self->{columns} } ) {
71 $self->{columns}[$_]->moveTo($x+19, $y+$dy+6);
72 $self->{keys}[$_]->moveTo($x+10, $y+$dy+3) if $self->{keys}[$_];
73 $dy+=20;
74 }
75 }
76  
77 1;