[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Ooops I mean Mac::Events



> I looked at the trumpet tutor2 code at Kevin Reids site as kindly
> recommended by David Seay. and saw something on the order of   storing the
> location of the old keyDown routine with
> 
> $OldDownHandler = $Event[keyDown]; Event[keyDown] = \&KeyDown;

That code is for a special purpose. For ordinary usage, you should never
need to set the mouseDown/keyDown/whatever handler. Instead, use a hook
on your window, as demonstrated by this program:

#!perl -w
# Rectangle click demo

use Mac::Windows;
use Mac::QuickDraw;
use Mac::Events;

sub ltwh {new Rect ($_[0], $_[1], $_[0] + $_[2], $_[1] + $_[3])}

$wbounds = new Rect (0, 0, 150, 150);
$rbounds = ltwh(50, 50, 50, 50);
$srect = GetMainDevice->gdRect;

$win = new MacColorWindow (
  Mac::QuickDraw::OffsetRect($wbounds,
    $srect->left + ($srect->right - $srect->left - $wbounds->right) / 2,
    $srect->top + ($srect->bottom - $srect->top - $wbounds->bottom) / 3,
      # change 3 to 2 for truly centered window.
  ), 
  "Test", 1, noGrowDocProc, 1);
$win->sethook(drawgrowicon => sub {});
$win->sethook(click => sub {
  my ($win, $pt) = @_;
  if (PtInRect($pt, $rbounds)) {
    my $tix = TickCount() + 20;
    my $inv = 0;
    while (TickCount() < $tix) {
      InvertRect $rbounds; $inv = !$inv;
    }
    InvertRect $rbounds if $inv;
  }
});
$win->sethook(redraw => sub {
  PaintRect $rbounds;
});

WaitNextEvent while $win->window;
END {$win->dispose}

__END__
-- 
 Kevin Reid: |    Macintosh:      
  "I'm me."  | Think different.

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org