fGLOptions.pas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. fGLDialog;
  22. type
  23. TFormOptions = class(TGLDialog)
  24. CheckBoxAxis: TCheckBox;
  25. Label1: TLabel;
  26. PanelBackground: TPanel;
  27. RadioGroupLanguage: TRadioGroup;
  28. procedure FormCreate(Sender: TObject);
  29. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  30. procedure RadioGroupLanguageClick(Sender: TObject);
  31. procedure ButtonOKClick(Sender: TObject);
  32. procedure PanelBackgroundClick(Sender: TObject);
  33. procedure CheckBoxAxisClick(Sender: TObject);
  34. private
  35. public
  36. CurLangID : Word;
  37. procedure ReadIniFile; override;
  38. procedure WriteIniFile;
  39. end;
  40. var
  41. FormOptions: TFormOptions;
  42. //---------------------------------------------------------------------------
  43. implementation
  44. {$R *.dfm}
  45. uses
  46. GnuGettext,
  47. fGLSViewer;
  48. procedure TFormOptions.FormCreate(Sender: TObject);
  49. begin
  50. inherited;
  51. ReadIniFile;
  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, RadioGroupLanguage.Name, 0);
  67. case LangID of
  68. LANG_ENGLISH : RadioGroupLanguage.ItemIndex := 0;
  69. LANG_RUSSIAN : RadioGroupLanguage.ItemIndex := 1;
  70. LANG_SPANISH : RadioGroupLanguage.ItemIndex := 2;
  71. LANG_ITALIAN : RadioGroupLanguage.ItemIndex := 3;
  72. else
  73. RadioGroupLanguage.ItemIndex := 0;
  74. end;
  75. finally
  76. IniFile.Free;
  77. end;
  78. end;
  79. procedure TFormOptions.RadioGroupLanguageClick(Sender: TObject);
  80. begin
  81. case RadioGroupLanguage.ItemIndex of
  82. 0: CurLangID := LANG_ENGLISH;
  83. 1: CurLangID := LANG_RUSSIAN;
  84. 2: CurLangID := LANG_SPANISH;
  85. 3: CurLangID := LANG_ITALIAN;
  86. else
  87. CurLangID := LANG_ENGLISH;
  88. end;
  89. end;
  90. procedure TFormOptions.WriteIniFile;
  91. begin
  92. IniFile := TIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));
  93. with IniFile do
  94. try
  95. WriteBool(Name, CheckBoxAxis.Name, CheckBoxAxis.Checked);
  96. WriteInteger(Name, RadioGroupLanguage.Name, CurLangID);
  97. WriteInteger(Name, PanelBackground.Name, PanelBackground.Color);
  98. finally
  99. IniFile.Free;
  100. end;
  101. inherited;
  102. end;
  103. procedure TFormOptions.CheckBoxAxisClick(Sender: TObject);
  104. begin
  105. if CheckBoxAxis.Checked then
  106. FormGLSViewer.DCAxis.Visible := True
  107. else
  108. FormGLSViewer.DCAxis.Visible := False;
  109. end;
  110. procedure TFormOptions.PanelBackgroundClick(Sender: TObject);
  111. begin
  112. dmDialogs.ColorDialog.Color := PanelBackground.Color;
  113. if dmDialogs.ColorDialog.Execute then
  114. begin
  115. PanelBackground.Color := dmDialogs.ColorDialog.Color;
  116. FormGLSViewer.ApplyBgColor;
  117. end;
  118. end;
  119. procedure TFormOptions.ButtonOKClick(Sender: TObject);
  120. var
  121. FileName: TFileName;
  122. begin
  123. if CurLangID <> LangID then
  124. begin
  125. MessageDlg(_('Reload to change language'), mtInformation, [mbOK], 0);
  126. FileName := ChangeFileExt(ParamStr(0), '.ini');
  127. if FileExists(UpperCase(FileName)) then
  128. DeleteFile(UpperCase(FileName)); //to exclude dublicated sections for each language
  129. end;
  130. end;
  131. end.