home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 3.ddi / CHESS.ZIP / INFO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  7.9 KB  |  267 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. #include <owl.h>
  4. #include <static.h>
  5. #include "wcdefs.h"
  6. #include "info.h"
  7. #include "externs.h"
  8.  
  9. short LEFTMARGIN = 6;
  10. short SEPERATOR = 4;
  11. #define MAXLINE    (INFOXSIZE - LEFTMARGIN -1)
  12.  
  13. #define COLORX     (LEFTMARGIN + CHARSIZE * 6)
  14. #define COLORY     (SEPERATOR + MYFRAMESIZE)
  15. #define COLORW     (CHARSIZE * 6)
  16. #define TIMERX    (LEFTMARGIN + CHARSIZE * 6)
  17. #define TIMERY    (COLORY + LINESIZE + SEPERATOR)
  18. #define TIMERW    (MAXLINE - TIMERX)
  19. #define WHITEINFOX    (LEFTMARGIN + CHARSIZE * 7)
  20. #define WHITEINFOY    (TIMERY + LINESIZE + SEPERATOR * 2)
  21. #define WHITEINFOW    (MAXLINE - WHITEINFOX)
  22. #define BLACKINFOX    (WHITEINFOX)
  23. #define BLACKINFOY    (WHITEINFOY + LINESIZE + SEPERATOR)
  24. #define BLACKINFOW    (WHITEINFOW)
  25. #define LEVELX    (LEFTMARGIN + CHARSIZE * 7)
  26. #define LEVELY    (BLACKINFOY + LINESIZE + SEPERATOR)
  27. #define LEVELW    (MAXLINE - LEVELX)
  28. #define VALUEX    (LEFTMARGIN + CHARSIZE * 7)
  29. #define VALUEY    (LEVELY + LINESIZE + SEPERATOR * 2)
  30. #define VALUEW    (MAXLINE - VALUEX)
  31. #define NODEX     (LEFTMARGIN + CHARSIZE * 8)
  32. #define NODEY     (VALUEY + LINESIZE + SEPERATOR)
  33. #define NODEW     (MAXLINE - NODEX)
  34. #define SECX      (LEFTMARGIN + CHARSIZE * 7)
  35. #define SECY      (NODEY + LINESIZE + SEPERATOR)
  36. #define SECW      (MAXLINE - SECX)
  37. #define DEPTHY    (SECY + LINESIZE + SEPERATOR)
  38. #define DEPTHX    (LEFTMARGIN + CHARSIZE * 7)
  39. #define DEPTHW    (MAXLINE - DEPTHX)
  40. #define STATBESTY (DEPTHY + LINESIZE + SEPERATOR * 2)
  41. #define BESTX     (LEFTMARGIN)
  42. #define BESTY     (STATBESTY + LINESIZE + 1)
  43. #define BESTW     (MAXLINE - LEFTMARGIN)
  44. #define BESTH     (LINESIZE * 3 + SEPERATOR * 3 - 9)
  45. #define MESSX     (LEFTMARGIN)
  46. #define MESSY     (BESTY + BESTH + SEPERATOR * 2)
  47. #define MESSW     (MAXLINE - MESSX)
  48.  
  49.  
  50. #define EmptyStr  ""
  51.  
  52.  
  53. //--------------- TNoEraseBkGndStatic methods -------------------
  54.  
  55. void TNoEraseBkGndStatic::WMEraseBkGnd(RTMessage msg)
  56. {
  57.    if (DoErase)
  58.       {
  59.       HDC hDC = HDC( msg.WParam );
  60.       RECT Rect;
  61.       HBRUSH hOldBrush;
  62.       hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
  63.       GetClientRect(HWindow, &Rect);
  64.       PatBlt(hDC, Rect.left, Rect.top, Rect.right - Rect.left,
  65.          Rect.bottom - Rect.top, PATCOPY);
  66.       SelectObject(hDC, hOldBrush);
  67.       DoErase = FALSE;
  68.       msg.Result = 1;
  69.       }
  70.    else
  71.       msg.Result = 0;
  72. }
  73.  
  74. //---------------- TInfoWindow Methods -------------------------
  75.  
  76. TInfoWindow::TInfoWindow(PTWindowsObject AParent, LPSTR ATitle) :
  77.     TWindow(AParent, ATitle)
  78. {
  79.    short temp;
  80.    
  81.    Attr.Style |= WS_CHILD | WS_VISIBLE;
  82.     Attr.X = (3 * BORDERSIZE) + (MAXBDSIZE * SQUARE_SIZE) + (2 * MYFRAMESIZE);
  83.     Attr.Y = BORDERSIZE;
  84.    LEFTMARGIN= MYFRAMESIZE + CHARSIZE/2;
  85.    SEPERATOR = LINESIZE/4;
  86.    INFOXSIZE = (28 * CHARSIZE) + (2 * LEFTMARGIN);
  87.    INFOYSIZE = MESSY + LINESIZE + SEPERATOR + MYFRAMESIZE;
  88.    temp = MAXBDSIZE * SQUARE_SIZE + (2 * MYFRAMESIZE);
  89.    INFOYSIZE = (temp > INFOYSIZE) ? temp : INFOYSIZE;
  90.     InfoRect.right = Attr.W = INFOXSIZE;
  91.     InfoRect.bottom = Attr.H = INFOYSIZE;
  92.     InfoRect.left = InfoRect.top =  0;
  93.     new TStatic(this, -1, " Turn:", LEFTMARGIN, COLORY,
  94.         CHARSIZE * 6, LINESIZE, 5);
  95.     new TStatic(this, -1, " White:", LEFTMARGIN, WHITEINFOY,
  96.         CHARSIZE * 7, LINESIZE, 4);
  97.     new TStatic(this, -1, " Black:", LEFTMARGIN, BLACKINFOY,
  98.         CHARSIZE * 7, LINESIZE, 6);
  99.     new TStatic(this, -1, " Time:", LEFTMARGIN, TIMERY,
  100.         CHARSIZE * 6, LINESIZE, 5);
  101.     new TStatic(this, -1, " Level:", LEFTMARGIN, LEVELY,
  102.         CHARSIZE * 13, LINESIZE, 12);
  103.     new TStatic(this, -1, " Value:", LEFTMARGIN, VALUEY,
  104.         CHARSIZE * 7, LINESIZE, 6);
  105.     new TStatic(this, -1, " Nodes:", LEFTMARGIN, NODEY,
  106.         CHARSIZE * 8, LINESIZE, 7);
  107.     new TStatic(this, -1, " N/Sec:", LEFTMARGIN, SECY,
  108.         CHARSIZE * 9, LINESIZE, 9);
  109.    new TStatic(this, -1, " Depth:", LEFTMARGIN, DEPTHY,
  110.       CHARSIZE * 7, LINESIZE, 6);
  111.     new TStatic(this, -1, " Bestline:", LEFTMARGIN-2, STATBESTY,
  112.         MAXLINE - 2, LINESIZE, 9);
  113.     Color = new TStatic(this, -1, EmptyStr, COLORX, COLORY,
  114.         COLORW, LINESIZE, 6);
  115.     WhiteInfo = new TStatic(this, -1, EmptyStr, WHITEINFOX, WHITEINFOY,
  116.         WHITEINFOW, LINESIZE, WHITEINFOW/CHARSIZE);
  117.     BlackInfo = new TStatic(this, -1, EmptyStr, BLACKINFOX, BLACKINFOY,
  118.         BLACKINFOW, LINESIZE, BLACKINFOW / CHARSIZE);
  119.    Timer = new TNoEraseBkGndStatic(this, -1, EmptyStr, TIMERX, TIMERY,
  120.       TIMERW, LINESIZE, TIMERW /CHARSIZE);
  121.     Level = new TStatic(this, -1, EmptyStr, LEVELX, LEVELY,
  122.         LEVELW, LINESIZE, LEVELW / CHARSIZE);
  123.     Value = new TStatic(this, -1, EmptyStr, VALUEX, VALUEY,
  124.         VALUEW, LINESIZE, VALUEW / CHARSIZE);
  125.     Nodes = new TStatic(this, -1, EmptyStr, NODEX, NODEY,
  126.         NODEW, LINESIZE, NODEW / CHARSIZE);
  127.     Seconds = new TStatic(this, -1, EmptyStr, SECX, SECY,
  128.         SECW, LINESIZE, SECW / CHARSIZE);
  129.    Depth = new TNoEraseBkGndStatic(this, -1, EmptyStr, DEPTHX, DEPTHY,
  130.       DEPTHW, LINESIZE, DEPTHW /CHARSIZE);
  131.     BestLine = new TStatic(this, -1, EmptyStr, BESTX, BESTY,
  132.         BESTW, BESTH, ((BESTW / CHARSIZE) * 3));
  133.     Message = new TStatic(this, -1, EmptyStr, MESSX, MESSY,
  134.         MESSW, LINESIZE, MESSW / CHARSIZE);
  135. }
  136.  
  137. void TInfoWindow::Paint( HDC PaintDC, PAINTSTRUCT& )
  138. {
  139.     DrawInfoFrame(PaintDC);
  140.    DrawStaticFrames(PaintDC);
  141. }
  142.  
  143. void TInfoWindow::DrawInfoFrame(HDC hDC)
  144. {
  145.    DrawFrame(hDC, InfoRect);
  146. }
  147.  
  148. void TInfoWindow::WMControlColor(TMessage& Msg)
  149. {
  150.     SetBkColor( HDC(Msg.WParam), RGB(192, 192, 192));
  151.     Msg.Result = (long)GetStockObject(LTGRAY_BRUSH);
  152. }
  153.  
  154. void TInfoWindow::Reset()
  155. {
  156.    Color->SetText("White");
  157.    WhiteInfo->Clear();
  158.    BlackInfo->Clear();
  159.    Level->Clear();
  160.    Value->Clear();
  161.    Nodes->Clear();
  162.    Seconds->Clear();
  163.    BestLine->Clear();
  164.    Message->Clear();
  165. }
  166.  
  167. void TInfoWindow::IterReset()
  168. {
  169.    Color->SetText("White");
  170.    Value->Clear();
  171.    Nodes->Clear();
  172.    Seconds->Clear();
  173.    BestLine->Clear();
  174. }
  175.  
  176. void TInfoWindow::DrawSFrame(HDC hDC, RECT *rect)
  177. {
  178.    int x1, x2, y1, y2;
  179.    HPEN hPen, hOldPen;
  180.    HBRUSH hOldBrush;
  181.  
  182.    POINT pArray[3];
  183.  
  184.    x1 = rect->left;
  185.    x2 = rect->right;
  186.    y1 = rect->top;
  187.    y2 = rect->bottom;
  188.  
  189.    hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(LTGRAY_BRUSH));
  190.  
  191.    PatBlt(hDC, x1, y1, x2 - x1, y2 - y1, PATCOPY);
  192.    SelectObject(hDC, hOldBrush);
  193.  
  194.    hPen = CreatePen(PS_SOLID, 1, RGB(128, 128, 128));
  195.  
  196.    hOldPen = (HPEN)SelectObject(hDC, hPen);
  197.  
  198.    pArray[1].x = pArray[0].x = x1;
  199.    pArray[0].y = y2;
  200.    pArray[2].y = pArray[1].y = y1;
  201.    pArray[2].x = x2;
  202.  
  203.    Polyline(hDC, pArray, 3);
  204.  
  205.    DeleteObject(SelectObject(hDC, GetStockObject(WHITE_PEN)));
  206.  
  207.    pArray[1].x = x2;
  208.    pArray[1].y = y2;
  209.    pArray[2].y = y1 - 1;
  210.  
  211.    Polyline(hDC, pArray, 3);
  212.    SelectObject(hDC, hOldPen);
  213. }
  214.  
  215. void TInfoWindow::DrawStaticFrames(HDC hDC)
  216. {
  217.    RECT rect;
  218.  
  219.    rect.left = LEFTMARGIN - 1;
  220.    rect.right = MAXLINE + 1;
  221.  
  222.    rect.top = COLORY - 1;
  223.    rect.bottom = COLORY + LINESIZE + 1;
  224.    DrawSFrame(hDC, &rect);
  225.  
  226.    rect.top = WHITEINFOY - 1;
  227.    rect.bottom = WHITEINFOY + LINESIZE + 1;
  228.    DrawSFrame(hDC, &rect);
  229.  
  230.    rect.top = BLACKINFOY - 1;
  231.    rect.bottom = BLACKINFOY + LINESIZE + 1;
  232.    DrawSFrame(hDC, &rect);
  233.  
  234.    rect.top = TIMERY - 1;
  235.    rect.bottom = TIMERY + LINESIZE + 1;
  236.    DrawSFrame(hDC, &rect);
  237.  
  238.    rect.top = LEVELY - 1;
  239.    rect.bottom = LEVELY + LINESIZE + 1;
  240.    DrawSFrame(hDC, &rect);
  241.  
  242.    rect.top = VALUEY - 1;
  243.    rect.bottom = VALUEY + LINESIZE + 1;
  244.    DrawSFrame(hDC, &rect);
  245.  
  246.    rect.top = NODEY - 1;
  247.    rect.bottom = NODEY + LINESIZE + 1;
  248.    DrawSFrame(hDC, &rect);
  249.  
  250.    rect.top = SECY - 1;
  251.    rect.bottom = SECY + LINESIZE + 1;
  252.    DrawSFrame(hDC, &rect);
  253.  
  254.    rect.top = DEPTHY - 1;
  255.    rect.bottom = DEPTHY + LINESIZE + 1;
  256.    DrawSFrame(hDC, &rect);
  257.  
  258.    rect.top = BESTY - 1;
  259.    rect.bottom = BESTY + BESTH + 1;
  260.    DrawSFrame(hDC, &rect);
  261.  
  262.    rect.top = MESSY - 1;
  263.    rect.bottom = MESSY + LINESIZE + 1;
  264.    DrawSFrame(hDC, &rect);
  265. }
  266.  
  267.