Re: Making a subclass help
- From: muppet <scott asofyet org>
- To: gtk-perl list <gtk-perl-list gnome org>
- Subject: Re: Making a subclass help
- Date: Sun, 13 Jun 2004 13:00:54 -0400
On Saturday, June 12, 2004, at 09:55 AM, Grahame White wrote:
sub clickcell{
my $clicked = @_;
welcome to the wild & wonderful world of scalar versus array context.
when you take an array in scalar context, you get the number of
elements in the array. here, the number of elements in @_ is 1, so
you're getting 1 in $clicked.
you want to say either
my $clicked = shift;
or
my ($clicked) = @_;
or even
my $clicked = $_[0];
here, and it works fine.
print $clicked . "\n";
print $cells[$clicked]->get_image . "\n";
$cells[$clicked]->set_image(image => "ball.png");
return 0;
}
What _is_ happening, however, is that when I click a cell instead of
passing the clicked IButton's index to clickcell() it's passing 1
instead. What's puzzling me in particular is that before adding the
image property the correct IButton index was being passed to the
function.
i changed it to use get('index') instead of get_index(), but the
problem was the same. you probably changed something else in there
somewhere.
What I'm eventually going to make is a simple peg-solitaire game. It's
just a test program that I start off making each time I try a
different language. It's got simple rules, flexes the mind muscles a
bit, gives a common example to compare against and also produces an
'artifact' that I can say "woo look what I built" about :)
nifty. a hint: it will run rather a bit faster if you don't load a
file every time a button is clicked (you probably knew that already).
GdkPixbufs will help, but if create server-side GdkPixmaps for the
image icons, you'll save a lot of network traffic (i run x remotely,
where it's noticeable).
# on startup, preload the icons
foreach my $name (qw(blank ball)) {
my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file ("$name.png");
my ($pixmap, $mask) = $pixbuf->render_pixmap_and_mask (65535/2);
$icons{$name}{pixmap} = $pixmap;
$icons{$name}{mask} = $mask;
}
...
sub Mup::IButton::set_image {
my ($self, $icon) = @_;
$self->child->set_from_pixmap ($icon->{pixmap}, $icon->{mask});
}
...
$cell->set_image ($icons{'ball'});
in fact, you could just make the button class know about the icons (and
keep the list of pixmaps), and tell the button which icon you want it
to display, by name.
--
How come hair colors for women take an hour, but "wash out the gray"
stuff for men only five minutes? This is so unfair!
-- Elysse, complaining about commercials
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]