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

[MacPerl-Toolbox] BitMapToRegion & 'cicn'



[ A copy of this message has been posted to the newsgroup ]
[     comp.sys.mac.programmer.help                        ]

I am trying to create a region out of the mask of a 'cicn' resource.

Am I doing something wrong in this code, or is MacPerl's definition of a
CIconHandle broken?

#!perl -w

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

use constant BLACK => new RGBColor (0,0,0);

$win = new MacColorWindow (
  ltwh(100, 100, 135, 130),
  "BitMapToRegion", 1, noGrowDocProc, 1);
$win->sethook(drawgrowicon => sub {});

$icon = GetCIcon -20020 or die "Could not get 'cicn' resource -20020:
$^E";
$rgn = NewRgn();
BitMapToRegion $rgn, $icon->iconMask or die $^E;
OffsetRgn $rgn, 80, 30;
$icr = ltwh(20, 30, 32, 32);
$bm1r = ltwh(20, 70, 32, 32);
$bm2r = ltwh(80, 70, 32, 32);

SetPort $win->window;
TextFont(0);
RGBBackColor(new RGBColor(50000, 50000, 65535));

$win->sethook(redraw => sub {
  MoveTo(20, 20);
  DrawString('Icon');
  PlotCIcon $icr, $icon;
  MoveTo(80, 20);
  DrawString('Mask');
  PaintRgn $rgn;
  CopyBits($icon->iconBMap, GetPort->portBits, $bm1r, $bm1r, srcCopy);
  CopyBits($icon->iconMask, GetPort->portBits, $bm2r, $bm2r, srcCopy);
});

WaitNextEvent while $win->window;

sub ltwh ($$$$) {
  my ($left, $top, $width, $height) = @_;
  new Rect ($left, $top, $left+$width, $top+$height);
}

END {
  $win->dispose if $win;
  DisposeCIcon $icon if $icon;
  DisposeRgn $rgn if $rgn;
}
__END__

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

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