]> mj.ucw.cz Git - anim.git/blob - gdktest.pl
2ec701bcccd3591ad52a03a5be7891f585803d0d
[anim.git] / gdktest.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Gtk2 -init;
7
8 my $area = Gtk2::DrawingArea->new();
9 my $xx = 0;
10 sub draw() {
11         my $win = $area->window;
12         my $alloc = $area->allocation;
13         my $w = $alloc->width;
14         my $h = $alloc->height;
15         print "Area $w x $h\n";
16
17         ## my $sty = $area->style;
18         ## my $gc = $sty->fg_gc($area->state);
19         my $gc = Gtk2::Gdk::GC->new($win);
20         $gc->set_rgb_background(0x000000);
21         $gc->set_rgb_foreground(0x000000);
22         $win->draw_rectangle($gc, 1, 0, 0, $w, $h);
23         $gc->set_rgb_foreground(0x00ff00);
24         $win->draw_line($gc, $xx, 0, $w-1, $h-1);
25         $xx++;
26         if ($xx >= $w) { $xx=0; }
27 }
28
29 my $timer;
30 $area->signal_connect("expose-event" => sub {
31         draw();
32         if (!defined $timer) {
33                 $timer = Glib::Timeout->add(10, sub { draw(); return 1; });
34         }
35 });
36
37 my $window = Gtk2::Window->new ('toplevel');
38 $window->signal_connect ("delete-event" => sub { Gtk2->main_quit });
39 $window->set_title("Brum");
40 $window->set_wmclass("anim", "Anim");
41 $window->set_default_size(640, 480);
42 $window->add ($area);
43 $window->show_all;
44 #$window->fullscreen;
45
46 Gtk2->main;