my $stopped = 0;
my $fullscreen = 0;
my $movie = 0;
-my ($lastw, $lasth, $lastd) = (-1, -1, -1);
+my ($lastw, $lasth) = (-1, -1);
my ($pixw, $pixh) = (-1, -1);
my ($last_scene, $last_frame) = (-1, -1);
-sub draw($) {
+sub draw {
my ($force) = @_;
- my $win = $area->window;
- my $wgc = Gtk2::Gdk::GC->new($win);
- my $alloc = $area->allocation;
- my $w = $alloc->width;
- my $h = $alloc->height;
- my $d = $win->get_depth;
- # print "Area $w x $h x $d, xx=$xx\n";
+ if (!$force) {
+ $area->queue_draw();
+ return;
+ }
+
+ my $w = $area->get_allocated_width;
+ my $h = $area->get_allocated_height;
+ # print "Area $w x $h\n";
- if (!defined($pixmap) || $lastw != $w || $lasth != $h || $lastd != $d) {
- ($lastw, $lasth, $lastd) = ($w, $h, $d);
+ if ($lastw != $w || $lasth != $h) {
+ ($lastw, $lasth) = ($w, $h);
if ($w/$h >= 4/3) {
$pixh = $h;
$pixw = int($h/3*4);
$pixh = int($w/4*3);
}
print "Resized to ${w}x${h}, pixmap size ${pixw}x${pixh}\n" if $debug;
-
- $pixmap = Gtk2::Gdk::Pixmap->new($win, $pixw, $pixh, $d);
- $cairo = Gtk2::Gdk::Cairo::Context->create($pixmap);
- my $scale = $pixw/1024;
- $cairo->scale($scale, $scale);
}
- if ($force) {
- $wgc->set_rgb_background(0);
- $wgc->set_rgb_foreground(0);
- $win->draw_rectangle($wgc, 1, 0, 0, $w, $h);
- }
-
- $cairo->rectangle(0, 0, 1024, 768);
+ $cairo->rectangle(0, 0, $w, $h);
$cairo->set_source_rgb(0, 0, 0);
$cairo->fill;
+ $cairo->translate(($w - $pixw) / 2, 0);
+ my $scale = $pixw/1024;
+ $cairo->scale($scale, $scale);
+
if (@u_scenes) {
print "@@@ Scene $u_scene frame $u_frame\n" if $debug;
$u_scenes[$u_scene]->[$u_frame]->Draw($cairo);
AA->draw($cairo);
}
- $win->draw_drawable($wgc, $pixmap, 0, 0, 0, 0, $pixw, $pixh);
$last_scene = $u_scene;
$last_frame = $u_frame;
}
}
sub prepare() {
- $window = Gtk2::Window->new ('toplevel');
- $area = Gtk2::DrawingArea->new();
- $area->signal_connect("expose-event" => sub {
+ $window = Gtk3::Window->new ('toplevel');
+ $area = Gtk3::DrawingArea->new();
+ $area->signal_connect("draw" => sub {
+ my ($w, $cr) = @_;
+ $cairo = $cr;
draw(1);
if (!defined $timer) {
$timer = Glib::Timeout->add(30, sub { $stopped || step(); return 1; });
}
});
- $area->set_flags('can-focus');
- # $area->add_events('key-press-mask');
+ $area->set_can_focus(1);
+ $area->add_events('key-press-mask');
$area->signal_connect('key-press-event' => sub {
my ($w, $evt) = @_;
- my $k = Gtk2::Gdk::keyval_name(0, $evt->keyval);
+ my $k = Gtk3::Gdk::keyval_name($evt->keyval);
print "Pressed key $k\n" if $debug;
if ($k eq "Escape") {
- Gtk2->main_quit;
+ Gtk3->main_quit;
} elsif ($k eq "f") {
if ($fullscreen = !$fullscreen) {
$window->fullscreen;
}
});
- $window->signal_connect ("delete-event" => sub { Gtk2->main_quit });
+ $window->signal_connect ("delete-event" => sub { Gtk3->main_quit });
$window->set_title("Brum");
$window->set_wmclass("brum", "Brum");
$window->set_default_size(640, 480);
$u_frame = 0;
$u_direction = 0;
prepare();
- Gtk2->main;
+ Gtk3->main;
}
package AA::UI::PDF;