Hi Huub,

Thanks for the help.

In fact I never got the original code to work.

However, your pointer to the OnPaint event and drawing on a Panel within 
the OnPaint was very useful.  I've got it working perfectly.

However, I do need to do dynamic drawing.  Each event needs to be recorded 
in a graphical way.  Should I keep redrawing the Panel, or should I use 
DC:Memory as you also suggest?

Ideas welcome.

Regards

Steve




-----Original Message-----
From: Huub Peters [mailto:i...@huubpeters.com] 
Sent: 11 September 2009 09:50
To: Steve Cookson
Cc: wxperl-users@perl.org
Subject: Re: Wx::PaintDC misunderstandings.

Steve Cookson wrote:
>
> Hi,
>
> I'm sure I've just misunderstood something simple about images, but 
> what have I done wrong here:
>
>      my $loc_image = Wx::Image->new(560,20);
>      my $loc_bmp;    # used to hold the bitmap.
>      $loc_bmp=Wx::Bitmap->new( $loc_image );
>      my $dc = Wx::PaintDC->new($self->{$loc_bmp});
>      $dc->DrawRectangle(0, 0, 20, 20);
>      if( $loc_bmp->Ok() ) {
>             #  create a static bitmap called
>     Ctl_Post_Exam_Videos_ImageViewer_Bmp that displays the
>             #  selected image.
>       $self->{Ctl_Post_Exam_Videos_ImageViewer_Bmp}=
>     Wx::StaticBitmap->new($self->{Ctl_Post_Exam_Videos_Pane_1}, -1,
>     $loc_bmp);
>      }
>
$self->{Ctl_Post_Exam_Videos_Sizer_2}->Add($self->{Ctl_Post_Exam_Videos_Imag
eViewer_Bmp},
>     0, 0, 0);
>
> I expected to get a black rectangle 560 x 20 (from  my $loc_image = 
> Wx::Image->new(560,20);)
>
> with the first 20px cut off (from $dc->DrawRectangle(0, 0, 20, 20);).
>
> I get the first but not the second. Using ClientDC instead of PaintDC 
> doesn't work either.
>
> Regards
>
> Steve
>

I think you are drawing a black rectangle on a black image. Try changing 
pen and/or brush colour:

    $dc->SetBrush( wxRED_BRUSH );
or
    my $pen = Wx::Pen->new( Wx::Colour->new(255,255,255), 2, wxSOLID);
    $dc->SetPen( $pen );

Also, if you plan on doing extensive drawing consider using a MemoryDC 
to draw bitmaps dynamically:

    $self->{BUFFER} = Wx::Bitmap->new(
        400,
        400,
        -1
    );
    $mdc = Wx::MemoryDC->new();
    $mdc->SelectObject($self->{BUFFER});
    $mdc->SetBackground(
        Wx::Brush->new(
            Wx::Colour->new( 255, 255, 255),
            wxSOLID
        )
    );
    $mdc->Clear();
    $mdc->SetBrush( wxBLACK_BRUSH );
    $mdc->SetPen( wxBLACK_PEN );
    $mdc->DrawCircle( 200,200, 195 );
    $mdc->SelectObject(wxNullBitmap); # deselect the bitmap out of the DC

Also have a look at the OnPaint event. I find drawing on a Panel within 
the OnPaint event to be a powerfull replacement of StaticBitmap

Cheers,
Huub

Reply via email to