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

This is my desired goal: I want to create an app that displays an image and then lets me "draw" on it, simple lines mostly, nothing fancy. After scanning through the Wx docs I found the Wx::ClientDC class which has several methods like "DrawBitmap" and "DrawLine" which looked like exactly what I needed.

However, nothing I've done has come close to working. My code is below. Am I simply making a mistake? Is there a better class I should be using? The code below simply opens a 500 x 500 frame. No rectangle or black of any kind.

use strict; use Wx qw/wxSOLID/; package MGV; use base 'Wx::App'; sub OnInit { my $self = shift; my $frame = Wx::Frame->new( undef, -1, 'title', [500,500], [500,500] ); my $dc = Wx::ClientDC->new( $frame ); $dc->SetBrush( Wx::Brush->new( 'black', Wx::wxSOLID ) ); $dc->DrawRectangle( 100,100, 200,200 ); $frame->Show( 1 ); } package main; MGV->new()->MainLoop();


Update: I think I solved my issue. I changed to using a Wx::PaintDC in a EVT_PAINT:
$self->EVT_PAINT( sub{ my $dc = Wx::PaintDC->new( $frame ); $dc->BeginDrawing(); $dc->DrawRectangle( 100,100, 200,200 ); $dc->EndDrawing(); } );

Replies are listed 'Best First'.
Re: WxPerl, Wx::ClientDC, displaying images
by Steve_BZ (Chaplain) on Sep 11, 2009 at 02:05 UTC

    OK, I think it should look like this:

    use strict; use Wx qw/wxSOLID/; package MGV; use base 'Wx::App'; sub OnInit { my $self = shift; $self->{frame} = Wx::Frame->new( undef, -1, 'title', [500,500], [50 +0,500] ); Wx::Event::EVT_PAINT($self,\&paint); sub paint{ my ($self,$event) = @_; my $dc = Wx::PaintDC->new( $self->{frame} ); $dc->DrawRectangle( 100,100, 200,200 ); } $self->{frame}->Show( 1 ); } package main; MGV->new()->MainLoop();

    Thanks for posting