hi
i have discovered a two valuable "secret" tutorials by "Robert May" :
Drawing (Part 1):
http://www.mail-archive.com/perl-win32-gui-users@lists.sourceforge.net/msg05194.html
Drawing (Part 2) :
http://www.mail-archive.com/perl-win32-gui-users@lists.sourceforge.net/msg05195.html
found also on sourceforge.net site.
this is another response to the previous "rpnoble" question with a title:
Taking action after the call to Win32::GUI::Dialog()
i will refer to the tutorial Drawing (Part 2): it contains an example about
how to draw something on a click of a button, and how to refresh the screen
by copying the screen to memory then from memory to screen in the refresh
event if required, the example are fully documented, i wish it is encluded
in the examples with the win32gui package with a name such as DrawOnClick.pl
below i will copy the codes from that example with a small variations to
launch a windows with a green color, then when we click a button it will
draw a sine wave function and a blue rectangle, there is also a cls button.
the draw will not be erased when we cover the window with another window.
the dimensions are for 640x480 screen .
use Win32::GUI;
use warnings;
use strict;
use Win32::GUI qw( CW_USEDEFAULT RDW_VALIDATE RDW_NOCHILDREN COLOR_3DFACE );
# The size of the memory DC we will create to draw into
my ($WIDTH, $HEIGHT) = (640, 480);
my $mw = Win32::GUI::Window->new(
-title => 'Draw on click example',
-left => CW_USEDEFAULT,
-size => [ 640, 480 ],
-onPaint => \&paint,
);
$mw->AddButton(
-name => "Button1",
-text => "RUN ",
-pos => [ 0, 0 ],
-onClick => \&click,
);
$mw->AddButton(
-name => "Button2",
-text => "CLS ",
-pos => [ 0, 30 ],
);
# Create a memory DC to act as a buffer into which we'll
# do our drawing; then in the paint handler we'll just bitblt()
# from the memory DC to the screen.
my $memDC;
my $mem_bitmap;
{
my $dc = $mw->GetDC();
$memDC = $dc->CreateCompatibleDC();
$mem_bitmap = $dc->CreateCompatibleBitmap($WIDTH, $HEIGHT);
}
my $memDC_orig_state = $memDC->Save();
$memDC->SelectObject($mem_bitmap);
# Draw into the memory DC
FormLoadColor($memDC); # to paint the windows with green color
$mw->Show();
Win32::GUI::Dialog();
# Tidy up
$memDC->Restore($memDC_orig_state);
Win32::GUI::DC::DeleteObject($mem_bitmap);
Win32::GUI::DC::DeleteDC($memDC);
exit(0);
sub paint {
my ($self, $dc) = @_;
my $saved = $dc->Save();
{
my($l, $t, $r, $b) = $dc->GetUpdateRect(1);
if(defined $l) {
my $clip_rgn = Win32::GUI::Region->CreateRectRgn($l, $t, $r, $b);
$dc->SelectClipRgn($clip_rgn);
}
# Validate the whole window
$self->Redraw(RDW_VALIDATE | RDW_NOCHILDREN);
}
$dc->BitBlt(0,0,$WIDTH,$HEIGHT, $memDC, 0,0);
$dc->Restore();
return 1;
}
sub click {
my ($self) = @_;
MyDraw($memDC);
$self->GetParent->InvalidateRect(1);
return 1;
}
sub MyDraw {
my ($dc) = @_;
# Erase the background - COLOR_3DFACE is the window
# background color
my @colrB = "210,251,125"; #color of background
my @colrBR= map { split ',', $_ } @colrB;
$dc->FillRect( 0,0,$WIDTH,$HEIGHT,
#Win32::GUI::Brush->new( -system => COLOR_3DFACE ) );
Win32::GUI::Brush->new( [EMAIL PROTECTED]) );
# Do our (complex) drawing
@colrB = "98,89,249"; #color of rectangle
my $x=0; my $y=250;
@colrBR= map { split ',', $_ } @colrB;
my $P = new Win32::GUI::Pen(
-color => [ @colrBR],
-width => 1,
);
my $B = new Win32::GUI::Brush(
[EMAIL PROTECTED]
);
my $oldP = $dc->SelectObject($P);
my $oldB = $dc->SelectObject($B);
$dc->Rectangle(70, 60, 300, 200);
my @colrF = "245, 56, 10"; #color of the Plot
my $pointsize = "1";
my @colrFR= map { split ',', $_ } @colrF;
my $pi = 3.1415926;
for ($x = -(4*$pi); $x <= +(4*$pi); $x += 0.1) {
$P = new Win32::GUI::Pen(
-color => [ @colrFR],
-width => 1,
);
$B = new Win32::GUI::Brush(
[ @colrFR]
);
$oldP = $dc->SelectObject($P);
$oldB = $dc->SelectObject($B);
$y = sin($x);
my $x1 = $x*20 + 250;
$y = $y*30 + 250;
$dc->Circle($x1, $y,$pointsize);
}
return;
}
sub FormLoadColor {
my ($dc) = @_;
# Erase the background - COLOR_3DFACE is the window
# background color
my @colrB = "210,251,125"; #color of background
my @colrBR= map { split ',', $_ } @colrB;
$dc->FillRect( 0,0,$WIDTH,$HEIGHT,
#Win32::GUI::Brush->new( -system => COLOR_3DFACE ) );
Win32::GUI::Brush->new( [EMAIL PROTECTED]) );
}
sub Button2_Click {
my $dc = $mw->GetDC;
# Erase the background - COLOR_3DFACE is the window
# background color
$dc->FillRect( 0,50,$WIDTH,$HEIGHT,
Win32::GUI::Brush->new( -system => COLOR_3DFACE ) );
}
__END__
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/