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

RE: 'cicn'/CopyBits help requested



Angus,

> Could someone take pity on my ignorance and tell
>me how (in MCL 2.0) to get at the PixMap data from a colour icon
>(cicn) given a handle to the 'cicn' resource?

Here's some pascal code that I wrote that does what you want.
I'll let you or someone else translate it to MCL.

procedure PlotAnIcon (theIcon: CIconHandle; theRect: Rect; IsPrinting:
Boolean);

 type
  BitMapPtr = ^BitMap;

 var
  aPixMap: PixMap;
  aMask: BitMap;
  aBitMap: BitMap;
  aBitMapPtr: BitMapPtr;
  srcRect, MaskRect: Rect;
  OldForeColor, OldBackColor: RGBColor;

begin
{Inside Macintosh V-68 says to make sure to set the foreground color to black
and the background color to white}
{before calling copybits with a pixmap as the source. So, we do it once around
the body of the procedure.}
 GetForeColor(OldForeColor);
 GetBackColor(OldBackColor);
 RGBForeColor(gRGBBlack);
 RGBBackColor(gRGBWhite);
 HLock(theIcon^^.iconData);
 aPixMap := theIcon^^.iconPMap;
 aMask := theIcon^^.iconMask;
 aPixMap.baseAddr := theIcon^^.iconData^;
 aMask.baseAddr := @theIcon^^.iconMaskData;
 srcRect := aPixMap.bounds;
 MaskRect := aMask.bounds;
 aBitMapPtr := @aPixMap;	{Ignore the Mask if we are printing (CopyMask won't
work)}
 if IsPrinting then
  CopyBits(aBitMapPtr^, thePort^.portBits, srcRect, theRect, SrcCopy, nil)
 else
  CopyMask(aBitMapPtr^, aMask, thePort^.portBits, srcRect, MaskRect, theRect);
 HUnLock(theIcon^^.iconData);
 RGBForeColor(OldForeColor);
 RGBBackColor(OldBackColor);
end;

-Jonathan