bkv2k has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use wxPerl for a project. I need to use DrawPolygon. I've had no luck calling this method. Can anyone show an example of how to call this method in an OnPaint event handler? Thanks for any help you're able to provide.

20090715 Janitored by Corion: Restored content, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: wxPerl DrawPolygon
by Anonymous Monk on Jul 15, 2009 at 16:09 UTC
      Again, thanks to those trying to help with this problem. I think I finally figured out how to call wxPerl DrawPolygon. Here's what I came up with:
      # This code in file main.pl. #!/usr/bin/perl package MyApp; use warnings; use strict; use Wx; use AppFrame; use vars qw( @ISA ); our @ISA = qw( Wx::App ); sub OnInit { my $self = shift; # Create new main application frame. my $frame = AppFrame->new( "Test DrawPolygon", Wx::Point->new( 50, + 50 ), Wx::Size->new( 640, 480 ) ); $frame->SetBackgroundColour( Wx::wxBLUE ); $self->SetTopWindow( $frame ); $frame->Center(); $frame->Show( 1 ); return 1; } package main; my( $app ) = MyApp->new(); $app->MainLoop(); # This code in file AppFrame.pm. #!/usr/bin/perl package AppFrame; use warnings; use strict; use Wx; use MyCanvas; our ( @ISA ) = qw( Wx::Frame ); sub new { my $class = shift; $class = ref( $class ) || $class; my ( $title, $pos, $size ) = @_; $title = defined( $title ) ? $title : "wxPerl"; $pos = defined( $pos ) ? $pos : Wx::Point->new( 0, 0 ); $size = defined( $size ) ? $size : Wx::Size->new( 50, 50 ); my $self = $class->SUPER::new( undef, -1, $title, $pos, $size ); bless( $self, $class ); # Create canvas. $self->{CANVAS} = MyCanvas->new( $self, -1, $pos, $size ); return $self; } return 1; # This code in file MyCanvas.pm. #!/usr/bin perl package MyCanvas; use warnings; use strict; use Wx; our ( @ISA ) = qw( Wx::Panel ); sub new { my ($class, $parent, $id, $pos, $size) = @_; $class = ref( $class ) || $class; $id = defined( $id ) ? $id : -1; $pos = defined( $pos ) ? $pos : Wx::wxDefaultPosition; $size = defined( $size ) ? $size : Wx::wxDefaultSize; my $self = $class->SUPER::new( $parent, $id, $pos, $size ); bless( $self, $class ); $self->SetBackgroundColour( Wx::wxBLUE ); use Wx::Event qw( EVT_PAINT ); EVT_PAINT( $self, \&on_paint ); return $self; } use Wx qw( wxGREEN_PEN wxGREEN_BRUSH ); sub on_paint { my ($self, $event) = @_; my $dc = Wx::PaintDC->new( $self ); $dc->SetPen( wxGREEN_PEN ); $dc->SetBrush( wxGREEN_BRUSH ); $dc->DrawPolygon( [ Wx::Point->new(319, 239), Wx::Point->new(311, +236), Wx::Point->new(311, 242) ], 0, 0 ); } return 1;
Re: wxPerl DrawPolygon
by Anonymous Monk on Jul 15, 2009 at 13:43 UTC
    I've had no luck calling this method

    Show your code please.

      Sorry! I tried adding code and updating. Not good. Don't know how to fix it.
      Thanks for attempting to help. The code I tried to post was unreadable. I think I've figured out how to delete the it. Sorry for the mess.