Great!  This was exactly what I needed!  I now have a very simple rolling
line graph working based on this code.  I'll send an example to the list in
a bit (there are a few glitches that I need to work out)

Brian Millham
This message traveled at least 44,000 miles to reach you!
Creator of the DW6000 Monitor
http://www.millham.net/dw6000
[EMAIL PROTECTED] 

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Johan
Lindstrvm
Sent: Tuesday, January 17, 2006 4:37 PM
To: perl-win32-gui-users@lists.sourceforge.net
Subject: Re: [perl-win32-gui-users] Win32::GUI and a "rolling line graph"

At 21:40 2006-01-17, Brian Millham wrote:
>         The VB portion shows a "Rolling Line Graph" of data.  Is there an
>easy way to do this in Perl and Win32::GUI?  I'm currently using
MSCHART.OCX
>to make the graph, but I'd like something that I have more control over.

You can paint a graph yourself on a Graphic control.

I posted this a few years back as an example of how to paint stuff on a 
Graphic:

----------


This is one way. Consider it a proof-of-concept rather than best-practice 
given the load of globals.

Basically, the _Paint event handler is used to always plot first the mouse 
lines and then the actual graph. This happens when the the Graphic control 
is invalidated, which can be triggered by three things; either Windows 
itself notices the need for it, or the graph changes, or the mouse moves.

(This method decouples the cause of the event from the action to be 
performed when it happens, which is a Good Thing)


The #### comments explain the important concepts.


#!/usr/local/bin/perl -w
use strict;
use Win32::GUI;



my $wWinPlot = 400;
my $hWinPlot = 250;
my ($xMouse, $yMouse) = (100, 100);
my $xBar = 100;
my $winPlot = winCreate();


sub winCreate {
         my $winPlot = Win32::GUI::Window->new(
               -left   => 100,
               -top    => 100,
               -width  => $wWinPlot,
               -height => $hWinPlot,
               -name   => "winPlot",
               -text   => "Plot test",
               -minheight        => 10,
               -minwidth         => 10,
               );

         my $grCanvas = Win32::GUI::Graphic->new($winPlot,
                         -left   => 0,
                         -top    => 0,
                 -width  => $wWinPlot,
                 -height => $hWinPlot,
                         -name   => "grCanvas",
                         -interactive => 1,
                         );
         my $tim = $winPlot->AddTimer("timTimer", 100);

         $winPlot->Show();

         return($winPlot);
}





#### Will be called when the window needs to be painted,
#### caused either by Windows, or the InvalidateRect of the entire window
sub grCanvas_Paint { my $win = $winPlot;
         my($dcDev) = @_;
         return(0) if(!$dcDev);

         $dcDev->TextColor([0, 0, 0]);           #Black

         #The cross-hair
         $dcDev->Rectangle($yMouse, 0, $yMouse + 1, $hWinPlot);
         $dcDev->Rectangle(0, $xMouse, $wWinPlot, $xMouse + 1);

         #The bar
         $dcDev->Rectangle(50, 0, 120, $xBar);

         #### Tell Windows we're satisfied with the way the area looks like
         $dcDev->Validate();

         return(1);
}



#### Trigger on the mouse move
sub grCanvas_MouseMove { my $win = $winPlot;
         my ($dummy, @aPos) = @_;

         ($yMouse, $xMouse) = @aPos;

         #### Tell Windows the window needs to be repainted,
         #### will call the _Paint event handler
         #### The 1 wipes the area before repainting it,
         #### changing it to 0 will leave trails
         $win->InvalidateRect(1);

         return(1);
}



my $timerCount = 0;
sub timTimer_Timer { my $win = $winPlot;
         $timerCount += .1;

         $xBar = (int(cos($timerCount) * 50)) + 70;

         #### Tell Windows the window needs to be repainted,
         #### will call the _Paint event handler
         #### The 1 wipes the area before repainting it,
         #### but since we may know exactly what needs to be repainted
         #### when $xBar changed, that may not be necessary
         $win->InvalidateRect(1);

         return(1);
}



Win32::GUI::Dialog();



__END__


/J



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
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/
---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0603-2, 01/17/2006
Tested on: 1/17/2006 6:32:45 PM
avast! is copyright (c) 2000-2003 ALWIL Software.
http://www.avast.com





Reply via email to