home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-05 | 3.8 KB | 126 lines | [TEXT/PJMM] |
- unit ChessDrawing;
-
- { ©1991 [RHS] and Quinn "The Eskimo" }
-
- interface
-
- uses
- QuickDrawRules, ChessTypes, DialogSubs, Failure, GraphSubs,{}
- ChessSubs, ChessBoardSubs;
-
- procedure DrawBoard (var game: gameRecord; var globals: globalsRecord);
- procedure BoardUserItem (dlg: WindowPeek; itemNo: integer);
- procedure LineUserItem (dlg: DialogPtr; itemNo: integer);
- procedure MorgueUserItem (dlg: DialogPtr; itemNo: integer);
-
- implementation
-
- procedure DrawBoard (var game: gameRecord; var globals: globalsRecord);
- var
- x: boardXNdx;
- y: boardYNdx;
- r: rect;
- where: boardCoord;
- ps: penState;
- begin
- { Draw (most of) the vertical lines }
- for x := 0 to kBoardXMax do begin
- MoveTo(game.boardXOrg + x * kCellXPitch, game.boardYOrg);
- LineTo(game.boardXOrg + x * kCellXPitch, game.boardYOrg + kBoardYMax * kCellYPitch + kCellYPitch);
- end; { for }
- { Draw (most of) the horizontal lines }
- for y := 0 to kBoardYMax do begin
- MoveTo(game.boardXOrg, y * kCellYPitch + game.boardYOrg);
- LineTo(game.boardXOrg + kBoardXMax * kCellXPitch + kCellXPitch, y * kCellYPitch + game.boardYOrg);
- end; { for }
- { Draw the remaining two lines (bottom and right) }
- MoveTo(game.boardXOrg, game.boardYOrg + (kBoardYMax + 1) * kCellYPitch);
- LineTo(game.boardXOrg + (kBoardXMax + 1) * kCellXPitch, game.boardYOrg + (kBoardYMax + 1) * kCellYPitch);
- LineTo(game.boardYOrg + (kBoardYMax + 1) * kCellYPitch, game.boardYOrg);
- { Plot the piece icons }
- for x := 0 to kBoardXMax do begin
- where.x := x;
- for y := 0 to kBoardYMax do begin
- where.y := y;
- GetRect(game, where, r);
- PlotIcon(r, globals.icons[game.board[x, y].colour, game.board[x, y].occupant]);
- end; { for }
- end; { for }
- if game.playstate = ps_Pawning then begin
- GetPawningRect(game, r);
- GetPenState(ps);
- PenNormal;
- PenSize(kPawningXBorder, kPawningYBorder);
- FrameRect(r);
- where.y := kPawningY;
- for x := kPawningX to kPawningXMax do begin
- where.x := x;
- GetRect(game, where, r);
- PlotIcon(r, globals.icons[Cwhite, PlayerPiece(game.playertomove, globals.pawnpieces[x])]);
- end; { for }
- SetPenState(ps);
- end; { if }
- end; { DrawBoard }
-
- procedure BoardUserItem (dlg: WindowPeek; itemNo: integer);
- var
- ps: PenState;
- s1, s2: signedByte;
- gameh, globalsh: Handle;
- begin
- GetPenState(ps);
- gameh := Handle(dlg^.refcon);
- s1 := HGetState(gameh);
- HLock(gameh);
- globalsh := Handle(gamePeek(gameh)^^.globals);
- s2 := HGetState(globalsh);
- HLock(globalsh);
- DrawBoard(gamePeek(gameh)^^, globalsPeek(globalsh)^^);
- HSetState(gameh, s1);
- HSetState(globalsh, s2);
- SetPenState(ps);
- end; { BoardUserItem }
-
- procedure LineUserItem (dlg: DialogPtr; itemNo: integer);
- var
- r: Rect;
- ps: PenState;
- begin
- GetPenState(ps);
- PenPat(QDGlobals^.gray);
- GetDRect(dlg, itemNo, r);
- MoveTo(r.left, r.top);
- LineTo(r.right, r.top);
- SetPenState(ps);
- end; { LineUser }
-
- procedure MorgueUserItem (dlg: DialogPtr; itemNo: integer);
- var
- morguerect, plotrect: Rect;
- player: playerType;
- body: morgueNdx;
- begin
- case itemNo of
- dit_blk_pieces:
- player := Pblack;
- dit_wht_pieces:
- player := Pwhite;
- otherwise
- Failure('This is not a known morgue');
- end; { case }
- GetDRect(dlg, itemNo, morguerect);
- plotrect.topleft := morguerect.topleft;
- plotrect.bottom := plotrect.top + kMorgueYSize;
- plotrect.right := plotrect.left + kMorgueXSize;
- for body := 1 to kMorgueMax do begin
- PlotSICN(plotrect, gamePeek(WindowPeek(dlg)^.refcon)^^.globals^^.deadicons, ord(gamePeek(WindowPeek(dlg)^.refcon)^^.deaths[player][body]));
- if body = (kMorgueXMax + 1) then begin
- OffsetRect(plotrect, -kMorgueXMax * kMorgueXPitch, kMorgueYPitch);
- end
- else begin
- OffsetRect(plotrect, kMorgueXPitch, 0);
- end; { if }
- end; { for }
- end; { MorgueUserItem }
-
- end. { ChessDrawing }