[comp.sys.mac.programmer] Hilite Mode Error

rj0z+@andrew.cmu.edu (Robert George Johnston, Jr.) (02/27/89)

    In Volume V of Inside Macintosh, on page 61, an explanation of how
to use the Hilite Mode follows:

    There are two ways to use the hilite mode. The easiest is to call
BitClr(Ptr(HiliteMode, pHiliteBit)); just before calling InvertRect,
InvertRgn, InvertArc, InvertRoundRct, or InvertPoly or any drawing using
srcXor mode. On a one-bit-deep destination, this will work exactly like
inversion, and is compatible with all versions of QuickDraw.

    Consider the following Pascal code:
    begin
      PenMode(srcXor);
      BitClr(Ptr(HiliteMode, pHiliteBit));
      FrameRect(SomeRect);
    end;

    On a Macintosh equipped with Color QuickDraw, this procedure acts as
expected, by drawing a rectangle in the current hilite color. If the
screen is only one-bit-deep, it also acts accordingly by inverting the
frame of the rectangle.
    Now, this same code, when executed on a regular SE or Plus without
Color QuickDraw will NOT draw anything to the screen.
    I then discovered that if I set the PenMode to patXor, the procedure
then functions exactly to specifications.

    I have not tried this out on other drawing routines like FrameOval. I
am using Lightspeed Pascal 2.0p1, System Software 6.0.2.

    Perhaps somebody should look into whether the book is wrong or the
implementation is wrong.

    Rob Johnston.

ech@pegasus.ATT.COM (Edward C Horvath) (02/27/89)

From article <4Y2CH4y00VE1MC7EUf@andrew.cmu.edu>, by rj0z+@andrew.cmu.edu (Robert George Johnston, Jr.):
...
>     Consider the following Pascal code:
>     begin
>       PenMode(srcXor);
>       BitClr(Ptr(HiliteMode, pHiliteBit));
>       FrameRect(SomeRect);
>     end;

>     On a Macintosh equipped with Color QuickDraw, this procedure acts as
> expected, by drawing a rectangle in the current hilite color. If the
> screen is only one-bit-deep, it also acts accordingly by inverting the
> frame of the rectangle.
>     Now, this same code, when executed on a regular SE or Plus without
> Color QuickDraw will NOT draw anything to the screen.
>     I then discovered that if I set the PenMode to patXor, the procedure
> then functions exactly to specifications.

According to IM-1 p.157, PenMode gets either
	- pattern transfer modes, for drawing shapes with a pattern
	- source transfer modes, for drawing text or transferring any bit
	  image between two bit maps.

I.e., use PenMode (patXor) for FrameRect().  For the record, I've never
been able to figure out why the distinctions is necessary, and apparently
the Color QD designers couldn't either, but for use with older Macs try
using the mode from IM-I.

=Ned Horvath=

gandreas@umn-d-ub.D.UMN.EDU (Glenn Andreas) (02/27/89)

In article <4Y2CH4y00VE1MC7EUf@andrew.cmu.edu> rj0z+@andrew.cmu.edu (Robert George Johnston, Jr.) writes:
>
>    In Volume V of Inside Macintosh, on page 61, an explanation of how
>to use the Hilite Mode follows:
>
>    There are two ways to use the hilite mode. The easiest is to call
>BitClr(Ptr(HiliteMode, pHiliteBit)); just before calling InvertRect,
>InvertRgn, InvertArc, InvertRoundRct, or InvertPoly or any drawing using
>srcXor mode. On a one-bit-deep destination, this will work exactly like
>inversion, and is compatible with all versions of QuickDraw.
>
>    Consider the following Pascal code:
>    begin
>      PenMode(srcXor);
>      BitClr(Ptr(HiliteMode, pHiliteBit));
>      FrameRect(SomeRect);
>    end;
>
[ Works in ColorQuickDraw, not on a Plus or SE ]
>    Perhaps somebody should look into whether the book is wrong or the
>implementation is wrong.
>
>    Rob Johnston.
The problem is in both places.  From back in IM I we get:

PROCEDURE PenMode (mode: INTEGER);

PenMode sets the transfer mode through which the pnPat is transferred
onto the bitMap when lines or shapes are drawn.  The mode may be any 
one of the pattern transfer modes:

	patCopy		patXor		notPatCopy	notPatXor
	patOr		patBic		notPatOr	notPatBic

If the mode is one of the source transfer modes (or negative), no drawing is
performed.

Also, IM V-60 says "On the Macintosh II the rules for setting the pen mode
and the text mode have been relaxed slightly.  It's no longer necessary to
specify a pattern or a source mode (patCopy as opposed to srcCopy) to
perform a particular operation.  QuickDraw will choose the correct drawing
mode automatically.  However, to be compatible with earlier versions of
QuickDraw, your application must specify the correct drawing mode.  Text and
bitmaps should always use a source mode; rectangles, regions, polygons,
arcs, ovals, round rectangles, and lines should always use a pattern mode."

So, what it says in IM V about "srcXor mode" is correct, since on a machine
that uses the hilight mode, srcXor works exactly as patXor.  But when you
ran your example on a non CQD machine, it didn't work since srcXor does
nothing for drawing on those machines.

This demonstrates that once again, unless you know every line in IM I-V, you
can get into trouble :-(

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
= "Whether you like it, or don't like it, sit   | - gandreas@ub.d.umn.edu - =
=  back and take a look at it, because it's the |   Glenn Andreas           =
=  best going today!  WOOOOoooo!" - Ric Flair   |                           =
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=