}
}
-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);
}
}
}
+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;
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$/) {
@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;
$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);
}
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);
}
}
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;
}