4 my ($class, $name) = @_;
6 return AA::UI::GTK->new(1);
7 } elsif ($name eq "gtk") {
8 return AA::UI::GTK->new(0);
9 } elsif ($name =~ /\.pdf$/) {
10 return AA::UI::PDF->new($name);
11 } elsif ($name =~ /\.png$/) {
12 return AA::UI::PNG->new($name);
21 my ($class, $mode) = @_;
25 return bless($ui, $class);
39 my ($lastw, $lasth, $lastd) = (-1, -1, -1);
40 my ($pixw, $pixh) = (-1, -1);
44 my $win = $area->window;
45 my $wgc = Gtk2::Gdk::GC->new($win);
46 my $alloc = $area->allocation;
47 my $w = $alloc->width;
48 my $h = $alloc->height;
49 my $d = $win->get_depth;
50 # print "Area $w x $h x $d, xx=$xx\n";
52 if (!defined($pixmap) || $lastw != $w || $lasth != $h || $lastd != $d) {
53 ($lastw, $lasth, $lastd) = ($w, $h, $d);
61 print "Resized to ${w}x${h}, pixmap size ${pixw}x${pixh}\n";
63 $pixmap = Gtk2::Gdk::Pixmap->new($win, $pixw, $pixh, $d);
64 $cairo = Gtk2::Gdk::Cairo::Context->create($pixmap);
65 $cairo->select_font_face('URW Palladio L', 'normal', 'normal');
66 my $scale = $pixw/1024;
67 $cairo->scale($scale, $scale);
71 $wgc->set_rgb_background(0);
72 $wgc->set_rgb_foreground(0);
73 $win->draw_rectangle($wgc, 1, 0, 0, $w, $h);
76 $cairo->rectangle(0, 0, 1024, 768);
77 $cairo->set_source_rgb(0, 0, 0);
81 $u_scenes[$u_scene]->Draw($cairo);
82 $cairo->set_source_rgb(.5, .5, .5);
83 $cairo->set_font_size(15);
84 $cairo->move_to(950,750);
85 $cairo->show_text($u_scene . "/" . $#u_scenes);
91 $win->draw_drawable($wgc, $pixmap, 0, 0, 0, 0, $pixw, $pixh);
100 $window = Gtk2::Window->new ('toplevel');
101 $area = Gtk2::DrawingArea->new();
102 $area->signal_connect("expose-event" => sub {
104 if (!defined $timer) {
105 $timer = Glib::Timeout->add(30, sub { $stopped || step(); return 1; });
108 $area->set_flags('can-focus');
109 # $area->add_events('key-press-mask');
110 $area->signal_connect('key-press-event' => sub {
112 my $k = Gtk2::Gdk::keyval_name(0, $evt->keyval);
113 print "Pressed key $k\n";
114 if ($k eq "Escape") {
116 } elsif ($k eq "f") {
117 if ($fullscreen = !$fullscreen) {
120 $window->unfullscreen;
122 } elsif ($k eq "space" || $k eq "Right" || $k eq "Page_Down") {
124 if ($u_scene+1 < @u_scenes) {
129 if ($u_scene+1 < @$u_scenario) {
131 &{$u_scenario->[$u_scene]};
135 } elsif ($k eq "BackSpace" || $k eq "Left" || $k eq "Page_Up") {
136 if (@u_scenes && $u_scene) {
140 } elsif ($k eq "Home" || $k eq "0") {
145 } elsif ($k eq "End" || $k eq "9") {
147 $u_scene = $#u_scenes;
153 $window->signal_connect ("delete-event" => sub { Gtk2->main_quit });
154 $window->set_title("Brum");
155 $window->set_wmclass("brum", "Brum");
156 $window->set_default_size(640, 480);
157 $window->add ($area);
161 sub RunScenario($$) {
162 my ($ui, $scenario) = @_;
165 print "Rendering...\n";
166 foreach my $s (@$scenario) {
169 push @u_scenes, AA::Scene->new();
173 $u_scenario = $scenario;
187 my ($class, $name) = @_;
189 $ui->{SURF} = Cairo::PdfSurface->create($name, 512, 384) or die "Unable to create PDF surface $name\n";
190 $ui->{CAIRO} = Cairo::Context->create($ui->{SURF});
191 $ui->{CAIRO}->scale(.5, .5);
192 return bless($ui, $class);
195 sub RunScenario($$$) {
196 my ($ui, $scenario) = @_;
198 foreach my $s (@$scenario) {
200 print "### Page $page ###\n";
203 AA->draw($ui->{CAIRO});
204 $ui->{CAIRO}->show_page;
213 my ($class, $name) = @_;
216 $ui->{SURF} = Cairo::ImageSurface->create('argb32', 1024, 768) or die "Unable to create image surface $name\n";
217 $ui->{CAIRO} = Cairo::Context->create($ui->{SURF});
218 return bless($ui, $class);
221 sub RunScenario($$$) {
222 my ($ui, $scenario) = @_;
223 my $cairo = $ui->{CAIRO};
225 foreach my $s (@$scenario) {
227 print "### Page $page ###\n";
232 my $name = sprintf($ui->{NAME}, $page);
233 $ui->{SURF}->write_to_png($name) or die "Unable to write to $name\n";