home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programming Unleashed / Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso / misc / life / setting.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-21  |  2.4 KB  |  100 lines

  1. unit Setting;
  2.  
  3. { Program copyright (c) 1995 by Charles Calvert }
  4. { Project Name: LIFE }
  5.  
  6. interface
  7.  
  8. uses
  9.   SysUtils, WinTypes, WinProcs,
  10.   Messages, Classes, Graphics,
  11.   Controls, Forms, Dialogs,
  12.   StdCtrls, Spin, ExtCtrls;
  13.  
  14. type
  15.   TSettings = class(TForm)
  16.     LBoardSize: TLabel;
  17.     LBoardSizeY: TLabel;
  18.     LGridSize: TLabel;
  19.     CheckforAltGen: TCheckBox;
  20.     SpinEdit1: TSpinEdit;
  21.     PBoardSizeX: TPanel;
  22.     PBoardSizeY: TPanel;
  23.     procedure AnyChangeClick(Sender: TObject);
  24.   protected
  25.     procedure CreateParams(var Params: TCreateParams); override;
  26.   public
  27.     procedure FindBestSize;
  28.     procedure SetStartState;
  29.     procedure TabsOn(Setting: Boolean);
  30.   end;
  31.  
  32. var
  33.   Settings: TSettings;
  34.  
  35. implementation
  36.  
  37. uses
  38.   LifeDef;
  39.  
  40. {$R *.DFM}
  41.  
  42. procedure TSettings.CreateParams(var Params: TCreateParams);
  43. begin
  44.   inherited CreateParams(Params);
  45.   Params.Style := Params.Style and not ws_Caption;
  46.   Params.Style := Params.Style and not ws_ThickFrame;
  47.   Params.Style := Params.Style or ws_Border;
  48. end;
  49.  
  50. procedure TSettings.FindBestSize;
  51. const
  52.   Border = 5;
  53. var
  54.   R: TRect;
  55.   MikeSize: Integer;
  56.   Temp: Integer;
  57. begin
  58.   R := GetClientRect;
  59.   MikeSize := BoardInfo.MicrobeSize;
  60.   if MikeSize > 0 then begin
  61.     BoardInfo.SizeX := (R.Right - (2 * Border)) div MikeSize;
  62.     BoardInfo.SizeY := (R.Bottom - (2 * Border)) div MikeSize;
  63.     Temp := BoardInfo.SizeY * MikeSize + Border + MikeSize;
  64.     if Temp >= R.Bottom then Dec(BoardInfo.SizeY);
  65.     Temp := BoardInfo.SizeX * MikeSize + Border + MikeSize;
  66.     if Temp >= R.Right then Dec(BoardInfo.SizeX);
  67.   end;
  68.   PBoardSizeX.Caption := IntToStr(BoardInfo.SizeX);
  69.   PBoardSizeY.Caption := IntToStr(BoardInfo.SizeY);
  70.   SpinEdit1.Value := BoardInfo.MicrobeSize;
  71. end;
  72.  
  73. procedure TSettings.AnyChangeClick(Sender: TObject);
  74. begin
  75.   BoardInfo.MicrobeSize := SpinEdit1.Value;
  76.   GameInfo.CheckForAltGen := CheckForAltGen.Checked;
  77.   FindBestSize;
  78. end;
  79.  
  80. { Called Only when program begins }
  81. procedure TSettings.SetStartState;
  82. begin
  83.   GameInfo.GameType := Classic;
  84.   GameInfo.MaxGen := 32000;
  85.   GameInfo.CheckForAltGen := True;
  86.   CheckForAltGen.Checked := GameInfo.CheckForAltGen;
  87.   BoardInfo.MicrobeSize := 10;
  88.   SpinEdit1.Value := BoardInfo.MicrobeSize;
  89. end;
  90.  
  91. procedure TSettings.TabsOn(Setting: Boolean);
  92. var
  93.   i: Integer;
  94. begin
  95.   for i := 0 to ComponentCount - 1 do
  96.     TWinControl(Components[i]).Enabled := Setting;
  97. end;
  98.  
  99. end.
  100.