Microsoft KB Archive/50807
Article ID: 50807
Article Last Modified on 11/21/2006
This article was previously published under Q50807
The following article gives an example of how to print gray text in Macintosh QuickBASIC and BASIC. A gray pen pattern can be used as a bit mask to overlay solid text to make it gray.
Gray text is used in Macintosh programs to indicate that a certain choice no longer applies or has been made inactive. An example of this is when a menu is grayed to indicate that it is no longer an allowed choice, but the grayed text is still shown as a "place holder" to show what choice might be possible under other conditions.
This information applies to Microsoft QuickBASIC Version 1.00 for the Apple Macintosh, Microsoft BASIC Compiler Version 1.00 for the Apple Macintosh, and Microsoft BASIC Interpreter Versions 2.00, 2.10, and 3.00 for the Apple Macintosh.
The key to creating gray text is to make a gray pen pattern that can be used as a bit mask to overlay solid text, as follows:
Use an eight-by-eight (8 x 8) template or grid to create the gray pattern. Each slot in the grid represents one of the pixels in a normal character. Setting every other pixel makes a gray pattern. In the following grid, a 1 (one) represents a black pixel and a 0 (zero) represents a white pixel. Start with 0, since starting with 1 creates a gray pattern mask different than that used by the Macintosh System.
Pattern Translates to Hex Byte Equivalent 2-Byte Value ------- ------------- ------------------- ------------ 01010101 ---------> &H55 -----\ 10101010 ---------> &HAA -----/ -----> &H55AA 01010101 ---------> &H55 -----\ 10101010 ---------> &HAA -----/ -----> &H55AA 01010101 ---------> &H55 -----\ 10101010 ---------> &HAA -----/ -----> &H55AA 01010101 ---------> &H55 -----\ 10101010 ---------> &HAA -----/ -----> &H55AA
- Convert the binary codes in the patterns into hexadecimal codes.
- Group the codes into pairs to form four-digit hexadecimal numbers. An integer in BASIC can hold exactly a four-digit hexadecimal number. The PENPAT ROM routine requires exactly four integers, as created above.
The steps above are described in detail on Page 390 of the "Microsoft QuickBASIC for the Apple Macintosh Systems: BASIC Language Reference" manual, Appendix D, Section D.3.5, "Changing the Pen Pattern."
Three other steps are required to correctly create grayed text:
- A TEXTFACE other than 2 must be used. Each of the other TEXTFACE choices work well with gray text, but TEXTFACE 2, which is italicized, does not created readable gray text. Bold text works best because it has more black pixels, which allows for some pixels to be turned to white creating a gray appearance but leaving the character readable.
- A PENMODE of 11 must be used. This causes the PEN to paint in BIC or "Black is Changed" mode.
- TEXTFONT 0, which is the default system font, should be used.
All of the above steps will create gray text. However, the text will not appear exactly as the gray text in the menu items created by the Macintosh Menu Manager. If this effect is desired, you should use TEXTFACE 64. TEXTFACE 64 creates "extended" characters, which causes more space between characters. The example below combines all of these methods to create gray text that should appear just as it does in grayed menu items.
' Invoke Chicago font, the font used by Macintosh System menus: TEXTFONT 0 ' Invoke the wider-spaced Textface used in the System menus: TEXTFACE 64 PRINT "This Should be gray "; ' "S" appears as in System menu items ' Print the apple, check, diamond, and COMMAND key symbols: PRINT CHR$(17);CHR$(18);CHR$(19);CHR$(20) PRINT "This is NOT gray" SetArray pat%(0), &H55AA, &H55AA, &H55AA, &H55AA PENPAT VARPTR(pat%(0)) setarray r%(0), 0, 0, 16, 250 PENMODE 11 ' Sets the penmode to BIC (Black Is Changed) ' Paint over the previously printed text to make it gray. PAINTRECT VARPTR(r%(0)) END
[Note: BASIC interpreter Versions 2.00 and 2.10 don't support SetArray, so you need to assign pat%(0) through pat%(3) individually to &H55AA in these older versions.]
Additional query words: BasicCom MQuickB grey (alternative spelling)