File: draw-widget.pl

package info (click to toggle)
libcairo-gobject-perl 1.004-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 172 kB
  • ctags: 2
  • sloc: perl: 125; makefile: 5
file content (24 lines) | stat: -rw-r--r-- 669 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/perl
use Cairo::GObject;
use Glib::Object::Introspection;

Glib::Object::Introspection->setup (
  basename => 'Gtk',
  version => '3.0',
  package => 'Gtk3');
Gtk3::init ([]);

my $window = Gtk3::Window->new ('toplevel');
my $button = Gtk3::Button->new_with_label ('Kazam!');
$window->add ($button);
$window->show_all;

my ($width, undef) = $button->get_preferred_width;
my ($height, undef) = $button->get_preferred_height;
my $surf = Cairo::ImageSurface->create ('argb32', $width,$height);
my $cr = Cairo::Context->create ($surf);

Glib::Idle->add (sub { $button->draw ($cr); Gtk3::main_quit (); });
Gtk3::main ();

$surf->write_to_png ('draw-widget.png');