home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / BPASCAL.700 / D12 / CHESSTV.ZIP / CHESSDLG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-01  |  6.9 KB  |  265 lines

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