Hi,

All I can say is that DC/Paint does work - and quite well. Although it does take a while to get your head around things. In the end I did go for using GD as the graphics engine (along with DIBitmap) since there was a performance issue using native windows drawing.

Below is an example from the from 558. I could probably dig out a paint/validate example if that would help.

Cheers,

jez.

use Win32::GUI;

$Menu = Win32::GUI::MakeMenu(
   "&Draw" => "&Draw",
   ">  &Dots"   => "DrawDots",
   ">  &Lines"   => "DrawLines",
   ">  &Boxes"   => { -name => "DrawBoxes", -checked => 1 },
   ">  &Circles" => "DrawCircles",
);

$Win = new Win32::GUI::Window(
   -left   => 100,
   -top    => 100,
   -width  => 300,
   -height => 300,
   -name   => "Window",
   -text   => "Win32::GUI drawing demo",
   -menu   => $Menu,
);

$Timer = $Win->AddTimer("Timer1", 50);

srand();

$Win->Show();
Win32::GUI::Dialog();

sub Window_Terminate {
   return -1;
}

sub DrawDots_Click {
   $Menu->{DrawDots}->Checked(1);
   $Menu->{DrawLines}->Checked(0);
   $Menu->{DrawBoxes}->Checked(0);
   $Menu->{DrawCircles}->Checked(0);
   $Win->InvalidateRect(1);
}

sub DrawLines_Click {
   $Menu->{DrawDots}->Checked(0);
   $Menu->{DrawLines}->Checked(1);
   $Menu->{DrawBoxes}->Checked(0);
   $Menu->{DrawCircles}->Checked(0);
   $Win->InvalidateRect(1);
}

sub DrawBoxes_Click {
   $Menu->{DrawDots}->Checked(0);
   $Menu->{DrawLines}->Checked(0);
   $Menu->{DrawBoxes}->Checked(1);
   $Menu->{DrawCircles}->Checked(0);
   $Win->InvalidateRect(1);
}

sub DrawCircles_Click {
   $Menu->{DrawDots}->Checked(0);
   $Menu->{DrawLines}->Checked(0);
   $Menu->{DrawBoxes}->Checked(0);
   $Menu->{DrawCircles}->Checked(1);
   $Win->InvalidateRect(1);
}

sub Timer1_Timer {
   my $W = $Win->ScaleWidth;
   my $H = $Win->ScaleHeight;
   my $DC = $Win->GetDC;
   my $left;
   my $top;
   my $right;
   my $bottom;
   my $P;
   my $B;

   if($Menu->{DrawDots}->Checked) {
       for(1..20) {
           $DC->SetPixel(
               rand()*$W,
               rand()*$H,
               [ rand()*255, rand()*255, rand()*255 ],
           );
       }
   } elsif($Menu->{DrawBoxes}->Checked) {
       $P = new Win32::GUI::Pen(
           -color => [ rand()*255, rand()*255, rand()*255 ],
           -width => rand()*5,
       );
       $B = new Win32::GUI::Brush(
           [ rand()*255, rand()*255, rand()*255 ]
       );
       $DC->SelectObject($P);
       $DC->SelectObject($B);
       $left   = rand()*$W;
       $top    = rand()*$H;
       $right  = $left + rand()*($W-$left);
       $bottom = $top + rand()*($H-$top);
       $DC->Rectangle($left, $top, $right, $bottom);
   } elsif($Menu->{DrawCircles}->Checked) {
       $P = new Win32::GUI::Pen(
           -color => [ rand()*255, rand()*255, rand()*255 ],
           -width => rand()*5,
       );
       $B = new Win32::GUI::Brush(
           [ rand()*255, rand()*255, rand()*255 ]
       );
       $DC->SelectObject($P);
       $DC->SelectObject($B);
       $left   = rand()*$W;
       $top    = rand()*$H;
       $right  = $left + rand()*($W-$left);
       $bottom = $top + rand()*($H-$top);
       $DC->Ellipse($left, $top, $right, $bottom);
   } elsif($Menu->{DrawLines}->Checked) {
       $P = new Win32::GUI::Pen(
           -color => [ rand()*255, rand()*255, rand()*255 ],
           -width => rand()*5,
       );
       $DC->SelectObject($P);
       $DC->BeginPath();
       $DC->MoveTo(rand()*$W, rand()*$H);
       $DC->LineTo(rand()*$W, rand()*$H);
       $DC->EndPath();
       $DC->StrokePath();
   }
}




From: [EMAIL PROTECTED]
To: perl-win32-gui-users@lists.sourceforge.net
Subject: [perl-win32-gui-users] Help with Win32::Gui::Graphic, WM_Paint and InvalidateRect
Date: Sun, 23 Nov 2003 11:58:55 -0600

Hi,
I am trying to draw an interactive graph in a window, and I don't want to use
GD, ImageMagick, Freeimage or any other libraries because of portability
issues.
However, I can't figure out how to correctly use Win32::GUI::Graphic,
Win32::GUI::DC, WM_Paint and InvalidateRect. I've tried reading through some of
my MSDN docs that came with my copy of VC++ 6.0, but I couldn't figure this
out.
I also looked through the samples directory in the Win32::GUI distribution, but
none of them use the Graphic object or _Paint handlers.

Can _Paint messages be generated only for Win32::GUI::Graphic objects?
How do I tell my program to redraw a window object?
What will cause a window object to be redrawn?
Does the entire window object have to be redrawn or can an area of
specified coordinates within the window object be redrawn?
What are the options that can be set in a "new Win32::GUI::Graphic"? I
cannot find them in GUI.xs.
Can someone share a simple, working example of the usage of
Win32::GUI::Graphic, WM_Paint, and InvalidateRect so that I can get
started on experimentation?

Thanks in advance,
Rod

Here is my code so far:

#!c:/Perl/bin/wperl.exe -w
use strict;
use Win32::GUI;

my $topwin = new Win32::GUI::Window(
              -name   => 'topwin',
              -title => 'window',
              -width  => 800,
              -height => 600,
              -pos => [125,75],
              -maximizebox => "0",
              -minimizebox => "0",
              -resizable => "0"
);
my $graph = new Win32::GUI::Graphic(
        $topwin,
       -name => "graph"
);

$topwin->Show();
$topwin->graph->InvalidateRect(1);
Win32::GUI::Dialog();

sub topwin_Terminate {
        return -1;
}
sub graph_Paint {
        my $W = $topwin->ScaleWidth;
        my $H = $topwin->ScaleHeight;
        my $DC = $topwin->graph->GetDC;
        my $P = new Win32::GUI::Pen(
            -color => 'BLACK',
            -width => 1,
        );
        $DC->SelectObject($P);
        $DC->BeginPath();
        $DC->MoveTo(50,50);
        $DC->LineTo(45,75);
        $DC->EndPath();
        $DC->StrokePath();
        $DC->Validate;
}
exit;

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.



-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users

_________________________________________________________________
Stay in touch with absent friends - get MSN Messenger http://www.msn.co.uk/messenger


Reply via email to