⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 display.cpp

📁 将UCOS与UCGUI整合到一起,并在BORLAND C++上运行通过的源程序.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ObjectWindows - (C) Copyright 1992 by Borland International

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <static.h>
#include <filedial.h>
#include <inputdia.h>
#include <bwcc.h>

#include "wcdefs.h"
#include "wchess.h"
#include "info.h"
#include "externs.h"


/*
 *  Global variables
 */

BOARDIDTYPE Display[0x78];
char *PieceLetter = " KQRBNP";
char buf[280];   //  general string buffer, used in several modules

/*
 *  static global variables
 */

static RECT BoardRect;


/*
 *  get handle to bitmap of current piece
 */

HBITMAP GetBitmapHandle(PIECETYPE piece, COLORTYPE pcolor)
{
   if (piece == 0)
      return 0;
   return PieceBmpArray[piece - 1][pcolor];
}


/*
 *  Clear all information from Info window
 */

void ClearInfoWindow()
{
   TInfo->Reset();
}

/*
 *  Prints current color to play
 */

void ColorToPlay(COLORTYPE color)
{
   if (color == white)
      TInfo->SetTurnText("White");
   else
      TInfo->SetTurnText("Black");
}

void Message(char *str)
{
   TInfo->SetMessageText(str);
}

void Error(char *str)
{
   if (SoundOn)
      MessageBeep(0);
   strcpy(buf, str);
   SendMessage(hWndMain, WM_COMMAND, EM_ERROR, 0L);
}

void Warning(char *str)
{
   if (SoundOn)
      MessageBeep(0);
   Message(str);
}


/*
 *  convert a move to a string
 */

char *MoveStr(MOVETYPE *move)
{
    static char str[7];

    strcpy(str, "      ");
    if (move->movpiece != empty)
    {
        if (move->spe && move->movpiece == king)  /*  castling  */
        {
            if (move->new1 > move->old) strcpy(str, "O-O   ");
            else strcpy(str, "O-O-O ");
        }
        else
        {
            str[0] = PieceLetter[move->movpiece];
            str[1] = 'a' + move->old % 16;
            str[2] = '1' + move->old / 16;
            if (move->content == empty)
                str[3] = '-';
            else
                str[3] = 'x';
            str[4] = 'a' + move->new1 % 16;
            str[5] = '1' + move->new1 / 16;
        }
    }
    return (str);
}


void PrintMove(int moveno, COLORTYPE programcolor, MOVETYPE *move, double time)
{
   int minutes;
   minutes = (int)(time / 60.0);

   sprintf(buf, "%2.2d:%#04.1f %3.3d. %s", minutes, time - minutes * 60.0, moveno / 2 + 1, MoveStr(move));
   if (programcolor == white)
      TInfo->SetWhiteInfoText(buf);
   else
      TInfo->SetBlackInfoText(buf);
}


/*
 *  draw 3d type frame
 */

void DrawFrame(HDC hDC, RECT& BoardRect, BOOL DrawBackground)
{
    int x1, y1, x2, y2;
    POINT pArray[3];
    HPEN hPen, hOldPen;
    HBRUSH hOldBrush;
     
    x1 = BoardRect.left;
    x2 = BoardRect.right;
    y1 = BoardRect.top;
    y2 = BoardRect.bottom;
    if (DrawBackground == FALSE)
      hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH));
    else
      hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
   
    hOldPen = (HPEN)SelectObject(hDC, GetStockObject(WHITE_PEN));

    Rectangle(hDC, x1, y1, x2, y2);
    SelectObject(hDC, hPen = CreatePen(PS_SOLID, 1, RGB(192, 192, 192)));
    Rectangle(hDC, x1+1, y1+1, x2-1, y2-1);
    DeleteObject(SelectObject(hDC, GetStockObject(WHITE_PEN)));

    pArray[0].x = x1 + 2;
    pArray[1].y = pArray[0].y = y2 - 3;
    pArray[2].x = pArray[1].x = x2 - 3;
    pArray[2].y = y1 + 2;

    Polyline(hDC, pArray, 3);
    hPen = CreatePen(PS_SOLID, 1, RGB(128, 128, 128));
    SelectObject(hDC, hPen);
    pArray[0].x = x1;
    pArray[1].y = pArray[0].y = y2-1;
    pArray[2].x = pArray[1].x = x2-1;
    pArray[2].y = y1;

    Polyline(hDC, pArray, 3);
    pArray[1].x = pArray[0].x = x1 + 2;
    pArray[0].y = y2 - 3;
    pArray[2].y = pArray[1].y = y1 + 2;
    pArray[2].x = x2 - 3;
    Polyline(hDC, pArray, 3);
    SelectObject(hDC, hOldBrush);
    DeleteObject(SelectObject(hDC, hOldPen));
}


/*
 *  Display the current level indicator
 */

void PrintCurLevel()
{
   extern BOOL MultiMove;

   if (MultiMove)
      strcpy(buf, "Two Player");
   else
      {
      switch (Level)
         {
         case normal:
            sprintf(buf, "%1.0f sec / move", AverageTime);
            break;
         case fullgametime:
            sprintf(buf, "%2.2f min / game", AverageTime);
            break;
         case easygame:
            strcpy(buf, "Easy");
            break;
         case infinite :
            strcpy(buf, "Infinte");
            break;
         case plysearch :
            sprintf(buf, "Ply-Depth = %d", MaxLevel);
            break;
         case matesearch:
            strcpy(buf, "MateSearch");
            break;
         case matching :
            strcpy(buf, "Match users time");
            break;
         }
      }
   TInfo->SetLevelText(buf);
}

POINT GetSquareXY(SQUARETYPE square)
{
   POINT p;

   if (Turned)
      square ^= 0x77;
   p.x = (square % 8) * SQUARE_SIZE + BORDERSIZE + MYFRAMESIZE;
   p.y = (7 - square / 16) * SQUARE_SIZE + BORDERSIZE + MYFRAMESIZE;
   return p;
}

void ClearSquare(SQUARETYPE square)
{
   HANDLE hOldBrush;
   POINT p;
   HDC hDC;

   p = GetSquareXY(square);
   
   hDC = GetDC(hWndMain);
   if ((square % 8 + square /16) % 2 == 1)
      hOldBrush = SelectObject(hDC, hWhiteBrush);
   else
      hOldBrush = SelectObject(hDC, hBlackBrush);
   PatBlt(hDC, p.x, p.y, SQUARE_SIZE, SQUARE_SIZE, PATCOPY);
   SelectObject(hDC, hOldBrush);
   ReleaseDC(hWndMain, hDC);
}

void ClearDisplay()
{
   SQUARETYPE sq;
   ClearInfoWindow();
   for (sq = 0; sq <= 0x77; sq++)
      Display[sq].piece = empty;
}


/*
 *  Draw the board on the screen
 */

void DrawBoard()
{
   unsigned char no;
   HDC hDC;
   const SQUARETYPE printno[64] = { 0, 0x10, 0x20, 0x30, 0x40, 0x50,
                                        0x60, 0x70, 0x71, 0x72, 0x73,
                                        0x74, 0x75, 0x76, 0x77, 0x67,
                                        0x57, 0x47, 0x37, 0x27, 0x17,
                                           7,    6,    5,    4,    3,
                                           2,    1, 0x11, 0x21, 0x31,
                                         0x41, 0x51, 0x61, 0x62, 0x63,
                                        0x64, 0x65, 0x66, 0x56, 0x46,
                                        0x36, 0x26, 0x16, 0x15, 0x14,
                                        0x13, 0x12, 0x22, 0x32, 0x42,
                                        0x52, 0x53, 0x54, 0x55, 0x45,
                                        0x35, 0x25, 0x24, 0x23, 0x33,
                                        0x43, 0x44, 0x34};

   
   BoardRect.left = BoardRect.top = BORDERSIZE;
   BoardRect.right = BoardRect.bottom = BORDERSIZE + (2 * MYFRAMESIZE) +
      (8 * SQUARE_SIZE);
   hDC = GetDC(hWndMain);
   DrawFrame(hDC, BoardRect);
   ReleaseDC(hWndMain, hDC);
   for (no = 0; no < 64; no++)
      ClearSquare(printno[no]);
}

                                                                       
void PrintPiece(SQUARETYPE square, PIECETYPE piece, COLORTYPE color, DWORD Rop)
{
   HBITMAP hBitmap, hOldBmp, hMaskBmp;
   BITMAP Bitmap;
   HDC hMemoryDC, hDC;
   POINT p;

   if (piece == empty)
      return;

   hBitmap = PieceBmpArray[piece-1][color];
   hMaskBmp = MaskArray[piece-1];

   hDC = GetDC(hWndMain);
   hMemoryDC = CreateCompatibleDC(hDC);
   GetObject(hBitmap, sizeof(BITMAP), (LPSTR) &Bitmap);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -