10 use Glib qw(TRUE FALSE);
15 my ($class, $args) = @_;
19 load_image_set('img/throttle%d.svg', 13, 100)
22 load_image_set('img/fuel%d.svg', 8, 100)
24 car_images => load_image_dir('img/SCXCars', 100),
25 builder => Gtk2::Builder->new,
30 $self->{builder}->add_from_file('slotcarman.glade');
32 $self->{builder}->connect_signals(undef);
40 my $window = $self->{builder}->get_object('slotcarman');
44 sub get_object { return shift->{builder}->get_object(@_); }
47 my ($pattern, $limit, $height) = @_;
50 for my $i (0..$limit) {
51 my $file = sprintf($pattern, $i);
53 my $dummy = Gtk2::Gdk::Pixbuf->new_from_file($file);
54 my $width = $dummy->get_width * $height / $dummy->get_height;
55 push @rv, Gtk2::Gdk::Pixbuf->new_from_file_at_scale(
56 $file, $width, $height, TRUE
63 my ($dir, $height) = @_;
66 for my $file (<$dir/*>) {
67 $file = Encode::decode('utf-8', $file);
75 my $dummy = Gtk2::Gdk::Pixbuf->new_from_file($file)
78 my $width = $dummy->get_width * $height / $dummy->get_height;
79 $rv{$name} = Gtk2::Gdk::Pixbuf->new_from_file_at_scale(
80 $file, $width, $height, TRUE
87 my ($self, $row, $val) = @_;
90 $val = 13 if !defined $val;
92 my $image = $self->get_object("image_throttle$row");
93 $image->set_from_pixbuf($self->{throttle_images}->[$val]);
97 my ($self, $row, $val) = @_;
100 $val = 0 if !defined $val;
102 my $image = $self->get_object("image_fuel$row");
103 $image->set_from_pixbuf($self->{fuel_images}->[$val]);
107 my ($self, $row, $name) = @_;
110 my $pixbuf = $self->{car_images}->{$name};
112 print "No car image for $name.\n";
116 my $image = $self->get_object("image_car$row");
117 $image->set_from_pixbuf($pixbuf);
121 my ($self, $row, $text) = @_;
124 my $label = $self->get_object("label_lap$row")
125 or die "Can't get label_lap$row";
126 $label->set_markup('<span font_desc="24" weight="bold">'.$text.'</span>');
130 my ($self, $row, $text) = @_;
133 my $label = $self->get_object("label_laptime$row")
134 or die "Can't get label_laptime$row";
135 $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
139 my ($self, $row, $text) = @_;
142 my $label = $self->get_object("label_best_lap$row")
143 or die "Can't get label_best_lap$row";
144 $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
148 my ($self, $row, $text) = @_;
151 my $label = $self->get_object("label_name$row")
152 or die "Can't get label_lap$row";
153 $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
157 my ($self, $row) = @_;
158 $self->set_laptime($row, 'PIT');
162 my ($self, $row) = @_;
163 $self->set_laptime($row, '--');