« lib/Video/PlaybackMachine/FillProducer/SlideShow.pm
↑ Summary
lib/Video/PlaybackMachine/ScheduleView.pm »
| 1 | package Video::PlaybackMachine::FillProducer::TextFrame::Row; | ||
| 2 | |||
| 3 | our $VERSION = '0.09'; # VERSION | ||
| 4 | |||
| 5 | use Moo; | ||
| 6 | |||
| 7 | use Video::PlaybackMachine::FillProducer::TextFrame::Column; | ||
| 8 | |||
| 9 | has 'image' => ( is => 'ro' ); | ||
| 10 | has 'border' => ( is => 'ro' ); | ||
| 11 | has 'columns' => ( is => 'ro' ); | ||
| 12 | has 'dimensions' => ( is => 'lazy' ); | ||
| 13 | |||
| 14 | sub BUILDARGS { | ||
| 15 | my ($type, @args) = @_; | ||
| 16 | my ($image, $border, @columns) = @args; | ||
| 17 | |||
| 18 | return { | ||
| 19 | image => $image, | ||
| 20 | border => $border, | ||
| 21 | columns => [ | ||
| 22 | map { Video::PlaybackMachine::FillProducer::TextFrame::Column->new( | ||
| 23 | image => $image, | ||
| 24 | text => $_ | ||
| 25 | ); } @columns | ||
| 26 | ], | ||
| 27 | }; | ||
| 28 | |||
| 29 | } | ||
| 30 | |||
| 31 | sub _build_dimensions { | ||
| 32 | my $self = shift; | ||
| 33 | |||
| 34 | my $total_width = 0; | ||
| 35 | my $max_height = 0; | ||
| 36 | |||
| 37 | foreach my $column ( $self->get_columns() ) { | ||
| 38 | my ($width, $height) = $column->get_dimensions( $self->image()->get_width() - $total_width ); | ||
| 39 | $total_width += ($width + $self->border()); | ||
| 40 | $max_height = $height if $height > $max_height; | ||
| 41 | } | ||
| 42 | |||
| 43 | return [$total_width - $self->{'border'}, $max_height]; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub get_columns { | ||
| 47 | my $self = shift; | ||
| 48 | |||
| 49 | return @{ $self->columns() }; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub get_dimensions { | ||
| 53 | my $self = shift; | ||
| 54 | |||
| 55 | return @{ $self->dimensions() }; | ||
| 56 | |||
| 57 | } | ||
| 58 | |||
| 59 | sub get_width { | ||
| 60 | my $self = shift; | ||
| 61 | my ($width, undef) = $self->get_dimensions(); | ||
| 62 | return $width; | ||
| 63 | } | ||
| 64 | |||
| 65 | sub get_height { | ||
| 66 | my $self = shift; | ||
| 67 | my (undef, $height) = $self->get_dimensions(); | ||
| 68 | return $height; | ||
| 69 | } | ||
| 70 | |||
| 71 | sub draw { | ||
| 72 | my $self = shift; | ||
| 73 | my ($x, $y) = @_; | ||
| 74 | |||
| 75 | my $currx = $x; | ||
| 76 | foreach my $column ( $self->get_columns() ) { | ||
| 77 | my $width_left = $self->image()->get_width() - $currx; | ||
| 78 | $column->draw($currx, $y, $width_left); | ||
| 79 | $currx += ($column->get_dimensions($width_left))[0]; | ||
| 80 | $currx += $self->border(); | ||
| 81 | } | ||
| 82 | return 1; | ||
| 83 | } | ||
| 84 | |||
| 85 | no Moo; | ||
| 86 | |||
| 87 | 1; | ||
| 88 |