Add libwx-perl
[pkg-perl] / deb-src / libwx-perl / libwx-perl-0.96 / samples / hello / hello.pl
1 #!/usr/bin/perl -w
2 #############################################################################
3 ## Name:        samples/hello/hello.pl
4 ## Purpose:     Hello wxPerl sample
5 ## Author:      Mattia Barbon
6 ## Modified by:
7 ## Created:     02/11/2000
8 ## RCS-ID:      $Id: hello.pl 2057 2007-06-18 23:03:00Z mbarbon $
9 ## Copyright:   (c) 2000, 2004, 2006 Mattia Barbon
10 ## Licence:     This program is free software; you can redistribute it and/or
11 ##              modify it under the same terms as Perl itself
12 #############################################################################
13
14 use Wx;
15
16 package MyFrame;
17
18 use strict;
19 use base qw(Wx::Frame);
20
21 use Wx::Event qw(EVT_PAINT);
22 # this imports some constants
23 use Wx qw(wxDECORATIVE wxNORMAL wxBOLD);
24 use Wx qw(wxDefaultPosition);
25 use Wx qw(wxWHITE);
26
27 sub new {
28     my( $class ) = @_;
29     # new frame with no parent, id -1, title 'Hello, world!'
30     # default position and size 350, 100
31     my $this = $class->SUPER::new( undef, -1, 'Hello, world!',
32                                    wxDefaultPosition , [350, 100] );
33
34     # create a new font object and store it
35     $this->{font} = Wx::Font->new( 40, wxDECORATIVE, wxNORMAL, wxBOLD, 0 );
36     # set background colour
37     $this->SetBackgroundColour( wxWHITE );
38
39     $this->SetIcon( Wx::GetWxPerlIcon() );
40
41     # declare that all paint events will be handled with the OnPaint method
42     EVT_PAINT( $this, \&OnPaint );
43
44     return $this;
45 }
46
47 sub OnPaint {
48     my( $this, $event ) = @_;
49     # create a device context (DC) used for drawing
50     my $dc = Wx::PaintDC->new( $this );
51
52     # select the font
53     $dc->SetFont( $this->font );
54     # draw a friendly message
55     $dc->DrawText( 'Hello, world!', 10, 10 );
56 }
57
58 sub font { $_[0]->{font} }
59
60 package main;
61
62 my $app  = Wx::SimpleApp->new;
63 my $frame = MyFrame->new;
64 $frame->Show;
65 $app->MainLoop;