]> www.fi.muni.cz Git - slotcarman.git/blobdiff - SCX/GUI.pm
Button reporting, fullscreen mode.
[slotcarman.git] / SCX / GUI.pm
index da3f9f45eb6a9256625fe9dc37ae2191d0bce495..08b4ea90354f1de859c069aaa0819d7e551fc0e0 100755 (executable)
@@ -8,6 +8,7 @@ use utf8;
 use Carp;
 use Encode;
 use Gtk2 '-init';
+use Gtk2::Gdk::Keysyms;
 use Glib qw(TRUE FALSE);
 
 our $BASE_SIZE;
@@ -26,7 +27,7 @@ sub new {
 
        $self->{builder}->add_from_file('slotcarman.glade');
 
-       $self->{builder}->connect_signals(undef);
+       $self->{builder}->connect_signals($self);
        $self->load_all_images;
        $self->set_font_sizes;
 
@@ -60,14 +61,52 @@ sub delete_event { Gtk2->main_quit; }
 
 sub quit { Gtk2->main_quit; }
 
+use Data::Dumper;
+
+sub hotkey {
+       my ($window, $key, $self) = @_;
+
+       if ($key->keyval == $Gtk2::Gdk::Keysyms{F5}) {
+               if ($self->{fullscreen}) {
+                       leave_fullscreen($window, $self);
+               } else {
+                       fullscreen($window, $self);
+               }
+               return 1;
+       }
+       return 0;
+}
+
 sub fullscreen {
-       my ($self) = @_;
+       my ($widget, $self) = @_;
+
+       return if $self->{fullscreen};
 
+       $self->get_object('menubar1')->hide;
+       $self->get_object('statusbar1')->hide;
        $self->get_object('slotcarman')->fullscreen;
+
+       $self->{fullscreen} = 1;
        my $h = $self->get_object('image_car1')->allocation->height;
-       print "h=$h\n";
+       my $h1 = $self->get_object('slotcarman')->allocation->height;
+       print "h=$h, h1=$h1\n";
 }
-       
+
+sub leave_fullscreen {
+       my ($widget, $self) = @_;
+
+       return if !$self->{fullscreen};
+
+       $self->get_object('menubar1')->show;
+       $self->get_object('statusbar1')->show;
+       $self->get_object('slotcarman')->unfullscreen;
+
+       $self->{fullscreen} = undef;;
+       my $h = $self->get_object('image_car1')->allocation->height;
+       my $h1 = $self->get_object('slotcarman')->allocation->height;
+       print "h=$h, h1=$h1\n";
+}
+
 sub watch_resize {
        my ($window, $rectangle, $self) = @_;
        print "w=", $rectangle->width, ", h=", $rectangle->height, "\n";
@@ -110,6 +149,9 @@ sub load_all_images {
        $self->{throttle_images} = [
                load_image_set('img/throttle%d.svg', 13, $h)
        ];
+       $self->{throttle_button_images} = [
+               load_image_set('img/throttle%dbutton.svg', 12, $h)
+       ];
        $self->{fuel_images} = [
                        load_image_set('img/fuel%d.svg', 8, int(0.6 * $h))
        ];
@@ -194,10 +236,11 @@ sub set_image {
 }
 
 sub set_throttle {
-       my ($self, $row, $val) = @_;
+       my ($self, $row, $val, $button) = @_;
 
        $val = 13 if !defined $val;
-       $self->set_image('image_throttle', $row, 'throttle', $val);
+       $self->set_image('image_throttle', $row,
+               $button ? 'throttle_button' : 'throttle', $val);
 }
 
 sub set_fuel {