📄 display.cpp
字号:
hOldBmp = (HBITMAP)SelectObject(hMemoryDC, hMaskBmp);
p = GetSquareXY(square);
BitBlt(hDC, p.x, p.y, Bitmap.bmWidth, Bitmap.bmHeight,
hMemoryDC, 0, 0, SRCAND);
SelectObject(hMemoryDC, hBitmap);
BitBlt(hDC, p.x, p.y, Bitmap.bmWidth, Bitmap.bmHeight,
hMemoryDC, 0, 0, Rop);
SelectObject(hMemoryDC, hOldBmp);
DeleteDC(hMemoryDC);
ReleaseDC(hWndMain, hDC);
}
void InitDisplay()
{
SQUARETYPE square;
for (square = 0; square <= 0x77; square++)
if (!(square & 0x88))
if ((Board[square].piece != Display[square].piece) ||
(Board[square].piece != empty) && (Board[square].color !=
Display[square].color))
{
Display[square].piece = Board[square].piece;
Display[square].color = Board[square].color;
}
}
/*
* Draw a box in the square of an attacked piece.
* Square is black if Defended is TRUE, else it is red.
*/
static void FrameSquare(SQUARETYPE square, BOOL Defended)
{
POINT p;
HPEN hOldPen;
HBRUSH hOldBrush;
HDC hDC;
hDC = GetDC(hWndMain);
p = GetSquareXY(square);
hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH));
if (Defended)
hOldPen = (HPEN)SelectObject(hDC, GetStockObject(BLACK_PEN));
else
hOldPen = (HPEN)SelectObject(hDC, CreatePen(PS_SOLID,1,RGB(192, 0, 0)));
Rectangle(hDC, p.x+1, p.y+1, p.x+SQUARE_SIZE-1, p.y+SQUARE_SIZE-1);
SelectObject(hDC, hOldBrush);
if (Defended)
SelectObject(hDC, hOldPen);
else
DeleteObject(SelectObject(hDC, hOldPen));
ReleaseDC(hWndMain, hDC);
}
void HideAttacks(void)
{
SQUARETYPE square;
for (square = 0; square <= 0x77; square++)
if (!(square & 0x88))
{
if (Board[square].attacked == TRUE)
{
Board[square].attacked = FALSE;
ClearSquare(square);
PrintPiece(square, Board[square].piece,
Board[square].color, SRCINVERT);
}
}
}
void ShowAttacks()
{
SQUARETYPE square;
for (square = 0; square <= 0x77; square++)
if (!(square & 0x88))
{
if (Attacks(ComputerColor, square) && Board[square].color != ComputerColor && Board[square].piece != empty)
{
Board[square].attacked = TRUE;
if (Attacks((COLORTYPE)!ComputerColor, square))
FrameSquare(square, TRUE);
else
FrameSquare(square, FALSE);
}
else if (Board[square].attacked == TRUE)
{
Board[square].attacked = FALSE;
ClearSquare(square);
PrintPiece(square, Board[square].piece,
Board[square].color, SRCINVERT);
}
}
}
void UpdateBoard()
{
SQUARETYPE square;
for (square = 0; square <= 0x77; square++)
if (!(square & 0x88))
if ((Board[square].piece != Display[square].piece) ||
(Board[square].piece != empty) && (Board[square].color !=
Display[square].color))
{
if (Display[square].piece != empty)
ClearSquare(square);
Display[square].piece = Board[square].piece;
Display[square].color = Board[square].color;
if (Board[square].piece != empty)
PrintPiece(square, Board[square].piece,
Board[square].color, SRCINVERT);
}
if (Level == easygame && !Editing)
ShowAttacks();
}
static void DrawAlphaNum();
void PrintBoard()
{
SQUARETYPE square;
DrawBoard();
for (square = 0; square <= 0x77; square++)
if (!(square & 0x88))
{
if (Display[square].piece != empty)
PrintPiece(square, Display[square].piece,
Display[square].color, SRCINVERT);
}
DrawAlphaNum();
if (Level == easygame && !Editing)
ShowAttacks();
}
/*
* find a square with a given point and determine whether it
* contains a player of the given color
*/
SQUARETYPE GetValidSquare(POINT p, COLORTYPE player, BOOL CheckPiece)
{
POINT point;
SQUARETYPE square;
RECT sqrect;
for (square = 0; square <= 0x77; square++)
{
if (!(square & 0x88))
{
point = GetSquareXY(square);
sqrect.left = point.x;
sqrect.top = point.y;
sqrect.right = sqrect.left + SQUARE_SIZE;
sqrect.bottom = sqrect.top + SQUARE_SIZE;
if (PtInRect(&sqrect, p))
{
if ((Display[square].color == player && Display[square].piece
!= empty) || !CheckPiece)
return square;
}
}
}
return -1;
}
void DrawNormalBitmap(SQUARETYPE square)
{
ClearSquare(square);
PrintPiece(square, Display[square].piece, Display[square].color, SRCINVERT);
}
void DrawInvertedBitmap(SQUARETYPE square)
{
PrintPiece(square, Display[square].piece, Display[square].color, NOTSRCERASE);
}
void OpeningLibMsg()
{
TInfo->SetMessageText("Using opening library");
}
void PrintNodes(NODEVAL *nodes, double time)
{
double nodereal;
char buf[80];
nodereal = (nodes->nodebase * MAXINT) + nodes->nodeoffset;
if (time)
{
sprintf(buf, "%7.1f", nodereal/time);
TInfo->SetSecondsText(buf);
}
sprintf(buf, "%7.0f ", nodereal);
TInfo->SetNodeText(buf);
}
/*
* Print bestline on screen
*/
void PrintBestMove(MOVETYPE *mainline, MAXTYPE mainevalu)
{
DEPTHTYPE dep = 0;
*buf = 0;
if (ShowBestLine == FALSE)
return;
while (dep < 7 && (mainline[dep].movpiece != empty))
{
strcat(buf, MoveStr(&mainline[dep++]));
strcat(buf, " ");
}
TInfo->SetBestLineText(buf);
sprintf(buf, "%7.2f", mainevalu /256.0);
TInfo->SetValueText(buf);
}
void ClearBestLine()
{
TInfo->SetBestLineText("");
}
void ClearMessage()
{
TInfo->SetMessageText("");
}
static char * CharArray[] = { "a","b", "c", "d", "e", "f", "g", "h" };
static char * NumArray[] = { "1", "2", "3", "4", "5", "6", "7", "8" };
static void DrawBump(HDC hDC, int x, int y)
{
int x2, y2;
HPEN hOldPen;
HBRUSH hOldBrush;
POINT pArray[3];
x2 = x + CHARSIZE + 2;
y2 = y-- + LINESIZE + 1;
x-=2;
hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
hOldPen = (HPEN)SelectObject(hDC, GetStockObject(WHITE_PEN));
Rectangle(hDC, x, y, x2, y2);
SelectObject(hDC, CreatePen(PS_SOLID, 1, RGB(128, 128, 128)));
pArray[0].x = ++x;
pArray[1].y = pArray[0].y = y2;
pArray[2].x = pArray[1].x = x2;
pArray[2].y = ++y;
Polyline(hDC, pArray, 3);
SelectObject(hDC, hOldBrush);
DeleteObject(SelectObject(hDC, hOldPen));
}
static void DrawAlphaNum()
{
int i;
int XPos, YPos;
HDC hDC;
hDC = GetDC(hWndMain);
XPos = (BORDERSIZE + MYFRAMESIZE)/2 - CHARSIZE/2;
YPos = (BORDERSIZE + SQUARE_SIZE/2) - LINESIZE / 2;
SetBkColor(hDC, RGB(192, 192, 192));
for (i = 7; i >= 0; i--)
{
DrawBump(hDC, XPos, YPos);
if (Turned)
{
TextOut(hDC, XPos, YPos, NumArray[7-i], 1);
}
else
TextOut(hDC, XPos, YPos, NumArray[i], 1);
YPos += SQUARE_SIZE;
}
XPos = BORDERSIZE + SQUARE_SIZE / 2 - CHARSIZE/2;
YPos = BORDERSIZE + (8 * SQUARE_SIZE) + (2 * MYFRAMESIZE) + 1;
for (i = 0; i < 8; i++)
{
DrawBump(hDC, XPos, YPos);
if (Turned)
TextOut(hDC, XPos, YPos, CharArray[7-i], 1);
else
TextOut(hDC, XPos, YPos, CharArray[i], 1);
XPos += SQUARE_SIZE;
}
ReleaseDC(hWndMain, hDC);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -