From: Martin Mares Date: Sun, 28 Oct 2007 22:24:22 +0000 (+0100) Subject: Mrazeni scen a obousmerny posun v GUI. X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=a670bf0d09877b50a6c69718b0b327a1e10c5c0e;p=anim.git Mrazeni scen a obousmerny posun v GUI. --- diff --git a/AA.pm b/AA.pm index c4fcc59..233df11 100644 --- a/AA.pm +++ b/AA.pm @@ -42,14 +42,18 @@ sub calculate($) { } } -sub draw($$) { - my ($class, $cairo) = @_; +sub get_visible_objects() { my @q = (); - print "Redrawing the scene...\n" if $debug; foreach my $o (values %known_objs) { push @q, $o if defined $o->{'a:d'}; } - foreach my $o (sort { $a->{'a:d'} <=> $b->{'a:d'} } @q) { + return sort { $a->{'a:d'} <=> $b->{'a:d'} } @q; +} + +sub draw($$) { + my ($class, $cairo) = @_; + print "Redrawing the scene...\n" if $debug; + foreach my $o (get_visible_objects()) { print "Drawing $o at depth ", $o->{'a:d'}, "\n" if $debug; $o->Draw($cairo); } @@ -186,4 +190,34 @@ sub MultiSet($@) { } } +package AA::Scene; + +sub new($) { + my ($class) = @_; + my $scene = []; + print "Simulated draw...\n" if $debug; + foreach my $o (AA::get_visible_objects()) { + print "Drawing $o at depth ", $o->{'a:d'}, "\n" if $debug; + my $obj = [$o]; + foreach my $k (keys %$o) { + $k =~ /^a:/ && push @$obj, $k, $o->{$k}; + } + push @$scene, $obj; + } + return bless($scene, $class); +} + +sub Draw($$) { + my ($scene, $cairo) = @_; + foreach my $obj (@$scene) { + my $o = $obj->[0]; + for (my $i=1; $i<@$obj; $i+=2) { + my $a =$obj->[$i]; + my $v =$obj->[$i+1]; + $o->{$a} = $v; + } + $o->Draw($cairo); + } +} + 1; diff --git a/AA/UI.pm b/AA/UI.pm index c20318e..0b7af2e 100644 --- a/AA/UI.pm +++ b/AA/UI.pm @@ -3,7 +3,9 @@ package AA::UI; sub new($$) { my ($class, $name) = @_; if ($name eq "") { - return AA::UI::GTK->new; + return AA::UI::GTK->new(1); + } elsif ($name eq "gtk") { + return AA::UI::GTK->new(0); } elsif ($name =~ /\.pdf$/) { return AA::UI::PDF->new($name); } elsif ($name =~ /\.png$/) { @@ -15,15 +17,17 @@ package AA::UI::GTK; @ISA = ('AA::UI'); -sub new($) { - my ($class) = @_; +sub new($$) { + my ($class, $mode) = @_; my $ui = { + MODE => $mode, }; return bless($ui, $class); } my $u_scenario; my $u_scene; +my @u_scenes = (); my $window; my $cairo; @@ -73,8 +77,16 @@ sub draw($) { $cairo->set_source_rgb(0, 0, 0); $cairo->fill; - AA->calculate; - AA->draw($cairo); + if (@u_scenes) { + $u_scenes[$u_scene]->Draw($cairo); + $cairo->set_source_rgb(.5, .5, .5); + $cairo->set_font_size(15); + $cairo->move_to(950,750); + $cairo->show_text($u_scene . "/" . $#u_scenes); + } else { + AA->calculate; + AA->draw($cairo); + } $win->draw_drawable($wgc, $pixmap, 0, 0, 0, 0, $pixw, $pixh); } @@ -101,18 +113,38 @@ sub prepare() { print "Pressed key $k\n"; if ($k eq "Escape") { Gtk2->main_quit; - } elsif ($k eq "space") { - $stopped = !$stopped; } elsif ($k eq "f") { if ($fullscreen = !$fullscreen) { $window->fullscreen; } else { $window->unfullscreen; } - } elsif ($k eq "Right") { - if ($u_scene+1 < @$u_scenario) { - $u_scene++; - &{$u_scenario->[$u_scene]}; + } elsif ($k eq "space" || $k eq "Right" || $k eq "Page_Down") { + if (@u_scenes) { + if ($u_scene+1 < @u_scenes) { + $u_scene++; + draw(0); + } + } else { + if ($u_scene+1 < @$u_scenario) { + $u_scene++; + &{$u_scenario->[$u_scene]}; + draw(0); + } + } + } elsif ($k eq "BackSpace" || $k eq "Left" || $k eq "Page_Up") { + if (@u_scenes && $u_scene) { + $u_scene--; + draw(0); + } + } elsif ($k eq "Home" || $k eq "0") { + if (@u_scenes) { + $u_scene = 0; + draw(0); + } + } elsif ($k eq "End" || $k eq "9") { + if (@u_scenes) { + $u_scene = $#u_scenes; draw(0); } } @@ -128,9 +160,21 @@ sub prepare() { sub RunScenario($$$) { my ($ui, $scenario, $live) = @_; - $u_scenario = $scenario; + + if ($ui->{MODE}) { + print "Rendering...\n"; + foreach my $s (@$scenario) { + &$s; + AA->calculate; + push @u_scenes, AA::Scene->new(); + } + print "Ready.\n"; + } else { + $u_scenario = $scenario; + &{$scenario->[0]}; + } + $u_scene = 0; - &{$scenario->[0]}; prepare(); Gtk2->main; } diff --git a/a.pl b/a.pl index 57b3d93..ca03003 100755 --- a/a.pl +++ b/a.pl @@ -81,7 +81,7 @@ if (!@ARGV || $ARGV[0] eq "1") { sub { flow(3, 5); hint(-1); }, ]; } elsif ($ARGV[0] eq "2") { - $title->Set('text', "Goldberg podruhé"); + $title->Set('text', "Goldberg v úzkých"); for (my $i=0; $i<@v-1; $i++) { $e[$i]->Set('c', 5-$i); }