[comp.sys.mac] Need help with drawing icons

atchison@hpindda.HP.COM (Lee Atchison) (01/20/88)

Hi!  I have a programming question.  I've tried looking in IM, but it
doesn't seem to give me the help I am looking for.

What I am trying to do is draw icons, invert them (using the icon mask,
like the finder does), and erase them.  I want to be able to do this both
in a window and on the desktop (like the disk icons, and the trashcan
in the finder).

The routine DrawIcon (I think that is what it is called, I don't have IM
handy) doesn't help, as it assumes a white background when it draws the icon
(the icon square is drawn white as well as the icon itself, ie. it uses a
srcCopy transfer mode).

I have tried the following routine to draw an icon in a window, and this
works fine:

    port:GrafPtr;
    pos:Rect; { location to draw icon }

    GetPort(port);
    CopyBits(myicon.iconmask,port^.portBits,
	     myicon.iconmask.bounds,pos,
	     SrcBic,Nil);  { clears mask space for icon }
    CopyBits(myicon.icon,port^.portBits,
	     myicon.icon.bounds,pos,
	     SrcOr,Nil);   { draw icon }

and this to invert the icon:

    GetPort(port);
    CopyBits(myicon.iconmask,port^.portBits,
	     myicon.iconmask.bounds,pos,
	     SrcXor,Nil);  { invert the icon }

Both of these work fine in a window.  I simply use EraseRect to erase the icon.
Is this the best way to do this?  Will this work on all Macs?

Now, for drawing on the desktop, I used the following:

    CopyBits(ScreenBits,myicon.hold,
	     pos,myicon.hold.bounds,
	     SrcCopy,Nil);  { save a copy of the background at this point }
    CopyBits(myicon.iconmask,ScreenBits,
	     myicon.iconmask.bounds,pos,
	     SrcBic,Nil);   { clear mask for icon }
    CopyBits(myicon.icon,ScreenBits,
	     myicon.icon.bounds,pos,
	     SrcOr,Nil);    { draw icon }

My EraseIcon is:

    CopyBits(myicon.hold,ScreenBits,
	     myicon.hold.bounds,pos,
	     SrcCopy,Nil);  { restore background at this point }

My InvertIcon is the same as the invericon for in a window.

Now, these routines work fine UNTIL I start having an overlapping window.
Then these routines fail.  If I draw an icon that is supposedly hidden (either
partially or completely) by a window, the icon draws on top of the window.

Obviously, my problem is that I shouldn't be using ScreenBits, but what should
I use instead?

Now the real question.  Is this the way I'm suppose to do it?  Will this work
on all Macs?  Will this work under (gulp) Multifinder?  Am I allowed to write
on the desktop AT ALL under Multifinder?  Am I conforming to the Macintosh
Guidelines correctly?

A related question.  How to I know when I need to update these icons stored
on the desktop?  Obviously, I don't get an update event for the desktop, but
there has to be someway.  I've thought about updating anytime a window was
moved, or anytime one of my windows became active.  The later will allow me
to redraw these icons after coming back from a DA (or another application
under MultiFinder).  Is there a better or more complete way of doing this?

Thanks in advance for any help you can give to me.

			-lee
--------------
Lee Atchison
Hewlett Packard, Information Networks Division
atchison%hpindda@hplabs.hp.com

han@apple.UUCP (-- Byron B. Han --) (01/22/88)

In article <6500008@hpindda.HP.COM> atchison@hpindda.HP.COM (Lee Atchison) writes:
>
>What I am trying to do is draw icons, invert them (using the icon mask,
>like the finder does), and erase them.  I want to be able to do this both
>in a window and on the desktop (like the disk icons, and the trashcan
>in the finder).
>
>Now, for drawing on the desktop, I used the following:

This is not recommended.  According to the "MultiFinder Development Package
Release Note" (p. 4) "The window manager port is generally off limits.  It
belongs strictly to the Window Manager.  Yes this means that applications 
cannot draw on the desktop.  Consider the call GetWMGRPort() to be for 
amusement only and certainly read-only purposes.  The fabled DESKHOOK,
a low-memory vector which allowed applications to draw on the desktop, has 
been eliminated. Applications that use DESKHOOK will not function as expected."

DESKHOOK was a low memory vector that would (described in IM-I p. 282, 288)
be called when a click in the desktop was registered and/or when the
the desktop is to be redrawn. 



-- 
------------------------ Byron Han,  Communications Tool ----------------------
     Apple Computer, Inc.  20525 Mariani Ave, MS 27Y  Cupertino, CA 95014
 ATTnet:408-973-6450    applelink:HAN1    domain:han@apple.COM     MacNET:HAN
GENIE:BYRONHAN   COMPUSERVE:72167,1664   UUCP:{sun,voder,nsc,decwrl}!apple!han

burnard@apple.UUCP (Dave Burnard) (01/22/88)

It is true that you should no longer draw on the DeskTop. On the question 
of Icon drawing in general, I refer you to Tech Note #55. Available at many
popular sites on the net.

DB