home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-22 | 6.1 KB | 296 lines | [TEXT/CWIE] |
- void DrawWindowColors (WindowPtr w);
-
- #define kDragOnLeftVarCode 1
-
- #define kZigSize 3
- typedef struct {
- struct {
- Point topLeft;
- Point bottomRight;
- } point;
- Rect rect;
- } EasyRect;
-
-
- static
- void ZigZag (short varCode, Point start, Point finish)
- {
- short horizontalOffset = (varCode & kDragOnLeftVarCode) ? -kZigSize : kZigSize;
-
- while (start.v > finish.v) {
- LineTo (start.h += horizontalOffset, start.v -= kZigSize);
- horizontalOffset *= -1;
- }
- }
-
- static
- void MakeBorder (short varCode, Rect& contentRect, Boolean outset)
- {
- Point frameStart, frameFinish, zigStart, zigFinish;
- short width;
- short height, slop;
-
- {
- Rect bounds = contentRect;
-
- if (varCode & kDragOnLeftVarCode) {
-
- if (outset) {
- frameStart.v = bounds.top - 1;
- frameStart.h = bounds.right + 1;
- frameFinish.v = bounds.bottom + 1;
- frameFinish.h = bounds.right + 1;
-
- width = bounds.left - bounds.right - 2;
-
- zigStart.v = frameFinish.v - 1;
- zigStart.h = frameFinish.h;
- zigFinish.v = frameStart.v + 1;
- zigFinish.h = frameStart.h;
- } else {
-
- frameStart.v = bounds.top;
- frameStart.h = bounds.right;
- frameFinish.v = bounds.bottom;
- frameFinish.h = bounds.right;
- width = bounds.left - bounds.right;
-
- zigStart = frameFinish;
- zigFinish = frameStart;
- }
- } else {
-
- if (outset) {
- frameStart.v = bounds.top - 1;
- frameStart.h = bounds.left - 1;
- frameFinish.v = bounds.bottom + 1;
- frameFinish.h = bounds.left - 1;
-
- width = bounds.right - bounds.left + 2;
-
- zigStart.v = frameFinish.v - 1;
- zigStart.h = frameFinish.h;
- zigFinish.v = frameStart.v + 1;
- zigFinish.h = frameStart.h;
- } else {
-
- frameStart.v = bounds.top;
- frameStart.h = bounds.left;
- frameFinish.v = bounds.bottom;
- frameFinish.h = bounds.left;
- width = bounds.right - bounds.left;
-
- zigStart = frameFinish;
- zigFinish = frameStart;
- }
- }
- }
-
- MoveTo (frameStart.h, frameStart.v);
- LineTo (frameStart.h + width, frameStart.v);
- LineTo (frameStart.h + width, frameFinish.v);
- LineTo (frameFinish.h, frameFinish.v);
-
- LineTo (zigStart.h, zigStart.v);
-
- // calculate slop
- height = zigStart.v - zigFinish.v;
- slop = height % (kZigSize * 2);
-
- Point actualZigStart = { zigStart.v -= slop / 2, zigStart.h };
- Point actualZigFinish = { zigFinish.v + (slop - (slop / 2)), zigFinish.h };
-
- LineTo (actualZigStart.h, actualZigStart.v);
-
- // ZigZag from start to finish
- ZigZag (varCode, actualZigStart, actualZigFinish);
-
- LineTo (zigFinish.h, zigFinish.v);
- }
-
- static
- void BorderTest (WindowPtr w)
- {
- Rect r = { 40, 40, 242, 242 };
- short varCode = 0;; // kDragOnLeftVarCode;
-
- SetPort (w);
-
- ForeColor (blackColor);
- // PaintRgn (w -> visRgn);
-
- RgnHandle content = NewRgn ();
- OpenRgn ();
- MakeBorder (varCode, r, false);
- CloseRgn (content);
-
- RgnHandle larger = NewRgn ();
- OpenRgn ();
- MakeBorder (varCode, r, true);
- CloseRgn (larger);
-
- RgnHandle drag = NewRgn ();
- Rect dragRect = r;
-
- if (varCode & kDragOnLeftVarCode) {
- dragRect.right = r.left;
- dragRect.left = dragRect.right - 9;
- } else {
- dragRect.left = r.right;
- dragRect.right = dragRect.left + 9;
- }
-
- InsetRect (&dragRect, 0, -1);
- RectRgn (drag, &dragRect);
- UnionRgn (larger, drag, larger);
-
- RgnHandle shadow = NewRgn ();
- CopyRgn (larger, shadow);
- OffsetRgn (shadow, 1, 1);
- UnionRgn (larger, shadow, larger);
-
- ForeColor (blackColor);
- PaintRgn (larger);
- ForeColor (yellowColor);
- PaintRgn (content);
-
-
- DisposeRgn (content);
- DisposeRgn (larger);
- DisposeRgn (shadow);
- DisposeRgn (drag);
- }
-
-
- void DrawWindowColors (WindowPtr w)
- {
- Rect r;
- int i;
- AuxWinHandle auxInfo;
- RGBColor c;
- Str255 s;
-
- SetPort (w);
- TextFont (geneva);
- TextSize (9);
-
- GetAuxWin (w, &auxInfo);
-
- for (i = 0; i <= (**(**auxInfo).awCTable).ctSize; i++) {
- SetRect (&r, i * 16 + 2, 2, i * 16 + 16, 16);
- c = (**(**auxInfo).awCTable).ctTable [i].rgb;
- RGBForeColor (&c);
- PaintRect (&r);
- ForeColor (blackColor);
- FrameRect (&r);
- MoveTo (r.left + 1, r.bottom + 13);
- NumToString (i, s);
- DrawString (s);
- }
- }
-
-
-
- void main (void)
-
- {
- WindowPtr w;
- EventRecord theEvent;
- short whichPart;
- Rect windowRect;
- WindowPtr whichWindow;
- long result;
- long newSize;
- RGBColor back = { 0xFFFF, 0xFFFF, 0x8000 };
-
- InitGraf (&qd.thePort);
- InitFonts ();
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs (nil);
-
- InitCursor ();
-
- if (OpenResFile ("\pScrappy") < 0) {
- SysBeep (10);
- return;
- }
-
- SetRect (&windowRect, 20, 40, 440, 460);
-
- OffsetRect (&windowRect, -640, 0);
-
-
- // w = NewCWindow (nil, &windowRect, "\p", true, 3200, (WindowPtr) -1, true, 0);
-
- w = GetNewCWindow (129, nil, (WindowPtr) -1);
-
- w = GetNewCWindow (128, nil, (WindowPtr) -1);
-
- ((WindowPeek) w) -> spareFlag = 1;
- ShowWindow (w);
-
- if (!w) {
- SysBeep (1);
- return;
- }
- SetPort (w);
- RGBBackColor (&back);
- do {
-
- WaitNextEvent (everyEvent, &theEvent, 1, nil);
-
- if (theEvent.what == keyDown)
- break;
-
- if (theEvent.what == updateEvt) {
- BeginUpdate ((WindowPtr) theEvent.message);
-
- //DrawWindowColors ((WindowPtr) theEvent.message);
- BorderTest ((WindowPtr) theEvent.message);
-
- // DrawGrowIcon ((WindowPtr) theEvent.message);
- EndUpdate ((WindowPtr) theEvent.message);
- }
-
- if (theEvent.what == mouseDown) {
-
- whichPart = FindWindow (theEvent.where, &whichWindow);
-
- switch (whichPart) {
-
- case (inDrag) :
- DragWindow (whichWindow, theEvent.where, &qd.screenBits.bounds);
- break;
-
- case (inGrow) :
- newSize = GrowWindow (whichWindow, theEvent.where, &qd.screenBits.bounds);
- SizeWindow (whichWindow, newSize & 0x0000FFFF, (newSize & 0xFFFF0000) >> 16, true);
- break;
-
- case (inGoAway) :
- if (TrackGoAway (whichWindow, theEvent.where))
- return;
- break;
-
- case (inZoomIn) :
- case (inZoomOut) :
- TrackBox (whichWindow, theEvent.where, whichPart);
- break;
-
- case (inContent) :
- if (FrontWindow () != whichWindow)
- SelectWindow (whichWindow);
- else {
- SetPort (whichWindow);
- GlobalToLocal (&theEvent.where);
- MoveTo (theEvent.where.h, theEvent.where.v);
- LineTo (theEvent.where.h, theEvent.where.v);
- }
- break;
- }
- }
-
- } while (1);
- }