From: Mattia B. <mb...@ds...> - 2001-10-10 14:17:29
|
On Wed, 10 Oct 2001, Jouke Visser wrote: >Hi, > >I can't find a successful way to draw on the screen using some kind of >DC other than in an OnPaint or OnDraw method. I want to draw to a piece >of the screen from outside of those methods. The following examplecode >executes without errors or warnings, but shows an empty window: > >Any ideas why? I don't have a wxPerl at hand here, but if you draw from 'new' then the first paint event you get will destroy everything you painted. If this is just a test case, and you do the drawing from an event handler ( say in response to a menu/toolbar event ) then I need to check at home. Regards Mattia >#!/usr/bin/perl >use strict; >use Wx; > >package MyApp; >use base qw(Wx::App); > >sub OnInit { > my $this = shift; > my $frame = MyFrame->new( undef, 'Blah', [50,50], [420, 300] ); > > $frame->Show(1); > $this->SetTopWindow( $frame ); > $frame->Maximize(1); > > return 1; >} > >package MyFrame; >use base qw(Wx::Frame); > >use Wx qw(wxWHITE wxBITMAP_TYPE_GIF wxDEFAULT wxNORMAL >wxFONTENCODING_ISO8859_1); > >sub new { > my $class = shift; > my $this = $class->SUPER::new( $_[0], -1, @_[1,2,3] ); > > Wx::InitAllImageHandlers(); > > # create a scrolledwindow (canvas) > $this->{PANEL} = Wx::ScrolledWindow->new($this, -1); > $this->{PANEL}->SetBackgroundColour( wxWHITE ); > $this->{PANEL}->Show(1); > > # Initialize the DC > my $dc = Wx::ClientDC->new($this->{PANEL}); > $this->{PANEL}->PrepareDC($dc); > > # create bitmap > my $bmp = >Wx::Bitmap->new("h:/pABC/SOURCES/Plaatjes-syntheseprogr/SOK.gif", >wxBITMAP_TYPE_GIF); > my $image = Wx::Image->new($bmp); > $image->Rescale(200, 200); > $bmp = $image->ConvertToBitmap(); > $dc->DrawBitmap($bmp, 250, 0, 0); > > # draw some text > my $font = Wx::Font->new(100, wxDEFAULT, wxNORMAL, wxNORMAL, 0, "", >wxFONTENCODING_ISO8859_1); > $dc->SetFont($font); > $dc->DrawText("S O _", 250,225); > > return $this; >} > >package main; > >my $app = MyApp->new(); >$app->MainLoop(); > > > |