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

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Vision Chess Demo                      }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. unit TVChsDlg;
  9.  
  10. interface
  11.  
  12. uses Objects, Views, Dialogs, TVChsCmd, Drivers;
  13.  
  14. type
  15.   PTimeLabel = ^TTimeLabel;
  16.   TTimeLabel = object(TLabel)
  17.     function GetPalette: PPalette; virtual;
  18.   end;
  19.  
  20.   PTimeInput = ^TTimeInput;
  21.   TTimeInput = object(TInputLine)
  22.     function GetPalette: PPalette; virtual;
  23.     procedure SetOpt(AOptions: Word; Enable: Boolean);
  24.   end;
  25.  
  26.   PTimeSettings = ^TTimeSettings;
  27.   TTimeSettings = object(TRadioButtons)
  28.     procedure MovedTo(Item: Integer); virtual;
  29.     procedure Press(Item: Integer); virtual;
  30.     procedure SetData(var Rec); virtual;
  31.   end;
  32.  
  33.   PSettingsDlg = ^TSettingsDlg;
  34.   TSettingsDlg = object(TDialog)
  35.     TurnLabel: PTimeLabel;
  36.     GameLabel: PTimeLabel;
  37.     TurnInput: PTimeInput;
  38.     GameInput: PTimeInput;
  39.     Minutes, Seconds: PTimeLabel;
  40.     constructor Load(var S: TStream);
  41.     procedure EnableSet(Game, Turn: Boolean);
  42.     function GetPalette: PPalette; virtual;
  43.     procedure HandleEvent(var Event: TEvent); virtual;
  44.     procedure ShowSet(Game, Turn: Boolean);
  45.     procedure Store(var S: TStream);
  46.   end;
  47.  
  48. const
  49.   RTimeLabel: TStreamRec = (
  50.     ObjType: otTimeLabel;
  51.     VmtLink: Ofs(TypeOf(TTimeLabel)^);
  52.     Load:    @TTimeLabel.Load;
  53.     Store:   @TTimeLabel.Store);
  54.  
  55.   RTimeInput: TStreamRec = (
  56.     ObjType: otTimeInput;
  57.     VmtLink: Ofs(TypeOf(TTimeInput)^);
  58.     Load:    @TTimeInput.Load;
  59.     Store:   @TTimeInput.Store);
  60.  
  61.   RSettingsDlg: TStreamRec = (
  62.     ObjType: otSettingsDlg;
  63.     VmtLink: Ofs(TypeOf(TSettingsDlg)^);
  64.     Load:    @TSettingsDlg.Load;
  65.     Store:   @TSettingsDlg.Store);
  66.  
  67. function CreateSettingsDlg: PDialog;
  68.  
  69. implementation
  70.  
  71. uses Validate;
  72.  
  73. function TTimeLabel.GetPalette: PPalette;
  74. const
  75.   P: string[Length(CTimeLabel)] = CTimeLabel;
  76. begin
  77.   if (Link <> nil) and (Link^.Options and ofSelectable <> 0) then
  78.     GetPalette := inherited GetPalette
  79.   else GetPalette := @P;
  80. end;
  81.  
  82. function TTimeInput.GetPalette: PPalette;
  83. const
  84.   P: string[Length(CTimeInput)] = CTimeInput;
  85. begin
  86.   if Options and ofSelectable <> 0 then
  87.     GetPalette := inherited GetPalette
  88.   else GetPalette := @P;
  89. end;
  90.  
  91. procedure TTimeInput.SetOpt(AOptions: Word; Enable: Boolean);
  92. begin
  93.   if Enable then Options := Options or AOptions
  94.   else Options := Options and not AOptions;
  95.   DrawView;
  96. end;
  97.  
  98. procedure TTimeSettings.MovedTo(Item: Integer);
  99. begin
  100.   inherited MovedTo(Item);
  101.   Message(Owner, evCommand, cmTimeOptChg, Pointer(Item));
  102. end;
  103.  
  104. procedure TTimeSettings.Press(Item: Integer);
  105. begin
  106.   inherited Press(Item);
  107.   Message(Owner, evCommand, cmTimeOptChg, Pointer(Item));
  108. end;
  109.  
  110. procedure TTimeSettings.SetData(var Rec);
  111. begin
  112.   inherited SetData(Rec);
  113.   Message(Owner, evCommand, cmTimeOptChg, Pointer(Value));
  114. end;
  115.  
  116. constructor TSettingsDlg.Load(var S: TStream);
  117. begin
  118.   inherited Load(S);
  119.   GetSubViewPtr(S, TurnLabel);
  120.   GetSubViewPtr(S, GameLabel);
  121.   GetSubViewPtr(S, TurnInput);
  122.   GetSubViewPtr(S, Gameinput);
  123.   GetSubViewPtr(S, Minutes);
  124.   GetSubViewPtr(S, Seconds);
  125. end;
  126.  
  127. procedure TSettingsDlg.EnableSet(Game, Turn: Boolean);
  128. begin
  129.   GameInput^.SetOpt(ofSelectable, Game);
  130.   GameLabel^.DrawView;
  131.   Minutes^.DrawView;
  132.   TurnInput^.SetOpt(ofSelectable, Turn);
  133.   TurnLabel^.DrawView;
  134.   Seconds^.DrawView;
  135. end;
  136.  
  137. function TSettingsDlg.GetPalette: PPalette;
  138. const
  139.   P: string[Length(CSettingsDlg)] = CSettingsDlg;
  140. begin
  141.   GetPalette := @P;
  142. end;
  143.  
  144. procedure TSettingsDlg.HandleEvent(var Event: TEvent);
  145. begin
  146.   inherited HandleEvent(Event);
  147.   if (Event.What = evCommand) and (Event.Command = cmTimeOptChg) then
  148.   begin
  149.     case Event.InfoInt of
  150.       0: ShowSet(True, False);
  151.       1: ShowSet(False, True);
  152.       2: EnableSet(False, False);
  153.       3: EnableSet(False, False);
  154.     else Exit;
  155.     end;
  156.     ClearEvent(Event);
  157.   end;
  158. end;
  159.  
  160. procedure TSettingsDlg.ShowSet(Game, Turn: Boolean);
  161. begin
  162.   GameInput^.SetOpt(ofSelectable, False);
  163.   TurnInput^.SetOpt(ofSelectable, False);
  164.   GameLabel^.SetState(sfVisible, Game);
  165.   Minutes^.SetState(sfVisible, Game);
  166.   GameInput^.SetState(sfVisible, Game);
  167.   TurnLabel^.SetState(sfVisible, Turn);
  168.   Seconds^.SetState(sfVisible, Turn);
  169.   TurnInput^.SetState(sfVisible, Turn);
  170.   EnableSet(Game, Turn);
  171. end;
  172.  
  173. procedure TSettingsDlg.Store(var S: TStream);
  174. begin
  175.   inherited Store(S);
  176.   PutSubViewPtr(S, TurnLabel);
  177.   PutSubViewPtr(S, GameLabel);
  178.   PutSubViewPtr(S, TurnInput);
  179.   PutSubViewPtr(S, Gameinput);
  180.   PutSubViewPtr(S, Minutes);
  181.   PutSubViewPtr(S, Seconds);
  182. end;
  183.  
  184.  
  185. function CreateSettingsDlg: PDialog;
  186. var
  187.   Dlg : PSettingsDlg;
  188.   R : TRect;
  189.   Control, Labl, Histry : PView;
  190. Begin
  191.   R.Assign(0,0,56,15);
  192.   New(Dlg, Init(R, 'Settings'));
  193.   with Dlg^ do
  194.   begin
  195.     Options := Options or ofCentered;
  196.  
  197.     R.Assign(3,3,26,7);
  198.     Control := New(PTimeSettings, Init(R,
  199.       NewSItem('Limit ~g~ame time',
  200.       NewSItem('Limit t~u~rn time',
  201.       NewSItem('~M~atch user''s time',
  202.       NewSItem('~N~o time limit',Nil))))));
  203.     Insert(Control);
  204.  
  205.       R.Assign(2,2,24,3);
  206.       Labl := New(PLabel, Init(R, 'Time limit selections', Control));
  207.       Dlg^.Insert(Labl);
  208.  
  209.     R.Assign(14,9,22,10);
  210.     GameInput := New(PTimeInput, Init(R, 6));
  211.     GameInput^.SetValidator(New(PRangeValidator, Init(1, 600)));
  212.     with GameInput^.Validator^ do
  213.       Options := Options or voTransfer;
  214.     Insert(GameInput);
  215.  
  216.       R.Assign(2,9,12,10);
  217.       GameLabel := New(PTimeLabel, Init(R, 'Gam~e~ time', GameInput));
  218.       Insert(GameLabel);
  219.  
  220.       R.Assign(22,9,26,10);
  221.       Minutes := New(PTimeLabel, Init(R, 'min', GameInput));
  222.       Insert(Minutes);
  223.  
  224.     R.Assign(14,9,22,10);
  225.     TurnInput := New(PTimeInput, Init(R, 6));
  226.     TurnInput^.SetValidator(New(PRangeValidator, Init(1, 36000)));
  227.     with TurnInput^.Validator^ do
  228.       Options := Options or voTransfer;
  229.     Insert(TurnInput);
  230.  
  231.       R.Assign(2,9,12,10);
  232.       TurnLabel := New(PTimeLabel, Init(R, 'Tu~r~n time', TurnInput));
  233.       Insert(TurnLabel);
  234.  
  235.       R.Assign(22,9,26,10);
  236.       Seconds := New(PTimeLabel, Init(R, 'sec', TurnInput));
  237.       Insert(Seconds);
  238.  
  239.     R.Assign(28,3,53,8);
  240.     Control := New(PCheckboxes, Init(R,
  241.       NewSItem('Show ~a~ttacks',
  242.       NewSItem('Show ~j~eopardies',
  243.       NewSItem('Show ~b~est-line',
  244.       NewSItem('Right click ~q~ueries',
  245.       NewSItem('T~h~ink ahead', nil)))))));
  246.     PCluster(Control)^.Value := 0;
  247.     Insert(Control);
  248.  
  249.       R.Assign(27,2,33,3);
  250.       Labl := New(PLabel, Init(R, 'Hints', Control));
  251.       Insert(Labl);
  252.  
  253.     R.Assign(28,10,53,11);
  254.     Control := New(PRadioButtons, Init(R,
  255.       NewSItem('~O~ne    ',
  256.       NewSItem('~T~wo',Nil))));
  257.     PCluster(Control)^.Value := 0;
  258.     Insert(Control);
  259.  
  260.       R.Assign(27,9,35,10);
  261.       Labl := New(PLabel, Init(R, 'Players', Control));
  262.       Insert(Labl);
  263.  
  264.     R.Assign(31,12,41,14);
  265.     Control := New(PButton, Init(R, 'O~K~', cmOK, bfDefault));
  266.     Insert(Control);
  267.  
  268.     Inc(R.A.X, 12); Inc(R.B.X, 12);
  269.     Control := New(PButton, Init(R, 'Cancel', cmCancel, bfNormal));
  270.     Insert(Control);
  271.  
  272.     SelectNext(False);
  273.   end;
  274.   CreateSettingsDlg := Dlg;
  275. end;
  276.  
  277. end.