[comp.sys.mac.programmer] Help with icl8's...

markt@wpi.wpi.edu (Mark Robert Tsombakos) (07/25/90)

Hello,
	Just a quick question (I've seen it asked before, but never saw the
answer) -

	How does one draw an icl8?

	Thanks in advance,
		John 
email: markt@wpi.wpi.edu

beard@ux5.lbl.gov (Patrick C Beard) (07/26/90)

In article <14176@wpi.wpi.edu> markt@wpi.wpi.edu (Mark Robert Tsombakos) writes:
#Hello,
#	Just a quick question (I've seen it asked before, but never saw the
#answer) -
#
#	How does one draw an icl8?
#
#	Thanks in advance,
#		John 
#email: markt@wpi.wpi.edu


I was just wondering that myself...  Couldn't be easier.  The format of
icl's is just the pixels.  Therefore, an icl8 is just 32x32 8-bit pixels,
or 1024 bytes.  Just create a pixmap, set rowBytes to 32, bounds to
0, 0, 32, 32, and set up baseAddr to point to the data, and call CopyBits.

This should work, though I've never done it.

--
-------------------------------------------------------------------------------
-  Patrick Beard, Macintosh Programmer                        (beard@lbl.gov) -
-  Berkeley Systems, Inc.  ".......<dead air>.......Good day!" - Paul Harvey  -
-------------------------------------------------------------------------------

mdavis@pro-sol.cts.com (Morgan Davis) (07/26/90)

In-Reply-To: message from markt@wpi.wpi.edu

Drawing an icl8 is fairly easy.  The icl8 consists of 1K of pixel data (a
pixMap).  All you do to draw it is use CopyBits to copy the icl8's pixMap to
your destination pixMap using a 32 x 32 pixel rectangle.  The rowbytes value
of the pixMap should be 32.

Here is a short routine that took me a while to figure out.  If anyone
knows of a better way to do this, PLEASE let me know.

/*****************************************************************************
 **
 **	PlotIcl8
 **
 ** Like PlotIcon, this function uses the same arguments, only the the icon's
 ** handle belongs to a 1K icl8 resource.
 **
 **/

void
PlotIcl8 (register Rect *dest, register Handle theIcon)
{
	register PixMapHandle	pm;
	register byte			hAttrs;
	CGrafPtr				gp;

	GetPort (&gp);
	pm = NewPixMap();
	HLock (pm);
	CopyPixMap (gp->portPixMap, pm);
	hAttrs = HGetState (theIcon);
	HLock (theIcon);
	(**pm).baseAddr = *theIcon;
	HSetState (theIcon, hAttrs);
	(**pm).rowBytes = 32 | 0x8000;
	SetRect(&(**pm).bounds, 0, 0, 32, 32);
	CopyBits(*pm, &(*gp).portPixMap, &(**pm).bounds, dest, 0, NULL);
	DisposPixMap (pm);
}
	

UUCP: crash!pnet01!pro-sol!mdavis		ProLine:  mdavis@pro-sol
ARPA: crash!pnet01!pro-sol!mdavis@nosc.mil	MCI Mail: 137-6036
INET: mdavis@pro-sol.cts.com			America Online, BIX: mdavis

stevec@Apple.COM (Steve Christensen) (07/26/90)

In article <3681@crash.cts.com> mdavis@pro-sol.cts.com (Morgan Davis) writes:
>...
>Here is a short routine that took me a while to figure out.  If anyone
>knows of a better way to do this, PLEASE let me know.
>
>/*****************************************************************************
> **
> **	PlotIcl8
> **
> ** Like PlotIcon, this function uses the same arguments, only the the icon's
> ** handle belongs to a 1K icl8 resource.
> **
> **/
>
>void
>PlotIcl8 (register Rect *dest, register Handle theIcon)
>{
>	register PixMapHandle	pm;
>	register byte			hAttrs;
>	CGrafPtr				gp;
>
>	GetPort (&gp);
>	pm = NewPixMap();
>	HLock (pm);
>	CopyPixMap (gp->portPixMap, pm);
>	hAttrs = HGetState (theIcon);
>	HLock (theIcon);
>	(**pm).baseAddr = *theIcon;
>	HSetState (theIcon, hAttrs);
>	(**pm).rowBytes = 32 | 0x8000;
>	SetRect(&(**pm).bounds, 0, 0, 32, 32);
>	CopyBits(*pm, &(*gp).portPixMap, &(**pm).bounds, dest, 0, NULL);
>	DisposPixMap (pm);
>}

Actually the "hSetState(theIcon, hAttrs)" should be moved below the CopyBits()
call since CopyBits can move memory, and if the icon is unlocked, it could
end up drawing garbage...

steve

-- 
____________________________________________________________________

  Steve Christensen             Internet:   stevec@goofy.apple.com
  Apple Computer, Inc.          AppleLink:  STEVEC
  20525 Mariani Ave, MS 81-CS   CompuServe: 76174,1712
  Cupertino, CA  95014

  "You just contradicted me."  "No I didn't."
____________________________________________________________________