use strict;
use utf8;
+use Carp;
use Encode;
use Gtk2 '-init';
use Glib qw(TRUE FALSE);
my ($self) = @_;
if ($self->{img_height} <= 80) {
- $self->{label_font} = 10;
- $self->{value_font} = 18;
- $self->{lap_font} = 24;
+ $self->{label_size} = 10;
+ $self->{value_size} = 18;
+ $self->{lap_size} = 24;
} elsif ($self->{img_height} <= 100) {
- $self->{label_font} = 12;
- $self->{value_font} = 20;
- $self->{lap_font} = 28;
+ $self->{label_size} = 12;
+ $self->{value_size} = 20;
+ $self->{lap_size} = 28;
} elsif ($self->{img_height} <= 120) {
- $self->{label_font} = 14;
- $self->{value_font} = 24;
- $self->{lap_font} = 32;
+ $self->{label_size} = 14;
+ $self->{value_size} = 24;
+ $self->{lap_size} = 32;
} elsif ($self->{img_height} <= 150) {
- $self->{label_font} = 16;
- $self->{value_font} = 28;
- $self->{lap_font} = 36;
+ $self->{label_size} = 16;
+ $self->{value_size} = 28;
+ $self->{lap_size} = 36;
} else {
- $self->{label_font} = 18;
- $self->{value_font} = 32;
- $self->{lap_font} = 40;
+ $self->{label_size} = 18;
+ $self->{value_size} = 32;
+ $self->{lap_size} = 40;
}
}
return \%rv;
}
+sub set_label {
+ my ($self, $prefix, $row, $text, $size) = @_;
+
+ ++$row if defined $row && $row =~ /\A\d+\z/xms;
+ $size //= 'value';
+
+ my $name = defined $row ? $prefix.$row : $prefix;
+ my $label = $self->get_object($name)
+ or croak "Can't get label named $name";
+ $label->set_markup('<span font_desc="' . $self->{$size.'_size'} . '"'
+ . ' weight="bold">' . $text . '</span>');
+}
+
+sub set_image {
+ my ($self, $prefix, $row, $imgset, $value) = @_;
+
+ ++$row if defined $row && $row =~ /\A\d+\z/xms;
+
+ my $name = defined $row ? $prefix.$row : $prefix;
+
+ my $image = $self->get_object($name)
+ or croak "Can't get image named $name";
+
+ my $set = $self->{$imgset.'_images'};
+ my $pixbuf = (ref($set) eq 'ARRAY')
+ ? $set->[$value]
+ : $set->{$value};
+
+ $image->set_from_pixbuf($pixbuf);
+}
+
sub set_throttle {
my ($self, $row, $val) = @_;
- $row++;
$val = 13 if !defined $val;
-
- my $image = $self->get_object("image_throttle$row");
- $image->set_from_pixbuf($self->{throttle_images}->[$val]);
+ $self->set_image('image_throttle', $row, 'throttle', $val);
}
sub set_fuel {
my ($self, $row, $val) = @_;
- $row++;
- $val = 0 if !defined $val;
-
- my $image = $self->get_object("image_fuel$row");
- $image->set_from_pixbuf($self->{fuel_images}->[$val]);
+ $self->set_image('image_fuel', $row, 'fuel', $val || 0);
}
sub set_car_icon {
my ($self, $row, $name) = @_;
- $row++;
- my $pixbuf = $self->{car_images}->{$name};
- if (!$pixbuf) {
- print "No car image for $name.\n";
- return;
- }
-
- my $image = $self->get_object("image_car$row");
- $image->set_from_pixbuf($pixbuf);
+ $self->set_image('image_car', $row, 'car', $name);
}
sub set_lap {
my ($self, $row, $text) = @_;
- ++$row;
- my $label = $self->get_object("label_lap$row")
- or die "Can't get label_lap$row";
- $label->set_markup('<span font_desc="24" weight="bold">'.$text.'</span>');
+ $self->set_label('label_lap', $row, $text, 'lap');
}
sub set_laptime {
my ($self, $row, $text) = @_;
- ++$row;
- my $label = $self->get_object("label_laptime$row")
- or die "Can't get label_laptime$row";
- $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
+ $self->set_label('label_laptime', $row, $text);
}
sub set_avg_lap {
my ($self, $row, $text) = @_;
- ++$row;
- my $label = $self->get_object("label_avg_lap$row")
- or die "Can't get label_avg_lap$row";
- $label->set_markup('<span font_desc="22" weight="bold">'.$text.'</span>');
+ $self->set_label('label_avg_lap', $row, $text);
}
sub set_best_lap {
- my ($self, $row, $text, $global) = @_;
-
- ++$row;
- my $label = $self->get_object("label_best_lap$row")
- or die "Can't get label_best_lap$row";
-
- if ($global) {
- $global = ' foreground="#e00000"';
- } else {
- $global = '';
- }
+ my ($self, $row, $text) = @_;
- $label->set_markup('<span font_desc="18" weight="bold"'.$global.'>'
- .$text.'</span>');
+ $self->set_label('label_best_lap', $row, $text);
}
-sub set_driver {
+sub set_name {
my ($self, $row, $text) = @_;
- ++$row;
- my $label = $self->get_object("label_name$row")
- or die "Can't get label_lap$row";
- $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
+ $self->set_label('label_name', $row, $text);
}
sub enter_pit_lane {
sub rounds {
my ($self, $text) = @_;
- my $label = $self->get_object("label_lap_global")
- or die "Can't get label_lap_global";
- $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
+ $self->set_label('label_lap_global', undef, $text);
}
sub time {
my ($self, $text) = @_;
- my $label = $self->get_object("label_time_global")
- or die "Can't get label_time_global";
- $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
+ $self->set_label('label_time_global', undef, $text);
}
sub best_lap {
my $text = $time;
$text .= ' by ' . $who
if defined $who;
-
- my $label = $self->get_object("label_best_lap_global")
- or die "Can't get label_best_lap_global";
- $label->set_markup('<span font_desc="18" weight="bold">'.$text.'</span>');
+ $self->set_label('label_best_lap_global', undef, $text);
}
1;
<child>
<object class="GtkFrame" id="frame1">
<property name="visible">True</property>
- <property name="label_xalign">0.5</property>
+ <property name="label_xalign">0</property>
<child>
<object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
</child>
</object>
<packing>
+ <property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame2">
<property name="visible">True</property>
- <property name="label_xalign">0.5</property>
+ <property name="label_xalign">0</property>
<child>
<object class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
</child>
</object>
<packing>
+ <property name="padding">5</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame3">
<property name="visible">True</property>
- <property name="label_xalign">0.5</property>
+ <property name="label_xalign">0</property>
<child>
<object class="GtkAlignment" id="alignment3">
<property name="visible">True</property>
</child>
</object>
<packing>
+ <property name="padding">5</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
+ <property name="padding">10</property>
<property name="position">1</property>
</packing>
</child>