From 8b83962ae36e5857f1da21b451b0acbb3a55a289 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Tue, 7 Dec 2010 18:59:52 +0100 Subject: [PATCH] WIP: fullscreen mode --- SCX/GUI.pm | 81 +++++++++++++++++++++++++++++++++++++++++------- slotcarman.glade | 34 +++++++++++++------- 2 files changed, 91 insertions(+), 24 deletions(-) diff --git a/SCX/GUI.pm b/SCX/GUI.pm index 0e01d17..4f02edc 100755 --- a/SCX/GUI.pm +++ b/SCX/GUI.pm @@ -9,22 +9,13 @@ use Encode; use Gtk2 '-init'; use Glib qw(TRUE FALSE); -use SCX::Reader; +our $BASE_SIZE; sub new { my ($class, $args) = @_; my $self = { - throttle_images => [ - load_image_set('img/throttle%d.svg', 13, 100) - ], - fuel_images => [ - load_image_set('img/fuel%d.svg', 8, 60) - ], - car_images => load_image_dir('img/SCXCars', 100), - semaphore_images => [ - load_image_set('img/semaphore%d.svg', 5, 200) - ], + img_height => $args->{img_height} || 100, builder => Gtk2::Builder->new, semaphore_win => Gtk2::Window->new('popup'), semaphore_img => Gtk2::Image->new, @@ -35,6 +26,8 @@ sub new { $self->{builder}->add_from_file('slotcarman.glade'); $self->{builder}->connect_signals(undef); + $self->load_all_images; + $self->set_font_sizes; my $pixbuf = $self->{semaphore_images}->[0]; $self->{semaphore_img}->set_from_pixbuf($pixbuf); @@ -43,9 +36,14 @@ sub new { $self->{semaphore_win}->set_type_hint('splashscreen'); $self->{semaphore_win}->set_position('center-on-parent'); $self->{semaphore_win}->set_transient_for( - $self->{builder}->get_object('slotcarman') + $self->get_object('slotcarman') ); + $self->get_object('image_car1')->signal_connect( + 'size_allocate' => \&watch_resize, + $self, + ); + return $self; } @@ -59,8 +57,67 @@ sub show { sub delete_event { Gtk2->main_quit; } +sub quit { Gtk2->main_quit; } + +sub fullscreen { + my ($self) = @_; + + $self->get_object('slotcarman')->fullscreen; + my $h = $self->get_object('image_car1')->allocation->height; + print "h=$h\n"; +} + +sub watch_resize { + my ($window, $rectangle, $self) = @_; + print "w=", $rectangle->width, ", h=", $rectangle->height, "\n"; + # TODO +} + sub get_object { return shift->{builder}->get_object(@_); } +sub set_font_sizes { + my ($self) = @_; + + if ($self->{img_height} <= 80) { + $self->{label_font} = 10; + $self->{value_font} = 18; + $self->{lap_font} = 24; + } elsif ($self->{img_height} <= 100) { + $self->{label_font} = 12; + $self->{value_font} = 20; + $self->{lap_font} = 28; + } elsif ($self->{img_height} <= 120) { + $self->{label_font} = 14; + $self->{value_font} = 24; + $self->{lap_font} = 32; + } elsif ($self->{img_height} <= 150) { + $self->{label_font} = 16; + $self->{value_font} = 28; + $self->{lap_font} = 36; + } else { + $self->{label_font} = 18; + $self->{value_font} = 32; + $self->{lap_font} = 40; + } +} + +sub load_all_images { + my ($self) = @_; + + my $h = $self->{img_height}; + + $self->{throttle_images} = [ + load_image_set('img/throttle%d.svg', 13, $h) + ]; + $self->{fuel_images} = [ + load_image_set('img/fuel%d.svg', 8, int(0.6 * $h)) + ]; + $self->{car_images} = load_image_dir('img/SCXCars', $h), + $self->{semaphore_images} => [ + load_image_set('img/semaphore%d.svg', 5, 2 * $h) + ]; +}; + sub load_image_set { my ($pattern, $limit, $height) = @_; diff --git a/slotcarman.glade b/slotcarman.glade index 4e1d0df..ce10796 100644 --- a/slotcarman.glade +++ b/slotcarman.glade @@ -250,6 +250,7 @@ + False 1 @@ -371,6 +372,7 @@ 8 2 3 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -383,6 +385,7 @@ 8 4 5 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -395,6 +398,7 @@ 8 6 7 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -407,6 +411,7 @@ 8 8 9 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -419,6 +424,7 @@ 8 10 11 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -431,6 +437,7 @@ 8 12 13 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -443,6 +450,7 @@ 7 2 3 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -455,6 +463,7 @@ 7 4 5 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -467,6 +476,7 @@ 7 6 7 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -479,6 +489,7 @@ 7 8 9 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -491,6 +502,7 @@ 7 10 11 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -503,6 +515,7 @@ 7 12 13 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -515,6 +528,7 @@ 4 2 3 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -527,6 +541,7 @@ 4 4 5 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -539,6 +554,7 @@ 4 6 7 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -551,6 +567,7 @@ 4 8 9 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -563,6 +580,7 @@ 4 10 11 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -575,6 +593,7 @@ 4 12 13 + GTK_EXPAND | GTK_SHRINK | GTK_FILL @@ -822,7 +841,7 @@ True - 7 + 8 7 8 @@ -832,7 +851,7 @@ True - 7 + 8 9 10 @@ -842,7 +861,7 @@ True - 7 + 8 11 12 @@ -1102,15 +1121,6 @@ - - - - - - - - - 3 -- 2.43.5