Mark Dootson <[email protected]> writes:
> Within an EVT_PAINT handler you should always use Wx::PaintDC.
> Wx::ClientDC is only for drawing outside the PAINT event handler.
Yes, I found this very confusing since I use the same routine to draw
from outside and within.
> It also probably makes sense to only call the drawing code within the
> EVT_PAINT handler. You should find that a resize causes repainting
> anyhow.
>
> If you want to cause a repaint from your own code, better to call
> $window->Refresh(); which will cause a paint event when the system is
> ready to paint.
These tips are exactly what I was missing.
What I do now is:
sub draw {
...
my $img = Wx::Image->new( ... );
... some image manipulations ...
my $bm = Wx::Bitmap->new( $img );
my $dc = Wx::PaintDC->new( $panel );
$dc->Clear;
$dc->DrawBitmap( $bm, 0, 0, 0 );
}
sub OnPaint { ...; $self->draw; ... }
And instead of calling draw elsewhere, I now issue
$panel->Refresh;
Everything works and the flicker is gone.
Thanks!
-- Johan