[net.micro.mac] Grow Regions

hamachi@KIM (Gordon Hamachi) (12/06/85)

Forwarded message:
=================

Subject: Grow Regions: How do they do that?

    Attention, Real Hackers.  Here's a tough one for you: When the mouse is
held down in the Grow box of a window and dragged, a gray outline of
the window follows it around.  Likewise, in MacPaint or the Finder, you can 
use a rectangle, which also appears in blinking gray, to select.  Now, this
has got to be a non-trivial operation, saving the bits under the outline,
writing the outline, then restoring the saved bits after the outline moves.
Do we mortals have access to some semi-highlevel routine which does this for
us?  Or am I going to have to kludge something up?  Many thanks in advance.

Steve Upstill

breuel@h-sc1.UUCP (thomas breuel) (12/06/85)

>     Attention, Real Hackers.  Here's a tough one for you: When the mouse is
> held down in the Grow box of a window and dragged, a gray outline of
> the window follows it around. [...] Now, this
> has got to be a non-trivial operation, saving the bits under the outline,
> writing the outline, then restoring the saved bits after the outline moves.
> Do we mortals have access to some semi-highlevel routine which does this for
> us?  Or am I going to have to kludge something up?  Many thanks in advance.

It looks to me as if the outline is just drawn in XOR mode, which means
that re-drawing it makes it disappear. No saving of bits is necessary.

						Thomas.

gus@Shasta.ARPA (12/06/85)

> this has got to be a non-trivial operation, saving the bits under the outline,
> writing the outline, then restoring the saved bits after the outline moves.
> Do we mortals have access to some semi-highlevel routine which does this for
> us?  Or am I going to have to kludge something up?  Many thanks in advance.
> 
> Steve Upstill

It's called XOR. Try it some time. XORing a line on a background puts
it there, drawing the same line again in XOR puts takes it away.

darin@ut-dillo.UUCP (Darin Adler) (12/06/85)

> Attention, Real Hackers.  Here's a tough one for you: When the mouse is
> held down in the Grow box of a window and dragged, a gray outline of
> the window follows it around.  Likewise, in MacPaint or the Finder, you can
> use a rectangle, which also appears in blinking gray, to select.  Now, this
> has got to be a non-trivial operation, saving the bits under the outline,
> writing the outline, then restoring the saved bits after the outline moves.
> Do we mortals have access to some semi-highlevel routine which does this for
> us?  Or am I going to have to kludge something ...

This is an old trick for making ephemeral, ghostlike images on a
bit-map display.  By drawing the outline in exclusive-or mode, all the
ToolBox has to do is re-draw the same outline again to completely undo
the effects of the first draw.  To do this just like the Finder, you
also need to know a trick or two about timing to avoid an inordinate
amount of flicker.  Here is some sample code (in Lisa Pascal, easy to
convert to C) that has all the necessary "magic":

PROCEDURE Boxer(startPoint: Point; VAR endPoint: Point;);

{This is a general purpose "boxing" routine, similar to the one used  }
{by the Finder.  It works in the current port (it is often useful to  }
{set a ClipRect first).  The endPoint is the location of the mouse-up }
{event (or the last known position of the mouse, if no mouse-up event }
{is available.  Both startPoint and endPoint are in local coordinates.}

    CONST
        noFlickTicks = 2;	{number of ticks between re-drawing}

    VAR
        box, oldBox: Rect;	{for tracking the mouse}
	boxTick: LongInt;	{for delay to avoid flicker}

	penSave: PenStatus;	{saved status of the pen}
	upEvent: EventRecord;	{for mouse-up event}

BEGIN
SetRect(oldBox, 0, 0, 0, 0);

GetPenState(penSave);		{save pen}

PenSize(1,1);			{set up the pen so that the box works}
PenPat(gray);
PenMode(notPatXor);

FrameRect(oldBox);		{framing an empty rectangle, but ...}
boxTick := TickCount;

WHILE StillDown DO
  BEGIN
  GetMouse(endPoint);		{track that mouse}
  Pt2Rect(startPoint, endPoint, box);
  IF NOT EqualRect(oldBox, box) THEN
    IF TickCount >= boxTick + noFlickTicks THEN
      BEGIN			{redraw the box...}
      FrameRect(oldBox);	{erase the old box}
      FramRect(box);		{draw the new box}
      oldBox := box;
      boxTick := TickCount;
      END;
  END;

FrameRect(oldBox);		{erase remnants of dragging}

SetPenState(penSave);		{restore pen}

IF EventAvail(mUpMask, upEvent) THEN
  BEGIN				{get endpoint from mouse-up event}
  endPoint := upEvent.where;
  GlobalToLocal(endPoint);
  END;
END;
-- 
Darin Adler
{gatech,harvard,ihnp4,seismo}!ut-sally!ut-dillo!darin

maclab@reed.UUCP (Mac DLab) (12/08/85)

> Subject: Grow Regions: How do they do that?
> 
>     Attention, Real Hackers.  Here's a tough one for you: When the mouse is
> held down in the Grow box of a window and dragged, a gray outline of
> the window follows it around.  Likewise, in MacPaint or the Finder, you can 
> use a rectangle, which also appears in blinking gray, to select.  Now, this
> has got to be a non-trivial operation, saving the bits under the outline,
> writing the outline, then restoring the saved bits after the outline moves.
> Do we mortals have access to some semi-highlevel routine which does this for
> us?  Or am I going to have to kludge something up?  Many thanks in advance.
> 
> Steve Upstill

No bits are saved -- the outline is just drawn in penmode patxor:  when
you redraw the same lines, the xor reverses the bits back to normal.

Scott Gillespie