fGLOptions.pas 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. dGLSViewer,
  19. fGLForm,
  20. fGLDialog;
  21. type
  22. TGLOptions = class(TGLDialog)
  23. CheckBoxAxis: TCheckBox;
  24. Label1: TLabel;
  25. RadioGroupLanguage: TRadioGroup;
  26. PanelBackground: TPanel;
  27. procedure FormCreate(Sender: TObject);
  28. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  29. procedure RadioGroupLanguageClick(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; override;
  38. end;
  39. var
  40. GLOptions: TGLOptions;
  41. implementation
  42. {$R *.dfm}
  43. uses
  44. GnuGettext,
  45. fMain;
  46. procedure TGLOptions.FormCreate(Sender: TObject);
  47. begin
  48. inherited;
  49. ReadIniFile;
  50. end;
  51. procedure TGLOptions.FormClose(Sender: TObject; var Action: TCloseAction);
  52. begin
  53. WriteIniFile;
  54. inherited;
  55. end;
  56. procedure TGLOptions.ReadIniFile;
  57. begin
  58. inherited;
  59. IniFile := TIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));
  60. with IniFile do
  61. try
  62. CheckBoxAxis.Checked := ReadBool(Name, CheckBoxAxis.Name, True);
  63. PanelBackground.Color := ReadInteger(Name, PanelBackground.Name, 0);
  64. LangID := ReadInteger(Name, RadioGroupLanguage.Name, 0);
  65. case LangID of
  66. LANG_ENGLISH : RadioGroupLanguage.ItemIndex := 0;
  67. LANG_RUSSIAN : RadioGroupLanguage.ItemIndex := 1;
  68. LANG_SPANISH : RadioGroupLanguage.ItemIndex := 2;
  69. LANG_FRENCH : RadioGroupLanguage.ItemIndex := 3;
  70. LANG_GERMAN : RadioGroupLanguage.ItemIndex := 4;
  71. LANG_ITALIAN : RadioGroupLanguage.ItemIndex := 5;
  72. else
  73. RadioGroupLanguage.ItemIndex := 0;
  74. end;
  75. finally
  76. IniFile.Free;
  77. end;
  78. end;
  79. procedure TGLOptions.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_FRENCH;
  86. 4: CurLangID := LANG_GERMAN;
  87. 5: CurLangID := LANG_ITALIAN;
  88. else
  89. CurLangID := LANG_ENGLISH;
  90. end;
  91. end;
  92. procedure TGLOptions.WriteIniFile;
  93. begin
  94. IniFile := TIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));
  95. with IniFile do
  96. try
  97. WriteBool(Name, CheckBoxAxis.Name, CheckBoxAxis.Checked);
  98. WriteInteger(Name, RadioGroupLanguage.Name, CurLangID);
  99. WriteInteger(Name, PanelBackground.Name, PanelBackground.Color);
  100. finally
  101. IniFile.Free;
  102. end;
  103. inherited;
  104. end;
  105. procedure TGLOptions.CheckBoxAxisClick(Sender: TObject);
  106. begin
  107. if CheckBoxAxis.Checked then
  108. MainForm.DCAxis.Visible := True
  109. else
  110. MainForm.DCAxis.Visible := False;
  111. end;
  112. procedure TGLOptions.PanelBackgroundClick(Sender: TObject);
  113. begin
  114. dmGLSViewer.ColorDialog.Color := PanelBackground.Color;
  115. if dmGLSViewer.ColorDialog.Execute then
  116. begin
  117. PanelBackground.Color := dmGLSViewer.ColorDialog.Color;
  118. MainForm.ApplyBgColor;
  119. end;
  120. end;
  121. procedure TGLOptions.ButtonOKClick(Sender: TObject);
  122. var
  123. FileName: TFileName;
  124. begin
  125. if CurLangID <> LangID then
  126. begin
  127. MessageDlg(_('Reload to change language'),
  128. mtInformation, [mbOK], 0);
  129. FileName := ChangeFileExt(ParamStr(0), '.ini');
  130. if FileExists(UpperCase(FileName)) then
  131. DeleteFile(UpperCase(FileName)); //to exclude dublicated sections for each language
  132. end;
  133. end;
  134. end.