home *** CD-ROM | disk | FTP | other *** search
- #define INTERFACE_C
- #include "Interface.h"
- #undef INTERFACE_C
-
-
- #if defined(__MWERKS__)
- #pragma segment __%Main
- #else
- #pragma segment Main
- #endif
-
-
- static char gMoveNotation[8] = " ";
-
-
-
- void
- UndoLastMove (void)
- {
- (void) PopBoard();
- (void) PopBoard();
- if (gSet.Players == 3)
- (void) PopBoard();
-
- gTheGame.CurrentMove -= gSet.Players;
-
- InvalBoard();
- }
-
-
-
- Rect
- FieldToRect (Field f)
- {
- Point coords = FieldToCarthCoord (f);
- Rect bounds;
-
- bounds.top = coords.v * gSet.FieldHeight;
- bounds.bottom = (coords.v + 1) * gSet.FieldHeight;
- bounds.left = coords.h * gSet.FieldWidth / 2;
- bounds.right = (coords.h + 2) * gSet.FieldWidth / 2;
-
- OffsetRect (& bounds, 1, 0); // correction for pixel outside hexagon
-
- return bounds;
- }
-
-
-
- Point
- FieldToCarthCoord (Field f)
- {
- Point coords;
-
- if (f > 0 && f <= 5) { coords.h = 2 * (f - 1) + 4; coords.v = 0; }
- else if (f <= 11) { coords.h = 2 * (f - 6) + 3, coords.v = 1; }
- else if (f <= 18) { coords.h = 2 * (f - 12) + 2, coords.v = 2; }
- else if (f <= 26) { coords.h = 2 * (f - 19) + 1, coords.v = 3; }
- else if (f <= 35) { coords.h = 2 * (f - 27) + 0, coords.v = 4; }
- else if (f <= 43) { coords.h = 2 * (f - 36) + 1, coords.v = 5; }
- else if (f <= 50) { coords.h = 2 * (f - 44) + 2, coords.v = 6; }
- else if (f <= 56) { coords.h = 2 * (f - 51) + 3, coords.v = 7; }
- else if (f <= 61) { coords.h = 2 * (f - 57) + 4, coords.v = 8; }
-
- return coords;
- }
-
-
-
- Point
- FieldToLoc (Field f)
- {
- Point loc;
-
- loc.h = loc.v = 0;
-
- if (f > 0 && f <= 5)
- {
- loc.h = (f - 1) * gSet.FieldWidth + 5 * gSet.FieldWidth / 2;
- loc.v = 1 * gSet.FieldHeight / 2;
- }
- else if (f <= 11)
- {
- loc.h = (f - 6) * gSet.FieldWidth + 2 * gSet.FieldWidth;
- loc.v = 3 * gSet.FieldHeight / 2;
- }
- else if (f <= 18)
- {
- loc.h = (f - 12) * gSet.FieldWidth + 3 * gSet.FieldWidth / 2;
- loc.v = 5 * gSet.FieldHeight / 2;
- }
- else if (f <= 26)
- {
- loc.h = (f - 19) * gSet.FieldWidth + 1 * gSet.FieldWidth;
- loc.v = 7 * gSet.FieldHeight / 2;
- }
- else if (f <= 35)
- {
- loc.h = (f - 27) * gSet.FieldWidth + 1 * gSet.FieldWidth / 2;
- loc.v = 9 * gSet.FieldHeight / 2;
- }
- else if (f <= 43)
- {
- loc.h = (f - 36) * gSet.FieldWidth + 1 * gSet.FieldWidth ;
- loc.v = 11 * gSet.FieldHeight / 2;
- }
- else if (f <= 50)
- {
- loc.h = (f - 44) * gSet.FieldWidth + 3 * gSet.FieldWidth / 2;
- loc.v = 13 * gSet.FieldHeight / 2;
- }
- else if (f <= 56)
- {
- loc.h = (f - 51) * gSet.FieldWidth + 2 * gSet.FieldWidth;
- loc.v = 15 * gSet.FieldHeight / 2;
- }
- else if (f <= 61)
- {
- loc.h = (f - 57) * gSet.FieldWidth + 5 * gSet.FieldWidth / 2;
- loc.v = 17 * gSet.FieldHeight / 2;
- }
- loc.h++; // correction for pixel outside hexagon
- return loc;
- }
-
-
-
- Rect
- FieldToBallRect (Field f)
- {
- Point coords = FieldToCarthCoord (f);
- Rect rect;
- short diff = gSet.FieldWidth - gSet.FieldHeight;
-
- rect.top = coords.v * gSet.FieldHeight;
- rect.bottom = rect.top + gSet.FieldHeight + 1;
- rect.left = (coords.h * gSet.FieldWidth)/ 2 + (diff + 1) / 2;
- rect.right = rect.left + gSet.FieldHeight + 1;
-
- // rect.left--;
- // rect.right--;
-
- return rect;
- }
-
-
-
- void
- InvalBoard (void)
- {
- Rect boardRect;
-
- if (ColorQDAvailable())
- {
- Update3D();
- RestoreColors();
- }
-
- SetRect (& boardRect, 0, 0, 9 * gSet.FieldWidth + 1 + 1, 9 * gSet.FieldHeight + 1);
- if (gBlackAndWhite)
- {
- PenPat ((ConstPatternParam) & qd.ltGray);
- PaintRect (& boardRect);
- PenPat ((ConstPatternParam) & qd.black);
- }
- else
- {
- EraseRect (& boardRect);
- }
- InvalRect (& boardRect);
- }
-
-
-
- void
- UpdateBoard (WindowPtr window)
- {
- SetPort (window);
-
- if (ColorQDAvailable())
- {
- Update3D();
- RestoreColors();
- }
-
- BeginUpdate (window);
-
- if (! EmptyRgn (window->visRgn)) // draw if updating needs to be done
- {
- DrawBackground (window);
- DrawBoard ((BoardPtr) GetWRefCon (window));
- UpdtDialog (window, window->visRgn);
- }
-
- EndUpdate (window);
- }
-
-
-
- void
- DrawBoard (BoardPtr board)
- {
- Field f;
- Rect fieldRect;
- WindowPtr window = gAbaloneWindow;
-
- // draw invalidated field backgrounds
-
- for (f = 1; f <= kFields; f++)
- {
- // if (board[0].field[f] == empty)
- {
- // fieldRect = FieldToRect (f);
- fieldRect = FieldToBallRect (f); // Optimization??
-
- if (RectInRgn (& fieldRect, window->visRgn))
- DrawField (f);
- }
- }
-
- // draw invalidated fields grid lines (if we want them)
-
- if (! gSet.Balls3D)
- {
- for (f = 1; f <= kFields; f++)
- {
- fieldRect = FieldToRect (f);
-
- if (RectInRgn (& fieldRect, window->visRgn))
- DrawGrid (f);
- }
- }
- // draw invalidated balls
- // this is done separately from the fields,
- // so the balls can overlap the bounds of all fields.
-
- for (f = 1; f <= kFields; f++)
- {
- if (board[0].field[f] != empty)
- {
- Rect ballRect;
-
- ballRect = FieldToBallRect (f);
-
- if (RectInRgn (& ballRect, window->visRgn))
- DrawBall (f, board[0].field[f]);
- }
- }
- }
-
-
-
- void
- InvalItems (WindowPtr wp)
- {
- short type, item;
- Handle hndl;
- Rect box;
-
- Assert (wp == gAbaloneWindow, ILLEGAL_PARAMETER);
-
- SetPort (wp);
- for (item = 1; item <= 4; item++)
- {
- GetDItem (wp, item, & type, & hndl, & box);
- InvalRect (& box);
- }
- if (gBlackAndWhite)
- {
- PenPat ((ConstPatternParam) & qd.ltGray);
- PaintRect (& box); // Erase notation item
- PenPat ((ConstPatternParam) & qd.black);
- }
- else
- {
- EraseRect (& box); // Erase notation item
- }
- }
-
-
-
- void
- SizeItems (WindowPtr wp)
- {
- short type;
- Handle hndl;
- Rect box;
-
- Assert (wp == gAbaloneWindow, ILLEGAL_PARAMETER);
-
- SetPort (wp);
-
- // resize and move item 1 to fit in bottom left corner
-
- GetDItem (wp, 1, & type, & hndl, & box);
- InvalRect (& box);
-
- box = wp->portRect;
- box.left += 2;
- box.bottom -= 2;
- box.top = box.bottom - 3 * gSet.FieldHeight / 2;
- box.right = box.left + 3 * gSet.FieldHeight / 2;
-
- SetDItem (wp, 1, type, hndl, & box);
- InvalRect (& box);
-
- // resize and move item 2 to fit in bottom right corner
-
- GetDItem (wp, 2, & type, & hndl, & box);
- InvalRect (& box);
-
- box = wp->portRect;
- box.right -= 2;
- box.bottom -= 2;
- box.top = box.bottom - 3 * gSet.FieldHeight / 2;
- box.left = box.right - 3 * gSet.FieldHeight / 2;
-
- SetDItem (wp, 2, type, hndl, & box);
- InvalRect (& box);
-
- // resize and move item 3 to fit in top right corner
-
- GetDItem (wp, 3, & type, & hndl, & box);
- InvalRect (& box);
-
- box = wp->portRect;
- box.right -= 2;
- box.top += 2;
- box.bottom = box.top + 3 * gSet.FieldHeight / 2;
- box.left = box.right - 3 * gSet.FieldHeight / 2;
-
- SetDItem (wp, 3, type, hndl, & box);
- InvalRect (& box);
- }
-
-
-
- void
- DrawPoint (Rect *box, short color)
- {
- if (! gBlackAndWhite)
- {
- RGBForeColor (& gSet.Color[color]);
- PaintOval (box);
- ForeColor (blackColor);
- return;
- }
- switch (color)
- {
- case whit:
- EraseOval (box);
- break;
- case blak:
- PaintOval (box);
- break;
- case grin:
- PenPat ((ConstPatternParam) & qd.gray);
- PaintOval (box);
- PenNormal();
- break;
- }
- }
-
-
- // Draw a small ball in the bottom left corner of the screen for each ball black has won.
-
- pascal void
- DrawBlackPoints (WindowPtr wp, short item)
- {
- BoardPtr board = (BoardPtr) GetWRefCon (gAbaloneWindow);
- short points = BallsWon (board, blak);
-
- if (points != 0)
- {
- short type;
- Handle hndl;
- Point oldLoc;
- Rect box;
- short ball;
-
- GrafPtr oldPort;
- GetPort (& oldPort);
- GetPen (& oldLoc);
- SetPort (wp);
-
- GetDItem (wp, item, & type, & hndl, & box);
-
- box.top = box.bottom - gSet.FieldHeight/2;
- box.right = box.left + gSet.FieldHeight/2;
-
- for (ball = 1; ball <= points; ball++)
- {
- DrawPoint (& box, board->loot[blak-1][ball]);
-
- // Compute the position for the next ball such that the balls are stacked neatly.
-
- switch (ball)
- {
- case 1:
- case 2:
- case 4:
- box.left += gSet.FieldHeight / 2;
- box.right += gSet.FieldHeight / 2;
- break;
- case 3:
- box.left -= gSet.FieldHeight / 2;
- box.right -= gSet.FieldHeight / 2;
- case 5:
- box.left -= gSet.FieldHeight / 4;
- box.right -= gSet.FieldHeight / 4;
- box.top -= ((short) (1.74 * gSet.FieldHeight)) / 4;
- box.bottom -= ((short) (1.74 * gSet.FieldHeight)) / 4;
- break;
- }
- }
- MoveTo (oldLoc.h, oldLoc.v);
- SetPort (oldPort);
- }
- }
-
-
- // Draw a small ball in the bottom right corner of the screen for each ball white has won.
-
- pascal void
- DrawWhitePoints (WindowPtr wp, short item)
- {
- BoardPtr board = (BoardPtr) GetWRefCon (gAbaloneWindow);
- short points = BallsWon (board, whit);
-
- if (points != 0)
- {
- short type;
- Handle hndl;
- Point oldLoc;
- Rect box;
- short ball;
-
- GrafPtr oldPort;
- GetPort (& oldPort);
- GetPen (& oldLoc);
- SetPort (wp);
-
- GetDItem (wp, item, & type, & hndl, & box);
-
- box.top = box.bottom - gSet.FieldHeight/2;
- box.left = box.right - gSet.FieldHeight/2;
-
- for (ball = 1; ball <= points; ball++)
- {
- DrawPoint (& box, board->loot[whit-1][ball]);
-
- switch (ball)
- {
- case 1:
- case 2:
- case 4:
- box.left -= gSet.FieldHeight / 2;
- box.right -= gSet.FieldHeight / 2;
- break;
- case 3:
- box.left += gSet.FieldHeight / 2;
- box.right += gSet.FieldHeight / 2;
- case 5:
- box.left += gSet.FieldHeight / 4;
- box.right += gSet.FieldHeight / 4;
- box.top -= ((short) (1.74 * gSet.FieldHeight)) / 4;
- box.bottom -= ((short) (1.74 * gSet.FieldHeight)) / 4;
- break;
- }
- }
- MoveTo (oldLoc.h, oldLoc.v);
- SetPort (oldPort);
- }
- }
-
-
-
- // Draw a small ball in the top right corner of the screen for each ball green has won.
-
- pascal void
- DrawGreenPoints (WindowPtr wp, short item)
- {
- BoardPtr board = (BoardPtr) GetWRefCon (gAbaloneWindow);
- short points = BallsWon (board, grin);
-
- if (points != 0)
- {
- short type;
- Handle hndl;
- Point oldLoc;
- Rect box;
- short ball;
-
- GrafPtr oldPort;
- GetPort (& oldPort);
- GetPen (& oldLoc);
- SetPort (wp);
-
- GetDItem (wp, item, & type, & hndl, & box);
-
- box.bottom = box.top + gSet.FieldHeight/2;
- box.left = box.right - gSet.FieldHeight/2;
-
- for (ball = 1; ball <= points; ball++)
- {
- DrawPoint (& box, board->loot[grin-1][ball]);
-
- switch (ball)
- {
- case 1:
- case 2:
- case 4:
- box.left -= gSet.FieldHeight / 2;
- box.right -= gSet.FieldHeight / 2;
- break;
- case 3:
- box.left += gSet.FieldHeight / 2;
- box.right += gSet.FieldHeight / 2;
- case 5:
- box.left += gSet.FieldHeight / 4;
- box.right += gSet.FieldHeight / 4;
- box.top += ((short) (1.74 * gSet.FieldHeight)) / 4;
- box.bottom += ((short) (1.74 * gSet.FieldHeight)) / 4;
- break;
- }
- }
- MoveTo (oldLoc.h, oldLoc.v);
- SetPort (oldPort);
- }
- }
-
-
-
- void
- EraseBall (Field field)
- {
- Rect ballRect;
-
- ballRect = FieldToBallRect (field);
-
- if (gBlackAndWhite)
- {
- PenPat ((ConstPatternParam) & qd.ltGray);
- PaintOval (& ballRect);
- PenPat ((ConstPatternParam) & qd.black);
- }
- else
- {
- EraseOval (& ballRect);
- }
- }
-
-
-
- void
- EraseField (Field field)
- {
- Rect fieldRect;
-
- fieldRect = FieldToRect (field);
- EraseRect (& fieldRect);
- }
-
-
-
- short
- PixelSize (void)
- {
- return (*(((CWindowPtr) gAbaloneWindow)->portPixMap))->pixelSize;
- }
-
-
- void
- DrawField (Field field)
- {
- Rect ballRect;
-
- if (! field)
- return;
-
- if (! gBlackAndWhite || gSet.Balls3D) // not the most simple case
- {
- DrawFieldColor (field);
- return;
- }
- EraseBall (field);
- ballRect = FieldToBallRect (field);
- ForeColor (blackColor);
- InsetRect (& ballRect, gSet.FieldHeight / 3, gSet.FieldHeight / 3);
- PaintOval (& ballRect);
- }
-
-
-
- void
- DrawFieldColor (Field field)
- {
- Rect ballRect;
- RGBColor fieldColor;
-
- // Draw the ball in color
-
- if (gSet.Balls3D) // The real hard case
- {
- DrawFieldColor3D (field);
- return;
- }
- EraseField (field);
- ballRect = FieldToBallRect (field);
- fieldColor = gSet.Color[0];
- Darken (& fieldColor);
- RGBForeColor (& fieldColor);
- InsetRect (& ballRect, gSet.FieldHeight / 3, gSet.FieldHeight / 3);
- PaintOval (& ballRect);
- RestoreColors();
- }
-
-
-
- void
- DrawGrid (Field field)
- {
- Rect fieldRect;
-
- if (! field)
- return;
-
- if (! gBlackAndWhite) // not the most simple case
- {
- DrawGridColor (field);
- return;
- }
- fieldRect = FieldToRect (field);
-
- FrameHexagon (& fieldRect);
- }
-
-
-
- void
- DrawGridColor (Field field)
- {
- Rect fieldRect = FieldToRect (field);
- RGBColor fieldColor = gSet.Color[0];
-
- Darken (& fieldColor);
- Darken (& fieldColor);
- RGBForeColor (& fieldColor);
- FrameHexagon (& fieldRect);
- RestoreColors();
- }
-
-
-
-
- void
- DrawBall (Field field, char color)
- {
- Rect ballRect;
-
- if (! field || ! color)
- return;
-
- if (! gBlackAndWhite || gSet.Balls3D) // not the most simple case
- {
- DrawBallColor (field, color);
- return;
- }
-
- ballRect = FieldToBallRect (field);
-
- // Simple case: PaintOval the ball, done.
-
- switch (color)
- {
- case whit:
- EraseOval (& ballRect);
- break;
- default:
- case blak:
- PaintOval (& ballRect);
- break;
- case grin: // gray, on this screen
- PenPat ((ConstPatternParam) & qd.gray);
- PaintOval (& ballRect);
- PenNormal();
- break;
- }
- }
-
-
-
- void
- DrawBallColor (Field field, char color)
- {
- Rect ballRect;
-
- // Draw the ball in color
-
- if (gSet.Balls3D) // The real hard case
- {
- DrawBallColor3D (field, color);
- return;
- }
- // Simple case: PaintOval the ball in the right color
-
- ballRect = FieldToBallRect (field);
-
- RGBForeColor (& gSet.Color[color]);
- PaintOval (& ballRect);
- ForeColor (blackColor);
- }
-
-
-
- void
- FrameHexagon (Rect * r)
- {
- short hor = r->right - r->left,
- ver = r->bottom - r->top,
- ddH = (hor + 1) / 2,
- ddV = ver,
- dH = (hor + 2) / 4,
- dV = (ver + 1) / 2;
-
- MoveTo (r->left + dH - 1, r->top);
- Line (ddH, 0);
- Line (dH, dV);
- Line (-dH, ddV - dV);
- Line (-ddH, 0);
- Line (-dH, dV - ddV);
- Line (dH, -dV);
- }
-
-
-
- void
- DoFieldClick (Field f)
- {
- BoardPtr board = (BoardPtr) GetWRefCon (gAbaloneWindow);
-
- if ( gSet.PlayerKind[gTheGame.CurrentPlayer] != humanPlayer
- || board->field[f] != gTheGame.CurrentPlayer)
- {
- SndPlayBeep();
- }
- else
- {
- Point mouseLoc;
- long position;
- Rect ballRect, fieldRect, limitRect, slopRect;
- RgnHandle ballRgn = NewRgn();
- Field toField;
- MoveData move;
-
- ballRect = FieldToBallRect (f);
- fieldRect = FieldToRect (f);
-
- OpenRgn();
- FrameOval (& ballRect);
- CloseRgn (ballRgn);
-
- limitRect = slopRect = fieldRect;
- InsetRect (& limitRect, -gSet.FieldWidth/2 - 1, -gSet.FieldHeight/2 - 1);
- InsetRect (& slopRect, -gSet.FieldWidth, -gSet.FieldHeight - 1);
- mouseLoc = FieldToLoc (f);
- position = DragGrayRgn (ballRgn, mouseLoc, & limitRect, & slopRect, noConstraint, NULL);
-
- DisposeRgn (ballRgn), ballRgn = 0;
-
- mouseLoc.v += ((position) >> 16) & 0xFFFF;
- mouseLoc.h += position & 0xFFFF;
-
- toField = LocToField (mouseLoc.h, mouseLoc.v);
- move[0] = f;
- move[1] = move[2] = 0;
- move[3] = Direction (f, toField);
-
- if (board->field [f] == gTheGame.CurrentPlayer)
- {
- if (ProcessMove (move, false))
- {
- // The broadcast is done after the board has been modified:
- // The move is still valid, so we can first send just the move,
- // but if sending the move somehow fails,
- // The whole board is already updated and can be sent 'as is'.
- ;
- BroadcastMove (move, PriorPlayer (CurrentPlayer()), CheckSum (RecentBoard()));
- }
- }
- }
- }
-
-
-
- void
- DoFieldShiftClick (Field f1)
- {
- BoardPtr board = (BoardPtr) GetWRefCon (gAbaloneWindow);
-
- if ( gSet.PlayerKind[gTheGame.CurrentPlayer] != humanPlayer
- || board->field[f1] != gTheGame.CurrentPlayer)
- {
- SndPlayBeep();
- }
- else
- {
- Point mouseLoc;
- long position;
- Rect ballRect, fieldRect, limitRect, slopRect;
- MoveData f;
- Field downField, upField;
- short b;
- RgnHandle ballRgn;
-
- f[0] = f[1] = f[2] = downField = upField = 0;
-
-
- for (b = 0; b < 4; b++)
- {
- EventRecord nextEvent;
-
- downField = f1; // for the first ball, use the original mouse-down
-
- if (b != 0) // for all other balls, get a new mouse-down
- {
- do
- GetNextEvent (everyEvent, & nextEvent);
- while (nextEvent.what != mouseDown);
-
- GlobalToLocal (& nextEvent.where);
- downField = LocToField (nextEvent.where.h, nextEvent.where.v);
- }
-
- fieldRect = FieldToRect (downField);
- ballRect = FieldToBallRect (downField);
-
- if (board->field[downField] == empty) // cancel the selection & get out of here
- {
- short b2;
-
- for (b2 = 0; b2 < b; b2++) // deselect all balls
-
- XORBall (f[b2]);
-
- return;
- }
- if ( b > 0 && downField == f[b-1] // mouse-down in the same ball twice:
- || b > 1 && downField == f[b-2] // assume user is starting to drag
- || b > 2 && downField == f[b-3]
- )
- break;
-
- if (b == 3)
- break;
-
- f[b] = downField; // add ball to selection
-
- if (! ValidFliche (board, f))
- {
- f[b] = 0;
- --b;
- SndPlayBeep();
- continue;
- }
-
- XORBall (f[b]); // show the ball is selected
-
- do // Wait for mouse-up or mouse out of current field
- {
- GetMouse (& mouseLoc);
- (void) GetNextEvent (everyEvent, & nextEvent);
- }
- while (nextEvent.what != mouseUp && PtInRect (mouseLoc, & fieldRect));
-
- GlobalToLocal (& nextEvent.where);
- upField = LocToField (nextEvent.where.h, nextEvent.where.v);
- if (! PtInRect (mouseLoc, & fieldRect))
- break;
- }
-
- ballRgn = NewRgn();
- OpenRgn();
- for (b = 0; b < 3; b++)
- {
- if (f[b] != 0)
- {
- ballRect = FieldToBallRect (f[b]);
- FrameOval (& ballRect);
- }
- }
- CloseRgn (ballRgn);
-
- limitRect = slopRect = fieldRect;
- InsetRect (& limitRect, -gSet.FieldWidth/2, -gSet.FieldHeight/2);
- InsetRect (& slopRect, -gSet.FieldWidth, -gSet.FieldHeight);
- mouseLoc = FieldToLoc (downField);
-
- for (b = 0; b < 3; b++)
-
- if (f[b] != 0)
-
- XORBall (f[b]);
-
- position = DragGrayRgn (ballRgn, mouseLoc, & limitRect, & slopRect, noConstraint, NULL);
- DisposeRgn (ballRgn), ballRgn = 0;
-
- mouseLoc.v += ((position) >> 16) & 0xFFFF;
- mouseLoc.h += position & 0xFFFF;
-
- upField = LocToField (mouseLoc.h, mouseLoc.v);
- f[3] = Direction (downField, upField);
-
- if (board->field [f[0]] == gTheGame.CurrentPlayer)
- {
- if (ProcessMove (f, false))
- {
- // The broadcast is done after the board has been modified:
- // The move is still valid, so we can first send just the move,
- // but if sending the move somehow fails,
- // The whole board is already updated and can be sent 'as is'.
-
- BroadcastMove (f, PriorPlayer (CurrentPlayer()), CheckSum (RecentBoard()));
- }
- }
- }
- }
-
-
-
- void
- InvalBall (Field field)
- {
- // Rect ballRect = FieldToBallRect (field);
- //
- // SetPort (FrontWindow());
- // InvalRect (& ballRect);
-
-
- Rect ballRect = FieldToBallRect (field);
- RgnHandle ballRgn = NewRgn();
-
- SetPort (FrontWindow());
- OpenRgn();
- FrameOval (& ballRect);
- CloseRgn (ballRgn);
- InvalRgn (ballRgn);
- DisposeRgn (ballRgn);
- }
-
-
-
- void
- ValidBall (Field field)
- {
- Rect ballRect = FieldToBallRect (field);
- RgnHandle ballRgn = NewRgn();
-
- SetPort (FrontWindow());
- OpenRgn();
- FrameOval (& ballRect);
- CloseRgn (ballRgn);
- ValidRgn (ballRgn);
- DisposeRgn (ballRgn);
- }
-
-
-
-
- void
- XORBall (Field field)
- {
- Rect r = FieldToBallRect (field);
-
- PenPat ((ConstPatternParam) & qd.black);
- PenMode (patXor);
- PenSize (4, 4);
- FrameOval (& r);
- PenNormal();
- }
-
-
-
- void
- ShowMove (MovePtr move, Boolean animate)
- {
- ShowPropMove (move[0], move[3], animate);
- }
-
-
-
- void
- ShowPropMove (Field f, short direction, Boolean animate)
- {
- if (f == 0 || direction == down || FieldOwner (f) == empty)
- {
- long dummy;
-
- if (f != 0) InvalBall (f);
- if (animate && ! gSet.SoundOn) Delay (10L, & dummy);
-
- return;
- }
- InvalBall (f);
- if (animate) XORBall (f);
- ShowPropMove (Neighbour (f, direction), direction, animate);
- }
-
-
-
- void
- ShowFlicheMove (MovePtr move, Boolean animate)
- {
- long dummy;
-
- if (move[0]) { InvalBall (move[0]); if (animate) XORBall (move[0]); }
- if (move[1]) { InvalBall (move[1]); if (animate) XORBall (move[1]); }
- if (move[2]) { InvalBall (move[2]); if (animate) XORBall (move[2]); }
- if (move[0]) InvalBall (Neighbour (move[0], move[3]));
- if (move[1]) InvalBall (Neighbour (move[1], move[3]));
- if (move[2]) InvalBall (Neighbour (move[2], move[3]));
- if (animate && ! gSet.SoundOn)
- Delay (10L, & dummy);
- }
-
-
-
- void
- RestoreColors (void)
- {
- ForeColor (blackColor);
- if (! ColorQDAvailable())
- BackColor (whiteColor);
- else
- RGBBackColor (& gSet.Color[0]);
- }
-
-
-
- void
- ShowNotation (MovePtr move, BoardPtr board)
- {
- short type;
- Rect box;
- Handle hndl;
- GrafPtr oldPort;
-
- // just store the move in case notation is turned on
-
- MoveToContestNotation (move, gMoveNotation, board);
-
- if (! gSet.ShowNotation)
- return;
-
- GetPort (& oldPort);
- SetPort (gAbaloneWindow);
- GetDItem (gAbaloneWindow, 4, & type, & hndl, & box);
- InvalRect (& box);
- SetPort (oldPort);
- }
-
-
-
- // draw the contest notation for a move
-
- pascal void
- DrawNotationItemProc (WindowPtr wp, short item)
- {
- short type;
- Rect box;
- Handle hndl;
- GrafPtr oldPort;
-
- if (! gSet.ShowNotation)
- return;
-
- GetPort (& oldPort);
- SetPort (wp);
-
- GetDItem (wp, 4, & type, & hndl, & box);
-
- if (! gBlackAndWhite)
- {
- RGBColor itemColor = gSet.Color[0];
-
- Darken (& itemColor);
- Darken (& itemColor);
- RGBForeColor (& itemColor);
- }
-
- FrameRect (& box);
- TextFont (monaco);
- TextFace (bold);
- InsetRect (& box, 1, 1);
- TextBox (gMoveNotation, strlen (gMoveNotation), & box, teJustCenter);
- TextFace (normal);
- TextFont (systemFont);
-
- if (! gBlackAndWhite)
- {
- RestoreColors();
- }
-
- SetPort (oldPort);
- }
-
-
-
- void
- Darken (RGBColor *color)
- {
- color->red -= (color->red >> 2);
- color->green -= (color->green >> 2);
- color->blue -= (color->blue >> 2);
- }
-
-
-
- void
- Lighten (RGBColor *color)
- {
- color->red += ((0xffff - color->red) >> 2);
- color->green += ((0xffff - color->green) >> 2);
- color->blue += ((0xffff - color->blue) >> 2);
- }
-
-
-