From: Jouke V. <jo...@pv...> - 2001-10-10 13:19:27
|
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? #!/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(); -- *-----------------------------------------------* |Jouke Visser |jo...@pv... | |Perl GUI Geek |http://www.pvoice.org | *-----------------------------------------------* PS: Notice new mailaddress!! |
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(); > > > |
From: Jouke V. <jo...@pv...> - 2001-10-11 07:12:12
|
> >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. Eventually I indeed want to draw from an event handler, but for this test, I'm trying to create a ScrollWindow in a frame and try to paint on it from the constructor of the frame. The code gets executed without any warnings or errors, but the stuff just isn't displayed. Not even after a Refresh method or a resize ... > >#!/usr/bin/perl <snip code> > >package main; > > > >my $app = MyApp->new(); > >$app->MainLoop(); -- *-----------------------------------------------* |Jouke Visser |jo...@pv... | |Perl GUI Geek |http://www.pvoice.org | *-----------------------------------------------* PS: Notice new mailaddress!! |
From: Mattia B. <mb...@ds...> - 2001-10-11 19:29:00
|
> > >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. > Eventually I indeed want to draw from an event handler, but for this > test, I'm trying to create a ScrollWindow in a frame and try to paint on > it from the constructor of the frame. The code gets executed without any > warnings or errors, but the stuff just isn't displayed. Not even after a > Refresh method or a resize ... Yes, I understood, but my explanation was not clear at all: you are doing: * create the window * draw in the window * show the window ( causes a wxEraseEvent & wxPaintEvent ) * maximize the window ( another wxEraseEvent & wxPaintEvent couple ) So whatever you draw is subsequently erased... If you do: * create the window * show the window ( causes a wxEraseEvent & wxPaintEvent ) * draw in the window Then the picture is drawn and not erased ( until you resize/refresh the window ). Hope it's clearer now Regards Mattia |