Re: [perl-win32-gui-users] need help with Graphic

2003-12-28 Thread Johan Lindstrom

At 17:37 2003-12-22, Jonathan Southwick wrote:
I have a Graphic object that I am plotting data on.  While the cursor is 
on this object I have a cross-hairs cursor.  What I would like to do is 
extend lines from the cursor position to the edges of the graph (the 
perimeter) but not have them overwrite what is plotted there and as I move 
the cursor around the lines move accordingly.

-snip
Has anyone ever accomplished this?  Does anyone know HOW to do it?  Any 
help would be greatly appreciated.


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__

 --  --- -- --  --  -- -  - -
Johan LindströmSourcerer @ Boss Casinos [EMAIL PROTECTED]

Latest bookmark: "Assembly Language Windows Applications"
http://grc.com/smgassembly.htm
dmoz (1 of 3): /Computers/Programming/Languages/Assembly/ 66




[perl-win32-gui-users] Tooltip for GroupBoxes?

2003-12-28 Thread Johan Lindstrom
Does anyone know whether the -tip option is supposed to work for the 
GroupBox control?



/J
 --  --- -- --  --  -- -  - -
Johan LindströmSourcerer @ Boss Casinos [EMAIL PROTECTED]

Latest bookmark: "Assembly Language Windows Applications"
http://grc.com/smgassembly.htm
dmoz (1 of 3): /Computers/Programming/Languages/Assembly/ 66