fGLOptions.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. rgLanguage: TRadioGroup;
  28. procedure FormCreate(Sender: TObject);
  29. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  30. procedure rgLanguageClick(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, rgLanguage.Name, 0);
  67. case LangID of
  68. LANG_ENGLISH : rgLanguage.ItemIndex := 0;
  69. LANG_RUSSIAN : rgLanguage.ItemIndex := 1;
  70. LANG_SPANISH : rgLanguage.ItemIndex := 2;
  71. else
  72. rgLanguage.ItemIndex := 0;
  73. end;
  74. finally
  75. IniFile.Free;
  76. end;
  77. end;
  78. procedure TFormOptions.rgLanguageClick(Sender: TObject);
  79. begin
  80. case rgLanguage.ItemIndex of
  81. 0: CurLangID := LANG_ENGLISH;
  82. 1: CurLangID := LANG_RUSSIAN;
  83. 2: CurLangID := LANG_SPANISH;
  84. else
  85. CurLangID := LANG_ENGLISH;
  86. end;
  87. end;
  88. procedure TFormOptions.WriteIniFile;
  89. begin
  90. IniFile := TIniFile.Create(ChangeFileExt(ParamStr(0), '.ini'));
  91. with IniFile do
  92. try
  93. WriteBool(Name, CheckBoxAxis.Name, CheckBoxAxis.Checked);
  94. WriteInteger(Name, rgLanguage.Name, CurLangID);
  95. WriteInteger(Name, PanelBackground.Name, PanelBackground.Color);
  96. finally
  97. IniFile.Free;
  98. end;
  99. inherited;
  100. end;
  101. procedure TFormOptions.CheckBoxAxisClick(Sender: TObject);
  102. begin
  103. if CheckBoxAxis.Checked then
  104. FormGLSViewer.DCAxis.Visible := True
  105. else
  106. FormGLSViewer.DCAxis.Visible := False;
  107. end;
  108. procedure TFormOptions.PanelBackgroundClick(Sender: TObject);
  109. begin
  110. dmDialogs.ColorDialog.Color := PanelBackground.Color;
  111. if dmDialogs.ColorDialog.Execute then
  112. begin
  113. PanelBackground.Color := dmDialogs.ColorDialog.Color;
  114. FormGLSViewer.ApplyBgColor;
  115. end;
  116. end;
  117. procedure TFormOptions.ButtonOKClick(Sender: TObject);
  118. var
  119. FileName: TFileName;
  120. begin
  121. if CurLangID <> LangID then
  122. begin
  123. MessageDlg(_('Reload to change language'), mtInformation, [mbOK], 0);
  124. FileName := ChangeFileExt(ParamStr(0), '.ini');
  125. if FileExists(UpperCase(FileName)) then
  126. DeleteFile(UpperCase(FileName)); //to exclude dublicated sections for each language
  127. end;
  128. end;
  129. end.