#!/usr/bin/perl

use strict;
use warnings;

use Gtk2 -init;

my $area = Gtk2::DrawingArea->new();
my $xx = 0;
sub draw() {
	my $win = $area->window;
	my $alloc = $area->allocation;
	my $w = $alloc->width;
	my $h = $alloc->height;
	print "Area $w x $h\n";

	## my $sty = $area->style;
	## my $gc = $sty->fg_gc($area->state);
	my $gc = Gtk2::Gdk::GC->new($win);
	$gc->set_rgb_background(0x000000);
	$gc->set_rgb_foreground(0x000000);
	$win->draw_rectangle($gc, 1, 0, 0, $w, $h);
	$gc->set_rgb_foreground(0x00ff00);
	$win->draw_line($gc, $xx, 0, $w-1, $h-1);
	$xx++;
	if ($xx >= $w) { $xx=0; }
}

my $timer;
$area->signal_connect("expose-event" => sub {
	draw();
	if (!defined $timer) {
		$timer = Glib::Timeout->add(10, sub { draw(); return 1; });
	}
});

my $window = Gtk2::Window->new ('toplevel');
$window->signal_connect ("delete-event" => sub { Gtk2->main_quit });
$window->set_title("Brum");
$window->set_wmclass("anim", "Anim");
$window->set_default_size(640, 480);
$window->add ($area);
$window->show_all;
#$window->fullscreen;

Gtk2->main;
