[comp.sys.mac.programmer] Obtaining the Gray colour used for disabled menu items

slang@bnr.ca (Steven Langlois) (06/14/91)

I have very little experience with colour on the Mac so please bare with me.
I am using James Plamondon's popup menu CDEF from MacTutor Vol.4 No.9 am
I am trying to enhance it a little. There were 2 things I noticed it
couldn't do. 1) there was not way to tell if the a menu selection
was abondoned, i.e. in a dialog, when you get the item selected, find
it was a popup control, and call GetCtlMin to find which item is selected,
you have no way of knowing if the user abandoned a selection or reselected
the same item because in either case, contrlMin will still be the same.
I managed to solve this using the contrlRfCon field. 2) If the menu
item in the popup box is disabled, the text in the popup box is still
solid. When the popup is selected, the current item becomes gray.
What I wanted to do was to draw the text in the popup box in gray when the
current item is disabled. I have been able to do this by painting
inside the popup rect with a gray pattern after drawing the string
in the popup box. The results are good for black and white or in
colour before System 7 because the grayed item looks the same as any
menu grayed item. Under System 7, the gray of disabled items is a
nice solid gray, it doesn't look like a gray pattern applied to
solid black text. How can I draw a disabled item in the popup
box in the grey which is used for disabled menu items?

Any help would be much appreciated.

Steven Langlois
ISDN Basic Rate Access
BNR, a subsidiary of Northern Telecom

Internet: slang@bnr.ca

benw@microsoft.UUCP (Ben WALDMAN) (06/18/91)

In article <1991Jun14.141644.4857@bmers95.bnr.ca> slang@bnr.ca (Steven Langlois) writes:
>Under System 7, the gray of disabled items is a
>nice solid gray, it doesn't look like a gray pattern applied to
>solid black text. How can I draw a disabled item in the popup
>box in the grey which is used for disabled menu items?

To draw the system 7.0 style grayed text (used in menus and controls),
do a TextMode(49) before your text drawing calls.
To draw a grayed line, compute a color that is the arithmetic average
of the foreground and background colors, computing each of the color
components (R,G,B) separately (and make sure to use longword arithmetic
to avoid overflow), and make this color your foreground color.

The Textmode(49) call is simply a shortcut that does the math for you.
Note that this does not always get you gray (i.e. use Kolor to get
weird menu colors and see what happens), but the algorithm I describe
is what System 7.0 does.

Ben Waldman
Excel Development Team
Microsoft Corp.

Disclaimer:  These are my thoughts, opinions, and ideas, and in no
way reflect those of my employer.