sdh@joevax.UUCP (The Doctor) (08/19/86)
#include <quickdraw.h> #include <window.h> #include <event.h> #include <osutil.h> /* In this little hack is a routine that will create a rectangular region * that surrounds a line, with a 2 pixel leeway on each side. * Written by Steve Hawley 8/19/86 * Aztec C ver 1.06H * * Note that it is imperative to have the rectangle definition be "proper". * This means that left hand side must be less than the right, and the * top less than the bottom. */ WindowRecord wRecord; WindowPtr myWindow; EventRecord myEvent; surrnd_line(x1, y1, x2, y2, region) int x1, y1, x2, y2; RgnHandle region; { Rect temprect; register int bucket; /* make the rectangle "proper" */ if (x1 > x2) { bucket = x1; x1 = x2; x2 = bucket; } if (y1 > y2) { bucket = y1; y1 = y2; y2 = bucket; } SetRect(&temprect, x1, y1, x2, y2); /* define a rectangle that will contain the line */ InsetRect(&temprect, -2, -2); RectRgn(region, &temprect); /* expand it 2 pixels on each side. * Note that these three lines could probably have been done as: SetRectRgn(region, x1-2, y1-2, x2+2, y2+2); * but I chose the above for readability. They speed difference * is probably minimal. */ } main () { Rect screen; RgnHandle r1, r2 ,r3; register int i1 = 0, i2 = 0, i3 = 0; long ticks; InitGraf(&thePort); /* do inits */ InitWindows(); FlushEvents(everyEvent,0); SetCursor(&arrow); HideCursor(); SetRect(&screen, 10, 40, 502, 340); /*set up window */ myWindow = NewWindow(&wRecord, &screen, ctop("regions"), 1,0,(char*)-1,1,(long)0); SetPort(myWindow); ShowWindow(myWindow); /* make 3 new regions */ r1 = NewRgn(); r2 = NewRgn(); r3 = NewRgn(); /* do some magic numbers to define them */ MoveTo(10,10); LineTo(25, 40); surrnd_line(10, 10, 25, 40, r1); FrameRgn(r1); MoveTo(70,5); LineTo(30,200); surrnd_line(70, 5, 30, 200, r2); FrameRgn(r2); MoveTo(150, 250); LineTo(300,200); surrnd_line(150, 250, 300, 200, r3); FrameRgn(r3); /* make them flash. */ while(!Button()) { Delay(3L, &ticks); /* delay 3 ticks */ ++i1; ++i2; ++i3; if (i1 > 3) { i1 = 0; InvertRgn(r1); /* unique rates for all 3 */ /* hooray for magic numbers */ } if (i2 > 7) { i2 = 0; InvertRgn(r2); } if (i3 > 11) { i3 = 0; InvertRgn(r3); } } }