Acme-Curses-Marquee
view release on metacpan or search on metacpan
lib/Acme/Curses/Marquee.pm view on Meta::CPAN
my $end = $len - $off;
my $rem = $x - $end;
my $tmp = substr($fig->[$i],$off,$end);
$tmp .= substr($fig->[$i],0,$rem);
addstr($w, $i, 0, $tmp);
} else {
addstr($w, $i, 0, substr($fig->[$i],$off,$x));
}
}
$self->{offset}++;
refresh($w);
}
=head2 text
Take a new line of text for the marquee...
$m->text("New line of text");
...render it via figlet, split it into an array, and perform width
adjustments as neccessary. Store the new text, figleted text, length
of figleted text lines, and set marquee state to active.
=cut
sub text {
my ($self,$text) = @_;
my $font = $self->{font};
my $width = length($text) * 12;
my $line = 0;
# render text via figlet
my @fig = split(/\n/,`figlet -f $font -w $width '$text'`);
# find longest line length
foreach my $i (0..(@fig - 1)) {
$line = length($fig[$i]) if (length($fig[$i]) > $line);
}
# set line length to window width if shorter than that
$line = $self->{width} if ($line < $self->{width});
# pad all lines window width or longest length + 5
foreach my $i (0..(@fig - 1)) {
my $len = length($fig[$i]);
my $pad = $line - $len;
$pad += 25 if ($len > ($self->{width} - 6));
$fig[$i] = join('',$fig[$i],(' 'x $pad));
}
$self->{active} = 1;
$self->{offset} = 0;
$self->{srctxt} = $text;
$self->{txtlen} = length($fig[0]);
$self->{figtxt} = \@fig;
}
=head2 font
Sets the font of the marquee object and then calls C<text> to make the
display change.
$m->font('univers')
This method should not be called before the marquee object is active.
No checking is done to ensure the spacified font exists.
=cut
sub font {
my ($self,$font) = @_;
$self->{font} = $font;
$self->text($self->{srctxt});
}
=head2 is_active
Returns the marquee object's status (whether text has been set or not)
=cut
sub is_active {
my $self = shift;
return $self->{active};
}
=head1 TODO
A couple of nice transitions when changing the message would be good.
Left-to-right scrolling?
=head1 AUTHOR
Shawn Boyette, C<< <mdxi@cpan.org> >>
=head1 BUGS
Please report any bugs or feature requests to
C<bug-acme-curses-marquee@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Acme-Curses-Marquee>.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
=head1 ACKNOWLEDGEMENTS
=head1 COPYRIGHT & LICENSE
Copyright 2005 Shawn Boyette, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
1; # End of Acme::Curses::Marquee
( run in 0.515 second using v1.01-cache-2.11-cpan-ceb78f64989 )