| Image-Button documentation | Contained in the Image-Button distribution. |
Image::Button::Set - Builds a set of related PNG buttons
use Image::Button::Rect;
use Image::Button::Plain;
use Image::Button::Set;
my $b1 = new Image::Button::Rect(text => 'text b1',
font => 'newsgotn.ttf',
fontsize => 20,
fgcolor => [0, 0, 0],
file => 'b1.png');
my $b2 = $b1->copy(text => 'text b2', file => 'b2.png');
my $set = new Image::Button::Set(buttons => [ $b1, $b2 ]);
my $b3 = $b1->copy(text => 'text b3', file => 'b3.png');
$set->push(button => $b3);
my $b4 = $b1->copy(text => 'text b4', file => 'b4.png');
my $b5 = $b1->copy(text => 'text b5', file => 'b5.png');
my $b6 = new Image::Button::Plain(text => 'text b6',
font => 'newsgotn.ttf',
bdcolor => [10, 10, 10]);
$set->push(buttons => [$b4, $b5, $b6]);
$set->print(sameWidth => 0,
sameHeight => 1,
prefix => 'w-');
$set->flush(sameWidth => 1,
sameHeight => 0,
postfix => '-h',
override => { bdcolor => [0, 0, 20],
btcolor => [20, 0, 0] });
Builds a set of related buttons. They might be forced to have the same width and/or height. Make sure you specify an output file in the constructor of the buttons, because otherwise they will all go to stdout and the result won't be what you expect.
my $set = new Image::Button::Set(buttons => [ $b1, $b2 ]);
Takes the same arguments as flush, coming next.
Image::Button for a description of how to make buttons, and a list of available button types.
Juan M. García-Reyero <joanmg@twostones.org>
Copyright (C) 2003 Juan M. García-Reyero. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Image-Button documentation | Contained in the Image-Button distribution. |
package Image::Button::Set; # $Id: Set.pm,v 1.6 2003/03/04 15:58:15 joanmg Exp $ use strict; use vars qw($VERSION); $VERSION = "0.53"; sub new { my $pkg = shift; my %args = (buttons => undef, button => undef, textlist => [], @_,); my $self = bless { buttons => [], }, $pkg; $self->push(%args); return $self; } sub push { my $self = shift; my %args = (buttons => undef, # expect [] button => undef, # expect Image::Button::* textlist => [], @_,); push @{ $self->{buttons} }, @{ $args{buttons} } if defined $args{buttons}; push @{ $self->{buttons} }, $args{button} if defined $args{button}; my $labels = $args{textlist}; if (@$labels) { my $button = $self->{buttons}[-1]; unless (defined $button) { die "Need a button to clone\n"; } foreach my $label (@$labels) { $self->push(button => $button->copy(text => $label, file => '')); } } } sub print { my $self = shift; my %args = (sameWidth => 0, sameHeight => 0, prefix => '', postfix => '', override => {}, @_,); my $sw = $args{sameWidth}; my $sh = $args{sameHeight}; my $pre = $args{prefix}; my $pos = $args{postfix}; my $th = 0; my $tw = 0; if ($sw or $sh) { foreach my $b (@{ $self->{buttons} }) { my ($w, $h) = $b->getSize; if ($sw) { $tw = ($w > $tw) ? $w : $tw; } if ($sh) { $th = ($h > $th) ? $h : $th; } } } foreach my $b (@{ $self->{buttons} }) { $b->textSize(texth => $th, textw => $tw); $b->override(self => $args{override}); $b->print(prefix => $pre, postfix => $pos); } } sub flush { my $self = shift; my %args = (print => 1, @_); if ($args{print}) { $self->print(%args) } $self->{buttons} = []; } 1;