Path: utzoo!utgpu!water!watmath!clyde!rutgers!cmcl2!nrl-cmf!ames!sdcsvax!ucsdhub!hp-sdd!hplabs!hpda!hpsal2!hpcupt1!hpirs!hpisoa2!hpindda!atchison From: atchison@hpindda.HP.COM (Lee Atchison) Newsgroups: comp.sys.mac Subject: Need help with drawing icons Message-ID: <6500008@hpindda.HP.COM> Date: 19 Jan 88 18:25:32 GMT Organization: HP Information Networks, Cupertino, CA Lines: 83 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