4 my ($class, $name) = @_;
6 return AA::UI::GTK->new;
7 } elsif ($name =~ /\.pdf$/) {
8 return AA::UI::PDF->new($name);
9 } elsif ($name =~ /\.png$/) {
10 return AA::UI::PNG->new($name);
22 return bless($ui, $class);
35 my ($lastw, $lasth, $lastd) = (-1, -1, -1);
36 my ($pixw, $pixh) = (-1, -1);
40 my $win = $area->window;
41 my $wgc = Gtk2::Gdk::GC->new($win);
42 my $alloc = $area->allocation;
43 my $w = $alloc->width;
44 my $h = $alloc->height;
45 my $d = $win->get_depth;
46 # print "Area $w x $h x $d, xx=$xx\n";
48 if (!defined($pixmap) || $lastw != $w || $lasth != $h || $lastd != $d) {
49 ($lastw, $lasth, $lastd) = ($w, $h, $d);
57 print "Resized to ${w}x${h}, pixmap size ${pixw}x${pixh}\n";
59 $pixmap = Gtk2::Gdk::Pixmap->new($win, $pixw, $pixh, $d);
60 $cairo = Gtk2::Gdk::Cairo::Context->create($pixmap);
61 $cairo->select_font_face('URW Palladio L', 'normal', 'normal');
62 my $scale = $pixw/1024;
63 $cairo->scale($scale, $scale);
67 $wgc->set_rgb_background(0);
68 $wgc->set_rgb_foreground(0);
69 $win->draw_rectangle($wgc, 1, 0, 0, $w, $h);
72 $cairo->rectangle(0, 0, 1024, 768);
73 $cairo->set_source_rgb(0, 0, 0);
79 $win->draw_drawable($wgc, $pixmap, 0, 0, 0, 0, $pixw, $pixh);
88 $window = Gtk2::Window->new ('toplevel');
89 $area = Gtk2::DrawingArea->new();
90 $area->signal_connect("expose-event" => sub {
92 if (!defined $timer) {
93 $timer = Glib::Timeout->add(30, sub { $stopped || step(); return 1; });
96 $area->set_flags('can-focus');
97 # $area->add_events('key-press-mask');
98 $area->signal_connect('key-press-event' => sub {
100 my $k = Gtk2::Gdk::keyval_name(0, $evt->keyval);
101 print "Pressed key $k\n";
102 if ($k eq "Escape") {
104 } elsif ($k eq "space") {
105 $stopped = !$stopped;
106 } elsif ($k eq "f") {
107 if ($fullscreen = !$fullscreen) {
110 $window->unfullscreen;
112 } elsif ($k eq "Right") {
113 if ($u_scene+1 < @$u_scenario) {
115 &{$u_scenario->[$u_scene]};
121 $window->signal_connect ("delete-event" => sub { Gtk2->main_quit });
122 $window->set_title("Brum");
123 $window->set_wmclass("brum", "Brum");
124 $window->set_default_size(640, 480);
125 $window->add ($area);
129 sub RunScenario($$$) {
130 my ($ui, $scenario, $live) = @_;
131 $u_scenario = $scenario;
143 my ($class, $name) = @_;
145 $ui->{SURF} = Cairo::PdfSurface->create($name, 512, 384) or die "Unable to create PDF surface $name\n";
146 $ui->{CAIRO} = Cairo::Context->create($ui->{SURF});
147 $ui->{CAIRO}->scale(.5, .5);
148 return bless($ui, $class);
151 sub RunScenario($$$) {
152 my ($ui, $scenario) = @_;
154 foreach my $s (@$scenario) {
156 print "### Page $page ###\n";
159 AA->draw($ui->{CAIRO});
160 $ui->{CAIRO}->show_page;
169 my ($class, $name) = @_;
172 $ui->{SURF} = Cairo::ImageSurface->create('argb32', 1024, 768) or die "Unable to create image surface $name\n";
173 $ui->{CAIRO} = Cairo::Context->create($ui->{SURF});
174 return bless($ui, $class);
177 sub RunScenario($$$) {
178 my ($ui, $scenario) = @_;
179 my $cairo = $ui->{CAIRO};
181 foreach my $s (@$scenario) {
183 print "### Page $page ###\n";
188 my $name = sprintf($ui->{NAME}, $page);
189 $ui->{SURF}->write_to_png($name) or die "Unable to write to $name\n";