home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l040 / 10.ddi / CHESS.ZIP / OWCHDLGS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-27  |  26.5 KB  |  892 lines

  1. {************************************************}
  2. {                                                }
  3. {   ObjectWindows Chess Demo                     }
  4. {   Dialogs unit                                 }
  5. {   Copyright (c) 1992 by Borland International  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. unit OWCHDlgs;
  10.  
  11. interface
  12.  
  13. uses WinProcs, WinTypes, OWindows, ODialogs, Validate, ChessDLL, OWConst;
  14.  
  15. const
  16.   AM_InfoUpdate = wm_User + 502;
  17.  
  18. type
  19.  
  20.   PMoveListbox = ^TMoveListbox;
  21.   TMoveListbox = object(TListbox)
  22.     procedure SetupWindow; virtual;
  23.     procedure AddMove(Turn: Integer; White, Black: PChar);
  24.     procedure DeleteRest(Turn: Integer);
  25.     procedure AMInfoUpdate(var Msg: TMessage);
  26.       virtual wm_First + am_InfoUpdate;
  27.   end;
  28.  
  29.   PChessInfoWindow = ^TChessInfoWindow;
  30.   TChessInfoWindow = object(TDlgWindow)
  31.     Msg: PStatic;
  32.     MoveListBox: PMoveListBox;
  33.     UpdateSearchInfo: Boolean;
  34.     constructor Init(AParent: PWindowsObject; AName: PChar);
  35.     function GetClassName: PChar; virtual;
  36.     procedure GetWindowClass(var WC: TWndClass); virtual;
  37.     procedure EnableSearchInfoUpdates(EnableUpdates: Boolean);
  38.     procedure ZeroNodes;
  39.     procedure Update(Game: HChess; WhiteTime, BlackTime,
  40.                      LastInterval: Longint;
  41.                      MoveNum: Integer; GameMode: Word);
  42.   end;
  43.  
  44.   PSettingsXferRec = ^TSettingsXferRec;
  45.   TSettingsXferRec = record
  46.     LimitGame,
  47.     LimitTurn,
  48.     MatchUser,
  49.     NoLimit:  WordBool;
  50.     GameTime,
  51.     TurnTime: Longint;
  52.     ShowAttacks,
  53.     ShowJeopardies,
  54.     ShowBestLine,
  55.     RightClickHints,
  56.     OnePlayer,
  57.     TwoPlayer: WordBool;
  58.     ThinkTime: TScrollBarTransferRec;
  59.     AllowThinkAhead,
  60.     CoverBoard: WordBool;
  61.     { The following are not used by the dialog, but are used by the program.
  62.       Keep them at the bottom of this record }
  63.     RefreshRate: Word;
  64.   end;
  65.  
  66.   PSettingsDlg = ^TSettingsDlg;
  67.   TSettingsDlg = object(TDialog)
  68.     constructor Init(AParent: PWindowsObject; AName: PChar;
  69.                      var XferBuf: TSettingsXferRec);
  70.     procedure SetupWindow; virtual;
  71.     procedure EnableSet(Game, Turn: Boolean);
  72.     procedure ShowSet(Game, Turn: Boolean);
  73.     procedure LimitGameTime(var Msg: TMessage);
  74.       virtual id_First + idLimitGameTime;
  75.     procedure LimitTurnTime(var Msg: TMessage);
  76.       virtual id_First + idLimitTurnTime;
  77.     procedure MatchUserTime(var Msg: TMessage);
  78.       virtual id_First + idMatchUserTime;
  79.     procedure NoTimeLimit(var Msg: TMessage);
  80.       virtual id_First + idNoTimeLimit;
  81.   end;
  82.  
  83.   PCoverDlg = ^TCoverDlg;
  84.   TCoverDlg = object(TDlgWindow)
  85.     Locked: Bool;
  86.     constructor Init(AParent: PWindowsObject; AResName: PChar);
  87.     procedure Lock;
  88.     procedure Unlock;
  89.     procedure Show(ShowCmd: Integer); virtual;
  90.     procedure WMSize(var Msg: TMessage);
  91.       virtual wm_First + wm_Size;
  92.   end;
  93.  
  94.   PRelocatingDlg = ^TRelocatingDlg;
  95.   TRelocatingDlg = object(TDialog)
  96.     procedure SetupWindow; virtual;
  97.   end;
  98.  
  99.   PChoosePawnPromoteDlg = ^TChoosePawnPromoteDlg;
  100.   TChoosePawnPromoteDlg = object(TRelocatingDlg)
  101.     Buffer: array [0..3] of WordBool;  { 4 radio buttons }
  102.     Change: PChange;
  103.     constructor Init(AParent: PWindowsObject;
  104.                      AResName: PChar; AChange: PChange);
  105.     procedure TransferData(Direction: Word); virtual;
  106.   end;
  107.  
  108.   PEnterMoveDlg = ^TEnterMoveDlg;
  109.   TEnterMoveDlg = object(TRelocatingDlg)
  110.     constructor Init(AParent: PWindowsObject;
  111.                      AResName: PChar;
  112.                      AMoveStr: PChar);
  113.   end;
  114.  
  115. var
  116.   ChessSettings: TSettingsXferRec;
  117.  
  118. procedure LoadINISettings;
  119. procedure SaveINISettings;
  120.  
  121. implementation
  122.  
  123. uses OWUtils, Strings, CTimers;
  124.  
  125.   { The LockWindowUpdate function will eliminate all flicker caused by
  126.     switching between the two edit controls set up in the Settings dialog.
  127.     This function is only available in Windows 3.1, though, so in order
  128.     to allow this program to run (with some flicker) in Windows 3.0,
  129.     this program should:
  130.  
  131.       1) Never call LockWindowUpdate when running under Windows 3.0
  132.       2) Avoid using static declarations (like Win31.pas) to import
  133.          the function, since Windows 3.0 won't load an app if the app
  134.          contains static references to DLL functions Windows 3.0
  135.          doesn't have.
  136.  
  137.     The following code uses a function variable and GetProcAddress to
  138.     request the address of the LockWindowUpdate function.  Windows 3.0
  139.     will return a nil function address if you ask for a function that
  140.     doesn't exist in the indicated DLL.  Before each use of the
  141.     function variable, test it for nil using the Assigned function.
  142.   }
  143.  
  144. type
  145.   Win31LockWindowUpdateFunc = function (Wnd: HWnd): Bool;
  146.  
  147. const
  148.   Win31LockWindowUpdate: Win31LockWindowUpdateFunc = nil;
  149.  
  150. type
  151.   PUpdateRec = ^TUpdateRec;
  152.   TUpdateRec = record
  153.     Time : array [cWhite..cBlack] of Longint;
  154.     MoveNum : Integer;
  155.     GameMode: Word;
  156.     Nodes: Longint;
  157.     LastInterval: Longint;
  158.     UpdateSearchInfo: Boolean;
  159.   end;
  160.  
  161.   TColoredStatic = object(TWindow)
  162.     Color: TColor;
  163.     constructor InitResource(AParent: PWindowsObject; ResID: Integer;
  164.                              AColor: TColor);
  165.     procedure Paint(DC: HDC; var PS: TPaintStruct); virtual;
  166.     procedure OutputText(DC: HDC; var PS: TPaintStruct); virtual;
  167.   end;
  168.  
  169.   PTurnDisplay = ^TTurnDisplay;
  170.   TTurnDisplay = object(TColoredStatic)
  171.     Tag: array [cWhite..cBlack] of PChar;
  172.     TurnNum: Integer;
  173.     constructor InitResource(AParent: PWindowsObject; ResID: Integer);
  174.     destructor Done; virtual;
  175.     procedure OutputText(DC: HDC; var PS: TPaintStruct); virtual;
  176.     procedure AMInfoUpdate(var Msg: TMessage);
  177.       virtual wm_First + am_InfoUpdate;
  178.   end;
  179.  
  180.   PTimeDisplay = ^TTimeDisplay;
  181.   TTimeDisplay = object(TColoredStatic)
  182.     CurrentTime: array [0..20] of Char;
  183.     constructor InitResource(AParent: PWindowsObject; ResID: Integer;
  184.                              AColor: TColor);
  185.     procedure OutputText(DC: HDC; var PS: TPaintStruct); virtual;
  186.     procedure AMInfoUpdate(var Msg: TMessage);
  187.       virtual wm_First + am_InfoUpdate;
  188.   end;
  189.  
  190.   PGameTimeDisplay = ^TGameTimeDisplay;
  191.   TGameTimeDisplay = object(TStatic)
  192.     CurrentTime: array [0..20] of Char;
  193.     constructor InitResource(AParent: PWindowsObject; ResID: Integer);
  194.     procedure AMInfoUpdate(var Msg: TMessage);
  195.       virtual wm_First + am_InfoUpdate;
  196.   end;
  197.  
  198.   PBestLine = ^TBestLine;
  199.   TBestLine = object(TStatic)
  200.     CurrentLine: array [0..100] of Char;
  201.     constructor InitResource(AParent: PWindowsObject; ResID: Integer);
  202.     procedure AMInfoUpdate(var Msg: TMessage);
  203.       virtual wm_First + am_InfoUpdate;
  204.   end;
  205.  
  206.   PValueLine = ^TValueLine;
  207.   TValueLine = object(TStatic)
  208.     CurrentValue: Integer;
  209.     constructor InitResource(AParent: PWindowsObject; ResID: Integer);
  210.     procedure AMInfoUpdate(var Msg: TMessage);
  211.       virtual wm_First + am_InfoUpdate;
  212.   end;
  213.  
  214.   PModeDisplay = ^TModeDisplay;
  215.   TModeDisplay = object(TStatic)
  216.     CurrentMode: Word;
  217.     constructor InitResource(AParent: PWindowsObject; ResID: Integer);
  218.     procedure AMInfoUpdate(var Msg: TMessage);
  219.       virtual wm_First + am_InfoUpdate;
  220.   end;
  221.  
  222.   PNodeDisplay = ^TNodeDisplay;
  223.   TNodeDisplay = object(TStatic)
  224.     NodeCount: Longint;
  225.     constructor InitResource(AParent: PWindowsObject; ResID: Integer);
  226.     procedure Zero;
  227.     procedure AMInfoUpdate(var Msg: TMessage);
  228.       virtual wm_First + am_InfoUpdate;
  229.   end;
  230.  
  231.   PNodesPerSecond = ^TNodesPerSecond;
  232.   TNodesPerSecond = object(TNodeDisplay)
  233.     procedure AMInfoUpdate(var Msg: TMessage);
  234.       virtual wm_First + am_InfoUpdate;
  235.   end;
  236.  
  237.  
  238. constructor TColoredStatic.InitResource(AParent: PWindowsObject;
  239.                                         ResID: Integer;
  240.                                         AColor: TColor);
  241. begin
  242.   inherited InitResource(AParent, ResID);
  243.   Color := AColor;
  244. end;
  245.  
  246. procedure TColoredStatic.Paint(DC: HDC; var PS: TPaintStruct);
  247. var
  248.   R: TRect;
  249. begin
  250.   SaveDC(DC);
  251.   GetClientRect(HWindow, R);
  252.   if Color = cBlack then
  253.   begin
  254.     SetTextColor(DC, RGB(255,255,255));
  255.     SetBkColor(DC, RGB(0,0,0));
  256.     PatBlt(DC, R.Left, R.Top, R.Right, R.Bottom, Blackness);
  257.   end
  258.   else
  259.   begin
  260.     SetTextColor(DC, RGB(0,0,0));
  261.     SetBkColor(DC, RGB(255,255,255));
  262.     PatBlt(DC, R.Left, R.Top, R.Right, R.Bottom, Whiteness);
  263.   end;
  264.   OutputText(DC, PS);
  265.   RestoreDC(DC, -1);
  266. end;
  267.  
  268. procedure TColoredStatic.OutputText(DC: HDC; var PS: TPaintStruct);
  269. begin
  270. end;
  271.  
  272. constructor TTurnDisplay.InitResource(AParent: PWindowsObject;
  273.                                       ResID: Integer);
  274. begin
  275.   inherited InitResource(AParent, ResID, cWhite);
  276.   TurnNum := 0;
  277.   Tag[cWhite] := StrNewRes(strWhite);
  278.   Tag[cBlack] := StrNewRes(strBlack);
  279. end;
  280.  
  281. destructor TTurnDisplay.Done;
  282. begin
  283.   StrDispose(Tag[cWhite]);
  284.   StrDispose(Tag[cBlack]);
  285.   inherited Done;
  286. end;
  287.  
  288. procedure TTurnDisplay.OutputText(DC: HDC; var PS: TPaintStruct);
  289. var
  290.   R: TRect;
  291.   TE1, TE2: Word;
  292.   TempStr: array [0..7] of Char;
  293. begin
  294.   GetClientRect(HWindow, R);
  295.   TempStr[0] := #0;
  296.   Str(TurnNum, TempStr);
  297.   TextOut(DC, 3, 0, TempStr, StrLen(TempStr));
  298.   TE1 := 3 + LoWord(GetTextExtent(DC, TempStr, StrLen(TempStr)));
  299.   TE2 := LoWord(GetTextExtent(DC, Tag[Color], StrLen(Tag[Color])));
  300.   TextOut(DC, TE1 + ((R.Right - TE1) div 2) - (TE2 div 2), 0,
  301.                  Tag[Color], StrLen(Tag[Color]));
  302. end;
  303.  
  304. procedure TTurnDisplay.AMInfoUpdate(var Msg: TMessage);
  305. begin
  306.   if Msg.WParam = 0 then  { Game reset }
  307.   begin
  308.     TurnNum := 0;
  309.     Color := cWhite;
  310.     InvalidateRect(HWindow, nil, False);
  311.   end
  312.   else
  313.   if (GetPlayer(HChess(Msg.WParam)) <> Color) or
  314.      (TurnNum <> PUpdateRec(Msg.LParam)^.MoveNum) then
  315.   begin
  316.     Color := GetPlayer(HChess(Msg.WParam));
  317.     TurnNum := PUpdateRec(Msg.LParam)^.MoveNum;
  318.     InvalidateRect(HWindow,nil,False);
  319.   end;
  320. end;
  321.  
  322. constructor TTimeDisplay.InitResource(AParent: PWindowsObject;
  323.                                       ResID: Integer;
  324.                                       AColor: TColor);
  325. begin
  326.   inherited InitResource(AParent, ResID, AColor);
  327.   CurrentTime[0] := #0;
  328. end;
  329.  
  330. procedure TTimeDisplay.OutputText(DC: HDC; var PS: TPaintStruct);
  331. var
  332.   R: TRect;
  333. begin
  334.   SetTextAlign(DC, ta_Center);
  335.   GetClientRect(HWindow, R);
  336.   TextOut(DC, R.Right div 2, 0, CurrentTime, StrLen(CurrentTime));
  337. end;
  338.  
  339.  
  340. procedure TTimeDisplay.AMInfoUpdate(var Msg: TMessage);
  341. var
  342.   s: array [0..20] of Char;
  343.   P: array [0..3] of Word;
  344. begin
  345.   if Msg.WParam = 0 then
  346.   begin
  347.     CurrentTime[0] := #0;
  348.     InvalidateRect(HWindow, nil, False);
  349.   end
  350.   else
  351.   if GetPlayer(HChess(Msg.WParam)) = Color then
  352.   begin
  353.     ConvertTicks(PUpdateRec(Msg.LParam)^.Time[Color],P[0],P[1],P[2],P[3]);
  354.     WVSprintf(S, '%02i:%02i:%02i.%02i', P);
  355.     if StrComp(CurrentTime, S) <> 0 then
  356.     begin
  357.       StrCopy(CurrentTime, S);
  358.       InvalidateRect(HWindow, nil, False);
  359.     end;
  360.   end;
  361. end;
  362.  
  363. constructor TGameTimeDisplay.InitResource(AParent: PWindowsObject;
  364.                                           ResID: Integer);
  365. begin
  366.   inherited InitResource(AParent, ResID, SizeOf(CurrentTime));
  367.   CurrentTime[0] := #0;
  368. end;
  369.  
  370. procedure TGameTimeDisplay.AMInfoUpdate(var Msg: TMessage);
  371. var
  372.   s: array [0..20] of Char;
  373.   P: array [0..3] of Word;
  374. begin
  375.   with PUpdateRec(Msg.LParam)^ do
  376.     ConvertTicks(Time[cWhite] + Time[cBlack],P[0],P[1],P[2],P[3]);
  377.   WVSprintf(S, '%02i:%02i:%02i.%02i', P);
  378.   if StrComp(CurrentTime, S) <> 0 then
  379.   begin
  380.     SetText(S);
  381.     StrCopy(CurrentTime, S);
  382.   end;
  383. end;
  384.  
  385. constructor TBestLine.InitResource(AParent: PWindowsObject; ResID: Integer);
  386. begin
  387.   inherited InitResource(AParent, ResID, 100);
  388.   CurrentLine[0] := #0;
  389. end;
  390.  
  391. procedure TBestLine.AMInfoUpdate(var Msg: TMessage);
  392. var
  393.   Value: Integer;
  394.   Line: array [0..23] of TMove;
  395.   S: array [0..8] of Char;
  396.   NewLine : array [0..100] of Char;
  397.   X, L: Integer;
  398. begin
  399.   NewLine[0] := #0;
  400.   if (Msg.WParam <> 0) and
  401.      ChessSettings.ShowBestLine then
  402.   begin
  403.     GetMainLine(HChess(Msg.WParam), Value, Line);
  404.     X := 0;
  405.     L := 0;
  406.     while (X <= High(Line))
  407.       and (Line[X].Change.Piece <> pEmpty)
  408.       and (L <= (High(NewLine) - High(S))) do
  409.     begin
  410.       MoveToStr(Line[X],S);
  411.       StrCopy(@NewLine[L],StrCat(S, ' '));
  412.       Inc(L, StrLen(S));
  413.       Inc(X);
  414.     end;
  415.   end;
  416.   if StrComp(CurrentLine, NewLine) <> 0 then
  417.   begin
  418.     SetText(NewLine);
  419.     StrCopy(CurrentLine, NewLine);
  420.   end;
  421. end;
  422.  
  423. constructor TValueLine.InitResource(AParent: PWindowsObject;
  424.                                     ResID: Integer);
  425. begin
  426.   inherited InitResource(AParent, ResID, 10);
  427.   CurrentValue := 0;
  428. end;
  429.  
  430. procedure TValueLine.AMInfoUpdate(var Msg: TMessage);
  431. var
  432.   Value: Integer;
  433.   Move: TMove;
  434.   S: array [0..10] of Char;
  435. begin
  436.   if Msg.WParam = 0 then
  437.     Value := 0
  438.   else
  439.     GetMainLine(HChess(Msg.WParam), Value, Move);
  440.   if Value <> CurrentValue then
  441.   begin
  442.     Str(Value, S);
  443.     SetText(S);
  444.     CurrentValue := Value;
  445.   end;
  446. end;
  447.  
  448. constructor TModeDisplay.InitResource(AParent: PWindowsObject; ResID: Integer);
  449. begin
  450.   inherited InitResource(AParent, ResID, 40);
  451.   CurrentMode := $FFFF;
  452. end;
  453.  
  454. procedure TModeDisplay.AMInfoUpdate(var Msg: TMessage);
  455. begin
  456.   with PUpdateRec(Msg.LParam)^ do
  457.   if GameMode <> CurrentMode then
  458.   begin
  459.     CurrentMode := GameMode;
  460.     SetText(StrNewRes(cxGameMode + CurrentMode));
  461.   end;
  462. end;
  463.  
  464. constructor TNodeDisplay.InitResource(AParent: PWindowsObject; ResID: Integer);
  465. begin
  466.   inherited InitResource(AParent, ResID, 20);
  467.   NodeCount := 0;
  468. end;
  469.  
  470. procedure TNodeDisplay.Zero;
  471. begin
  472.   NodeCount := 0;
  473.   SetText('0');
  474. end;
  475.  
  476. procedure TNodeDisplay.AMInfoUpdate(var Msg: TMessage);
  477. var
  478.   S: array [0..10] of Char;
  479. begin
  480.   with PUpdateRec(Msg.LParam)^ do
  481.   if UpdateSearchInfo then
  482.     if NodeCount <> Nodes then
  483.     begin
  484.       NodeCount := Nodes;
  485.       Str(NodeCount, S);
  486.       SetText(S);
  487.     end;
  488. end;
  489.  
  490. procedure TNodesPerSecond.AMInfoUpdate(var Msg: TMessage);
  491. var
  492.   S: array [0..10] of Char;
  493.   Temp: Longint;
  494. begin
  495.   with PUpdateRec(Msg.LParam)^ do
  496.   if UpdateSearchInfo then
  497.     if (LastInterval = 0) then
  498.       if NodeCount <> 0 then
  499.         Zero
  500.       else
  501.     else
  502.     begin
  503.       Temp := Nodes div Succ(LastInterval div 18);
  504.       if (NodeCount <> Temp) then
  505.       begin
  506.         NodeCount := Temp;
  507.         Str(NodeCount, S);
  508.         SetText(S);
  509.       end;
  510.     end;
  511. end;
  512.  
  513. procedure TMoveListbox.SetupWindow;
  514. var
  515.   TabStops: array [0..1] of Integer;
  516. begin
  517.   inherited SetupWindow;
  518.   TabStops[0] := 13;
  519.   TabStops[1] := 39;
  520.   SendMessage(HWindow, lb_SetTabStops, 2, Longint(@TabStops));
  521. end;
  522.  
  523. procedure TMoveListBox.AddMove(Turn: Integer;
  524.                                White, Black: PChar);
  525. var
  526.   S: array [0..20] of Char;
  527.   Params: array [0..2] of PChar;
  528. begin
  529.   if Turn < GetCount then
  530.     DeleteRest(Turn);
  531.   Params[0] := PChar(Turn);
  532.   Params[1] := White;
  533.   Params[2] := Black;
  534.   S[0] := #0;
  535.   wvsprintf(S, '%li'#9'%s'#9'%s', Params);
  536.   InsertString(S, -1);
  537.   SetSelIndex(Turn);
  538. end;
  539.  
  540. procedure TMoveListBox.DeleteRest(Turn: Integer);
  541. var
  542.   X: Integer;
  543. begin
  544.   for X := GetCount downto Turn do
  545.     DeleteString(X);
  546. end;
  547.  
  548. procedure TMoveListbox.AMInfoUpdate(var Msg: TMessage);
  549. begin
  550. end;
  551.  
  552.  
  553. constructor TChessInfoWindow.Init(AParent: PWindowsObject; AName: PChar);
  554. var
  555.   Dummy : PWindowsObject;
  556. begin
  557.   inherited Init(AParent, AName);
  558.   UpdateSearchInfo := False;
  559.   Msg := New(PStatic, InitResource(@Self, idInfoMsg, 50));
  560.   Dummy := New(PValueLine, InitResource(@Self, idInfoValue));
  561.   Dummy := New(PBestLine, InitResource(@Self, idInfoBestLine));
  562.   Dummy := New(PTimeDisplay, InitResource(@Self, idInfoWhite, cWhite));
  563.   Dummy := New(PTimeDisplay, InitResource(@Self, idInfoBlack, cBlack));
  564.   Dummy := New(PGameTimeDisplay, InitResource(@Self, idInfoTime));
  565.   Dummy := New(PTurnDisplay, InitResource(@Self, idInfoTurn));
  566.   Dummy := New(PModeDisplay, InitResource(@Self, idInfoMode));
  567.   Dummy := New(PNodeDisplay, InitResource(@Self, idInfoNodes));
  568.   Dummy := New(PNodesPerSecond, InitResource(@Self, idInfoNPSec));
  569.   MoveListBox := New(PMoveListBox, InitResource(@Self, idMovesListbox));
  570. end;
  571.  
  572. function TChessInfoWindow.GetClassName: PChar;
  573. begin
  574.   GetClassName := 'BorDlg_ChessInfo';
  575. end;
  576.  
  577. procedure TChessInfoWindow.GetWindowClass(var WC: TWndClass);
  578. begin
  579.   inherited GetWindowClass(WC);
  580.   WC.hCursor := 0;      { reflect wm_setcursor back to parent window }
  581. end;
  582.  
  583. procedure TChessInfoWindow.EnableSearchInfoUpdates(EnableUpdates: Boolean);
  584. begin
  585.   UpdateSearchInfo := EnableUpdates;
  586. end;
  587.  
  588. procedure TChessInfoWindow.ZeroNodes;
  589. begin
  590.   PNodeDisplay(ChildWithID(idInfoNodes))^.Zero;
  591.   PNodesPerSecond(ChildWithID(idInfoNPSec))^.Zero;
  592. end;
  593.  
  594. procedure TChessInfoWindow.Update(Game: HChess;
  595.                                   WhiteTime,
  596.                                   BlackTime,
  597.                                   LastInterval: Longint;
  598.                                   MoveNum: Integer;
  599.                                   GameMode: Word);
  600. var
  601.   N: TUpdateRec;
  602.  
  603.   procedure DoUpdate(P: PWindowsObject); far;
  604.   begin
  605.     SendMessage(P^.HWindow, AM_InfoUpdate, Game, Longint(@N));
  606.   end;
  607.  
  608. begin
  609.   N.Time[cWhite] := WhiteTime;
  610.   N.Time[cBlack] := BlackTime;
  611.   N.LastInterval := LastInterval;
  612.   N.MoveNum := MoveNum;
  613.   N.GameMode := GameMode;
  614.   N.Nodes := GetNodes(Game);
  615.   N.UpdateSearchInfo := UpdateSearchInfo;
  616.   ForEach(@DoUpdate);
  617. end;
  618.  
  619.  
  620. constructor TSettingsDlg.Init(AParent: PWindowsObject;
  621.                               AName: PChar;
  622.                               var XferBuf: TSettingsXferRec);
  623. var
  624.   P : PWindowsObject;
  625. begin
  626.   inherited Init(AParent, AName);
  627.   P := New(PRadioButton, InitResource(@Self, idLimitGameTime));
  628.   P := New(PRadioButton, InitResource(@Self, idLimitTurnTime));
  629.   P := New(PRadioButton, InitResource(@Self, idMatchUserTime));
  630.   P := New(PRadioButton, InitResource(@Self, idNoTimeLimit));
  631.   P := New(PEdit, InitResource(@Self, idLimitGameTimeInput, TimeLimitInputLen));
  632.   PEdit(P)^.SetValidator(New(PRangeValidator, Init(1, 600)));
  633.   with PEdit(P)^.Validator^ do
  634.     Options := Options or voTransfer;
  635.   P := New(PEdit, InitResource(@Self, idLimitTurnTimeInput, TimeLimitInputLen));
  636.   PEdit(P)^.SetValidator(New(PRangeValidator, Init(1, 36000)));
  637.   with PEdit(P)^.Validator^ do
  638.     Options := Options or voTransfer;
  639.   P := New(PCheckBox, InitResource(@Self, idShowAttacks));
  640.   P := New(PCheckBox, InitResource(@Self, idShowJeopardies));
  641.   P := New(PCheckBox, InitResource(@Self, idShowBestLine));
  642.   P := New(PCheckBox, InitResource(@Self, idRightClickQueries));
  643.   P := New(PRadioButton, InitResource(@Self, idSinglePlayer));
  644.   P := New(PRadioButton, InitResource(@Self, idTwoPlayer));
  645.   P := New(PScrollbar, InitResource(@Self, idThinkTime));
  646.   P^.EnableTransfer;
  647.   P := New(PCheckBox, InitResource(@Self, idAllowThinkAhead));
  648.   P := New(PCheckBox, InitResource(@Self, idCoverBoard));
  649.   TransferBuffer := @XferBuf;
  650. end;
  651.  
  652. procedure TSettingsDlg.SetupWindow;
  653. begin
  654.   inherited SetupWindow;
  655.   with PSettingsXferRec(TransferBuffer)^ do
  656.     ShowSet(LimitGame, LimitTurn);
  657. end;
  658.  
  659. procedure TSettingsDlg.EnableSet(Game, Turn: Boolean);
  660. begin
  661.   EnableWindow(GetItemHandle(idLimitTurnTimeLabel), Turn);
  662.   EnableWindow(GetItemHandle(idLimitTurnTimeInput), Turn);
  663.   EnableWindow(GetItemHandle(idTurnTimeUnit), Turn);
  664.   EnableWindow(GetItemHandle(idLimitGameTimeLabel), Game);
  665.   EnableWindow(GetItemHandle(idLimitGameTimeInput), Game);
  666.   EnableWindow(GetItemHandle(idGameTimeUnit), Game);
  667. end;
  668.  
  669. procedure TSettingsDlg.ShowSet(Game, Turn: Boolean);
  670. const
  671.   sw : array [False..True] of Word = (sw_Hide, sw_Show);
  672. begin
  673.   if Assigned(Win31LockWindowUpdate) then
  674.     Win31LockWindowUpdate(HWindow);
  675.   ShowWindow(GetItemHandle(idLimitTurnTimeInput), sw[Turn]);
  676.   ShowWindow(GetItemHandle(idLimitTurnTimeLabel), sw[Turn]);
  677.   ShowWindow(GetItemHandle(idTurnTimeUnit), sw[Turn]);
  678.   ShowWindow(GetItemHandle(idLimitGameTimeInput), sw[Game]);
  679.   ShowWindow(GetItemHandle(idLimitGameTimeLabel), sw[Game]);
  680.   ShowWindow(GetItemHandle(idGameTimeUnit), sw[Game]);
  681.   if Assigned(Win31LockWindowUpdate) then
  682.     Win31LockWindowUpdate(0);
  683.   EnableSet(Game, Turn);
  684. end;
  685.  
  686. procedure TSettingsDlg.LimitGameTime(var Msg: TMessage);
  687. begin
  688.   DefWndProc(Msg);
  689.   if Msg.LParamHi = BN_Clicked then
  690.     ShowSet(True, False);
  691. end;
  692.  
  693. procedure TSettingsDlg.LimitTurnTime(var Msg: TMessage);
  694. begin
  695.   DefWndProc(Msg);
  696.   if Msg.LParamHi = BN_Clicked then
  697.     ShowSet(False, True);
  698. end;
  699.  
  700. procedure TSettingsDlg.MatchUserTime(var Msg: TMessage);
  701. begin
  702.   DefWndProc(Msg);
  703.   if Msg.LParamHi = BN_Clicked then
  704.     EnableSet(False, False);
  705. end;
  706.  
  707. procedure TSettingsDlg.NoTimeLimit(var Msg: TMessage);
  708. begin
  709.   DefWndProc(Msg);
  710.   if Msg.LParamHi = BN_Clicked then
  711.     EnableSet(False, False);
  712. end;
  713.  
  714.  
  715. procedure LoadINISettings;
  716. var
  717.   I: Longint;
  718. begin
  719.   FillChar(ChessSettings, SizeOf(ChessSettings), 0);
  720.   with ChessSettings, XApp^ do
  721.   begin
  722.     I := GetAppProfileLongint('Settings','TimeLimitType',2);
  723.     case I of
  724.       1: LimitGame := True;
  725.       2: LimitTurn := True;
  726.       4: MatchUser := True;
  727.       8: NoLimit   := True;
  728.     else
  729.       {!! Display error msg }
  730.       LimitTurn := True;
  731.     end;
  732.     TurnTime := GetAppProfileLongint('Settings','SecsPerTurn',10);
  733.     GameTime := GetAppProfileLongint('Settings','MinsPerGame',30);
  734.     ShowAttacks := GetAppProfileBoolean('Settings','ShowAttacks',True);
  735.     ShowJeopardies := GetAppProfileBoolean('Settings',
  736.                                            'ShowJeopardies',True);
  737.     ShowBestLine := GetAppProfileBoolean('Settings','ShowBestLine',True);
  738.     RightClickHints := GetAppProfileBoolean('Settings',
  739.                                             'RightClickHints',True);
  740.     TwoPlayer := GetAppProfileBoolean('Settings','TwoPlayers',False);
  741.     OnePlayer := not TwoPlayer;
  742.     with ThinkTime do
  743.     begin
  744.       LowValue := 1;
  745.       HighValue := 36;
  746.       Position := Integer(GetAppProfileLongint('Settings',
  747.                                                'TicsPerThink',2));
  748.     end;
  749.     AllowThinkAhead := GetAppProfileBoolean('Settings',
  750.                                             'AllowThinkAhead',True);
  751.     CoverBoard := GetAppProfileBoolean('Settings','PauseCoversBoard',True);
  752.     RefreshRate := Word(GetAppProfileLongint('Settings','RefreshRate',500));
  753.   end;
  754. end;
  755.  
  756. procedure SaveINISettings;
  757. var
  758.   X: Longint;
  759. begin
  760.   with ChessSettings, XApp^ do
  761.   begin
  762.     X := Word(LimitGame) +
  763.          Word(LimitTurn) shl 1 +
  764.          Word(MatchUser) shl 2 +
  765.          Word(NoLimit) shl 3;
  766.     WriteAppProfileLongint('Settings','TimeLimitType',X);
  767.     WriteAppProfileLongint('Settings','SecsPerTurn',TurnTime);
  768.     WriteAppProfileLongint('Settings','MinsPerGame',GameTime);
  769.     WriteAppProfileBoolean('Settings','ShowAttacks',ShowAttacks);
  770.     WriteAppProfileBoolean('Settings','ShowJeopardies',ShowJeopardies);
  771.     WriteAppProfileBoolean('Settings','ShowBestLine',ShowBestLine);
  772.     WriteAppProfileBoolean('Settings','RightClickHints',RightClickHints);
  773.     WriteAppProfileBoolean('Settings','TwoPlayers',TwoPlayer);
  774.     WriteAppProfileLongint('Settings','TicsPerThink',ThinkTime.Position);
  775.     WriteAppProfileBoolean('Settings','AllowThinkAhead',AllowThinkAhead);
  776.     WriteAppProfileBoolean('Settings','PauseCoversBoard',CoverBoard);
  777.     WriteAppProfileLongint('Settings','RefreshRate',RefreshRate);
  778.   end;
  779. end;
  780.  
  781.  
  782. constructor TCoverDlg.Init(AParent: PWindowsObject; AResName: PChar);
  783. begin
  784.   inherited Init(AParent, AResName);
  785.   Locked := False;
  786. end;
  787.  
  788. procedure TCoverDlg.Lock;
  789. begin
  790.   Inc(Locked);
  791. end;
  792.  
  793. procedure TCoverDlg.Unlock;
  794. begin
  795.   if Locked then
  796.     Dec(Locked);
  797. end;
  798.  
  799. procedure TCoverDlg.Show(ShowCmd: Integer);
  800. begin
  801.   if not Locked then
  802.     if ShowCmd = sw_Hide then
  803.       SetWindowPos(HWindow, 0,0,0,0,0,
  804.         swp_NoZOrder or swp_HideWindow)
  805.     else
  806.     begin
  807.       SetWindowPos(HWindow, 0,0,0,0,0,
  808.         swp_NoActivate or swp_NoZOrder or swp_ShowWindow);
  809.       { Win 3.0 needs the following forced repaint. }
  810.       InvalidateRect(HWindow, nil, True);
  811.     end;
  812. end;
  813.  
  814. procedure TCoverDlg.WMSize(var Msg: TMessage);
  815. var
  816.   R: TRect;
  817. begin
  818.   DefWndProc(Msg);
  819.   SetWindowPos(GetDlgItem(HWindow, idCoverGroup), 0,
  820.         Msg.LParamLo div 5, Msg.LParamHi div 5,
  821.         Integer(Msg.LParamLo - 2*(Msg.LParamLo div 5)),
  822.         Integer(Msg.LParamHi - 2*(Msg.LParamHi div 5)),
  823.         swp_NoZOrder or swp_NoActivate);
  824.   GetClientRect(GetDlgItem(HWindow, idCoverText), R);
  825.   SetWindowPos(GetDlgItem(HWindow, idCoverText), 0,
  826.         Msg.LParamLo div 5 + 2,
  827.         Integer(Msg.LParamHi div 2 - R.Bottom div 2),
  828.         Integer(Msg.LParamLo - 2*(Msg.LParamLo div 5) - 4), R.Bottom,
  829.         swp_NoZOrder or swp_NoActivate);
  830. end;
  831.  
  832.  
  833. procedure TRelocatingDlg.SetupWindow;
  834. var
  835.   R: TRect;
  836. begin
  837.   inherited SetupWindow;
  838.   GetWindowRect(Parent^.HWindow, R);
  839.   SetWindowPos(HWindow, 0, R.Left, R.Top, 0, 0, swp_NoSize or swp_NoZOrder);
  840. end;
  841.  
  842.  
  843. constructor TChoosePawnPromoteDlg.Init(AParent: PWindowsObject;
  844.                                        AResName: PChar;
  845.                                        AChange: PChange);
  846. var
  847.   Dummy: PRadiobutton;
  848. begin
  849.   inherited Init(AParent, AResName);
  850.   Change := AChange;
  851.   FillChar(Buffer, SizeOf(Buffer), 0);
  852.   Buffer[0] := True;           { Queen is the default choice }
  853.   TransferBuffer := @Buffer;
  854.   New(Dummy, InitResource(@Self, idQueen));
  855.   New(Dummy, InitResource(@Self, idRook));
  856.   New(Dummy, InitResource(@Self, idBishop));
  857.   New(Dummy, InitResource(@Self, idKnight));
  858. end;
  859.  
  860. procedure TChoosePawnPromoteDlg.TransferData(Direction: Word);
  861. var
  862.   X: Byte;
  863. begin
  864.   inherited TransferData(Direction);
  865.   if Direction = tf_GetData then
  866.   begin
  867.     for X := 0 to High(Buffer) do
  868.       if Buffer[X] then Break;
  869.     Change^.Piece := TPiece(ord(pQueen) + X);
  870.   end;
  871. end;
  872.  
  873. constructor TEnterMoveDlg.Init(AParent: PWindowsObject;
  874.                                AResName: PChar;
  875.                                AMoveStr: PChar);
  876. var
  877.   Dummy : PWindowsObject;
  878. begin
  879.   inherited Init(AParent, AResName);
  880.   Dummy := New(PEdit, InitResource(@Self, idEnterMoveEdit, 10));
  881.   TransferBuffer := AMoveStr;
  882. end;
  883.  
  884.  
  885. begin
  886.       { In Windows 3.0, the following GetProcAddress call will return nil,
  887.         but not cause a critical error message.  Any code that uses
  888.         this function variable should always test it first, with
  889.         the Assigned system function. }
  890.   @Win31LockWindowUpdate := GetProcAddress(
  891.                              GetModuleHandle('User'), PChar(294));
  892. end.