fGLOptions.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. unit fGLOptions;
  2. interface
  3. uses
  4. Winapi.Windows,
  5. Winapi.Messages,
  6. System.SysUtils,
  7. System.UITypes,
  8. System.Variants,
  9. System.Classes,
  10. System.IniFiles,
  11. Vcl.Graphics,
  12. Vcl.Controls,
  13. Vcl.Forms,
  14. Vcl.Dialogs,
  15. Vcl.StdCtrls,
  16. Vcl.ExtCtrls,
  17. //
  18. dImages,
  19. dDialogs,
  20. fGLForm;
  21. type
  22. TFormOptions = class(TGLForm)
  23. rgLanguage: TRadioGroup;
  24. CheckBoxAxis: TCheckBox;
  25. PanelBackground: TPanel;
  26. ButtonOk: TButton;
  27. procedure FormCreate(Sender: TObject);
  28. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  29. procedure rgLanguageClick(Sender: TObject);
  30. procedure ButtonOKClick(Sender: TObject);
  31. procedure PanelBackgroundClick(Sender: TObject);
  32. procedure CheckBoxAxisClick(Sender: TObject);
  33. private
  34. public
  35. CurLangID : Word;
  36. procedure ReadIniFile; override;
  37. procedure WriteIniFile;
  38. end;
  39. var
  40. FormOptions: TFormOptions;
  41. //---------------------------------------------------------------------------
  42. implementation
  43. {$R *.dfm}
  44. uses
  45. GnuGettext,
  46. fGLSViewer;
  47. procedure TFormOptions.FormCreate(Sender: TObject);
  48. begin
  49. inherited;
  50. ReadIniFile;
  51. SetLanguage;
  52. end;
  53. procedure TFormOptions.FormClose(Sender: TObject; var Action: TCloseAction);
  54. begin
  55. WriteIniFile;
  56. inherited;
  57. end;
  58. procedure TFormOptions.ReadIniFile;
  59. begin
  60. inherited;
  61. IniFile := TIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));
  62. with IniFile do
  63. try
  64. CheckBoxAxis.Checked := ReadBool(Name, CheckBoxAxis.Name, True);
  65. PanelBackground.Color := ReadInteger(Name, PanelBackground.Name, 0);
  66. LangID := ReadInteger(Name, rgLanguage.Name, 0);
  67. case LangID of
  68. LANG_ENGLISH : rgLanguage.ItemIndex := 0;
  69. LANG_RUSSIAN : rgLanguage.ItemIndex := 1;
  70. else
  71. rgLanguage.ItemIndex := 0;
  72. end;
  73. finally
  74. IniFile.Free;
  75. end;
  76. end;
  77. procedure TFormOptions.rgLanguageClick(Sender: TObject);
  78. begin
  79. case rgLanguage.ItemIndex of
  80. 0: CurLangID := LANG_ENGLISH;
  81. 1: CurLangID := LANG_RUSSIAN;
  82. else
  83. CurLangID := LANG_ENGLISH;
  84. end;
  85. end;
  86. procedure TFormOptions.WriteIniFile;
  87. begin
  88. IniFile := TIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));
  89. with IniFile do
  90. try
  91. WriteBool(Name, CheckBoxAxis.Name, CheckBoxAxis.Checked);
  92. WriteInteger(Name, rgLanguage.Name, CurLangID);
  93. WriteInteger(Name, PanelBackground.Name, PanelBackground.Color);
  94. finally
  95. IniFile.Free;
  96. end;
  97. inherited;
  98. end;
  99. procedure TFormOptions.CheckBoxAxisClick(Sender: TObject);
  100. begin
  101. if CheckBoxAxis.Checked then
  102. FormGLSViewer.DCAxis.Visible := True
  103. else
  104. FormGLSViewer.DCAxis.Visible := False;
  105. end;
  106. procedure TFormOptions.PanelBackgroundClick(Sender: TObject);
  107. begin
  108. dmDialogs.ColorDialog.Color := PanelBackground.Color;
  109. if dmDialogs.ColorDialog.Execute then
  110. begin
  111. PanelBackground.Color := dmDialogs.ColorDialog.Color;
  112. FormGLSViewer.ApplyBgColor;
  113. end;
  114. end;
  115. procedure TFormOptions.ButtonOKClick(Sender: TObject);
  116. var
  117. FileName: TFileName;
  118. begin
  119. if CurLangID <> LangID then
  120. begin
  121. MessageDlg(_('Reload to change language'), mtInformation, [mbOK], 0);
  122. FileName := ChangeFileExt(ParamStr(0), '.ini');
  123. if FileExists(UpperCase(FileName)) then
  124. DeleteFile(UpperCase(FileName)); //to exclude dublicated sections for each language
  125. end;
  126. end;
  127. end.