10 use Glib qw(TRUE FALSE);
15 my ($class, $args) = @_;
18 img_height => $args->{img_height} || 100,
19 builder => Gtk2::Builder->new,
20 semaphore_win => Gtk2::Window->new('popup'),
21 semaphore_img => Gtk2::Image->new,
26 $self->{builder}->add_from_file('slotcarman.glade');
28 $self->{builder}->connect_signals(undef);
29 $self->load_all_images;
30 $self->set_font_sizes;
32 my $pixbuf = $self->{semaphore_images}->[0];
33 $self->{semaphore_img}->set_from_pixbuf($pixbuf);
34 $self->{semaphore_img}->show;
35 $self->{semaphore_win}->add($self->{semaphore_img});
36 $self->{semaphore_win}->set_type_hint('splashscreen');
37 $self->{semaphore_win}->set_position('center-on-parent');
38 $self->{semaphore_win}->set_transient_for(
39 $self->get_object('slotcarman')
42 $self->get_object('image_car1')->signal_connect(
43 'size_allocate' => \&watch_resize,
53 my $window = $self->{builder}->get_object('slotcarman');
54 $window->signal_connect(delete_event => \&delete_event);
58 sub delete_event { Gtk2->main_quit; }
60 sub quit { Gtk2->main_quit; }
65 $self->get_object('slotcarman')->fullscreen;
66 my $h = $self->get_object('image_car1')->allocation->height;
71 my ($window, $rectangle, $self) = @_;
72 print "w=", $rectangle->width, ", h=", $rectangle->height, "\n";
76 sub get_object { return shift->{builder}->get_object(@_); }
81 if ($self->{img_height} <= 80) {
82 $self->{label_font} = 10;
83 $self->{value_font} = 18;
84 $self->{lap_font} = 24;
85 } elsif ($self->{img_height} <= 100) {
86 $self->{label_font} = 12;
87 $self->{value_font} = 20;
88 $self->{lap_font} = 28;
89 } elsif ($self->{img_height} <= 120) {
90 $self->{label_font} = 14;
91 $self->{value_font} = 24;
92 $self->{lap_font} = 32;
93 } elsif ($self->{img_height} <= 150) {
94 $self->{label_font} = 16;
95 $self->{value_font} = 28;
96 $self->{lap_font} = 36;
98 $self->{label_font} = 18;
99 $self->{value_font} = 32;
100 $self->{lap_font} = 40;
104 sub load_all_images {
107 my $h = $self->{img_height};
109 $self->{throttle_images} = [
110 load_image_set('img/throttle%d.svg', 13, $h)
112 $self->{fuel_images} = [
113 load_image_set('img/fuel%d.svg', 8, int(0.6 * $h))
115 $self->{car_images} = load_image_dir('img/SCXCars', $h),
116 $self->{semaphore_images} => [
117 load_image_set('img/semaphore%d.svg', 5, 2 * $h)
122 my ($pattern, $limit, $height) = @_;
125 for my $i (0..$limit) {
126 my $file = sprintf($pattern, $i);
128 my $dummy = Gtk2::Gdk::Pixbuf->new_from_file($file);
129 my $width = $dummy->get_width * $height / $dummy->get_height;
130 push @rv, Gtk2::Gdk::Pixbuf->new_from_file_at_scale(
131 $file, $width, $height, TRUE
138 my ($dir, $height) = @_;
141 for my $file (<$dir/*>) {
142 $file = Encode::decode('utf-8', $file);
150 my $dummy = Gtk2::Gdk::Pixbuf->new_from_file($file)
153 my $width = $dummy->get_width * $height / $dummy->get_height;
154 $rv{$name} = Gtk2::Gdk::Pixbuf->new_from_file_at_scale(
155 $file, $width, $height, TRUE
162 my ($self, $row, $val) = @_;
165 $val = 13 if !defined $val;
167 my $image = $self->get_object("image_throttle$row");
168 $image->set_from_pixbuf($self->{throttle_images}->[$val]);
172 my ($self, $row, $val) = @_;
175 $val = 0 if !defined $val;
177 my $image = $self->get_object("image_fuel$row");
178 $image->set_from_pixbuf($self->{fuel_images}->[$val]);
182 my ($self, $row, $name) = @_;
185 my $pixbuf = $self->{car_images}->{$name};
187 print "No car image for $name.\n";
191 my $image = $self->get_object("image_car$row");
192 $image->set_from_pixbuf($pixbuf);
196 my ($self, $row, $text) = @_;
199 my $label = $self->get_object("label_lap$row")
200 or die "Can't get label_lap$row";
201 $label->set_markup('<span font_desc="24" weight="bold">'.$text.'</span>');
205 my ($self, $row, $text) = @_;
208 my $label = $self->get_object("label_laptime$row")
209 or die "Can't get label_laptime$row";
210 $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
214 my ($self, $row, $text) = @_;
217 my $label = $self->get_object("label_avg_lap$row")
218 or die "Can't get label_avg_lap$row";
219 $label->set_markup('<span font_desc="22" weight="bold">'.$text.'</span>');
223 my ($self, $row, $text, $global) = @_;
226 my $label = $self->get_object("label_best_lap$row")
227 or die "Can't get label_best_lap$row";
230 $global = ' foreground="#e00000"';
235 $label->set_markup('<span font_desc="18" weight="bold"'.$global.'>'
240 my ($self, $row, $text) = @_;
243 my $label = $self->get_object("label_name$row")
244 or die "Can't get label_lap$row";
245 $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
249 my ($self, $row) = @_;
250 $self->set_laptime($row, 'PIT');
254 my ($self, $row) = @_;
255 $self->set_laptime($row, 'GO!');
259 my ($self, $num) = @_;
261 my $win = $self->{semaphore_win};
263 my $img = $self->{semaphore_img};
264 my $pixbuf = $self->{semaphore_images}->[$num];
265 $img->set_from_pixbuf($pixbuf);
273 my ($self, $text) = @_;
275 my $label = $self->get_object("label_lap_global")
276 or die "Can't get label_lap_global";
277 $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
281 my ($self, $text) = @_;
283 my $label = $self->get_object("label_time_global")
284 or die "Can't get label_time_global";
285 $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
289 my ($self, $time, $who) = @_;
292 $text .= ' by ' . $who
295 my $label = $self->get_object("label_best_lap_global")
296 or die "Can't get label_best_lap_global";
297 $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');