source: tags/1.3.1/Settings.pas

Last change on this file was 433, checked in by chronos, 3 years ago
  • Fixed: Controls alignment in Settings form under Linux.
File size: 9.4 KB
Line 
1unit Settings;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
7 LCLProc, ScreenTools, Messg, ButtonA, Directories, DrawDlg, ButtonC,
8 UKeyBindings, ULanguages;
9
10type
11 { TSettingsDlg }
12
13 TSettingsDlg = class(TDrawDlg)
14 ButtonFullscreen: TButtonC;
15 Down2Btn: TButtonC;
16 EditShortCutPrimary: TEdit;
17 EditShortCutSecondary: TEdit;
18 ListLanguages: TListBox;
19 ListKeyBindings: TListBox;
20 ButtonOk: TButtonA;
21 ButtonCancel: TButtonA;
22 ButtonReset: TButtonA;
23 Up2Btn: TButtonC;
24 procedure ButtonFullscreenClick(Sender: TObject);
25 procedure ButtonCancelClick(Sender: TObject);
26 procedure ButtonResetClick(Sender: TObject);
27 procedure Down2BtnClick(Sender: TObject);
28 procedure EditShortCutPrimaryKeyUp(Sender: TObject; var Key: Word;
29 Shift: TShiftState);
30 procedure EditShortCutSecondaryKeyUp(Sender: TObject; var Key: Word;
31 Shift: TShiftState);
32 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
33 procedure FormCreate(Sender: TObject);
34 procedure FormDestroy(Sender: TObject);
35 procedure FormPaint(Sender: TObject);
36 procedure FormShow(Sender: TObject);
37 procedure ListKeyBindingsSelectionChange(Sender: TObject; User: Boolean);
38 procedure ButtonOkClick(Sender: TObject);
39 procedure Up2BtnClick(Sender: TObject);
40 private
41 LocalGamma: Integer;
42 LocalKeyBindings: TKeyBindings;
43 CurrentKeyBinding: TKeyBinding;
44 procedure UpdateShortCutItem;
45 public
46 procedure LoadData;
47 procedure SaveData;
48 end;
49
50var
51 SettingsDlg: TSettingsDlg;
52
53
54implementation
55
56{$R *.lfm}
57
58uses
59 Start;
60
61var
62 SFullScreen, SGamma, SRestartMsg, SShortCutPrimary, SShortCutSecondary,
63 SLanguages, SKeyBindings: string;
64
65procedure ReloadLanguages;
66begin
67 SFullScreen := Phrases.Lookup('SETTINGS', 0);
68 SGamma := Phrases.Lookup('SETTINGS', 1);
69 SRestartMsg := Phrases.Lookup('SETTINGS', 2);
70 SShortCutPrimary := Phrases.Lookup('SETTINGS', 3);
71 SShortCutSecondary := Phrases.Lookup('SETTINGS', 4);
72 SLanguages := Phrases.Lookup('SETTINGS', 5);
73 SKeyBindings := Phrases.Lookup('SETTINGS', 6);
74end;
75
76{ TSettingsDlg }
77
78procedure TSettingsDlg.FormCreate(Sender: TObject);
79begin
80 Color := clBlack;
81 LocalKeyBindings := TKeyBindings.Create;
82
83 Canvas.Font.Assign(UniFont[ftNormal]);
84 Canvas.Brush.Style := bsClear;
85
86 ButtonOk.Caption := Phrases.Lookup('BTN_OK');
87 ButtonCancel.Caption := Phrases.Lookup('BTN_CANCEL');
88 ButtonReset.Caption := Phrases.Lookup('BTN_RESET');
89 InitButtons;
90end;
91
92procedure TSettingsDlg.ButtonCancelClick(Sender: TObject);
93begin
94 ModalResult := mrCancel;
95end;
96
97procedure TSettingsDlg.ButtonResetClick(Sender: TObject);
98begin
99 ListLanguages.ItemIndex := 0;
100 ButtonFullscreen.ButtonIndex := 3;
101 LocalGamma := 100;
102 ListKeyBindings.ItemIndex := -1;
103 ListKeyBindingsSelectionChange(nil, False);
104 LocalKeyBindings.ResetToDefault;
105 LocalKeyBindings.LoadToStrings(ListKeyBindings.Items);
106 Repaint;
107end;
108
109procedure TSettingsDlg.Down2BtnClick(Sender: TObject);
110begin
111 if LocalGamma > 50 then
112 begin
113 Dec(LocalGamma);
114 Invalidate;
115 end;
116end;
117
118procedure TSettingsDlg.EditShortCutPrimaryKeyUp(Sender: TObject; var Key: Word;
119 Shift: TShiftState);
120begin
121 if (Sender is TEdit) and Assigned(CurrentKeyBinding) and not (Key in [16..18]) then begin
122 CurrentKeyBinding.ShortCut := Key or
123 (scShift * Integer(ssShift in Shift)) or
124 (scCtrl * Integer(ssCtrl in Shift)) or
125 (scAlt * Integer(ssAlt in Shift));
126 EditShortCutPrimary.Text := ShortCutToText(CurrentKeyBinding.ShortCut);
127 Key := 0;
128 UpdateShortCutItem;
129 end;
130end;
131
132procedure TSettingsDlg.EditShortCutSecondaryKeyUp(Sender: TObject;
133 var Key: Word; Shift: TShiftState);
134begin
135 if (Sender is TEdit) and Assigned(CurrentKeyBinding) and not (Key in [16..18]) then begin
136 CurrentKeyBinding.ShortCut2 := Key or
137 (scShift * Integer(ssShift in Shift)) or
138 (scCtrl * Integer(ssCtrl in Shift)) or
139 (scAlt * Integer(ssAlt in Shift));
140 EditShortCutSecondary.Text := ShortCutToText(CurrentKeyBinding.ShortCut2);
141 Key := 0;
142 UpdateShortCutItem;
143 end;
144end;
145
146procedure TSettingsDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction
147 );
148begin
149 ListKeyBindings.ItemIndex := -1;
150end;
151
152procedure TSettingsDlg.ButtonFullscreenClick(Sender: TObject);
153begin
154 ButtonFullscreen.ButtonIndex := ButtonFullscreen.ButtonIndex xor 1;
155end;
156
157procedure TSettingsDlg.FormDestroy(Sender: TObject);
158begin
159 FreeAndNil(LocalKeyBindings);
160end;
161
162procedure TSettingsDlg.FormPaint(Sender: TObject);
163begin
164 PaintBackground(self, 3, 3, ClientWidth - 6, ClientHeight - 6);
165 Frame(Canvas, 0, 0, ClientWidth - 1, ClientHeight - 1, 0, 0);
166 Frame(Canvas, 1, 1, ClientWidth - 2, ClientHeight - 2,
167 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
168 Frame(Canvas, 2, 2, ClientWidth - 3, ClientHeight - 3,
169 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
170 EditFrame(Canvas, EditShortCutPrimary.BoundsRect, MainTexture);
171 EditFrame(Canvas, EditShortCutSecondary.BoundsRect, MainTexture);
172 EditFrame(Canvas, ListLanguages.BoundsRect, MainTexture);
173 BtnFrame(Canvas, ButtonOk.BoundsRect, MainTexture);
174 BtnFrame(Canvas, ButtonCancel.BoundsRect, MainTexture);
175
176 RFrame(Canvas, ButtonFullscreen.Left - 1, ButtonFullscreen.Top - 1,
177 ButtonFullscreen.Left + 12, ButtonFullscreen.Top + 12, MainTexture.ColorBevelShade,
178 MainTexture.ColorBevelLight);
179
180 LoweredTextOut(Canvas, -2, MainTexture, ListLanguages.Left,
181 ListLanguages.Top - 26, SLanguages);
182 LoweredTextOut(Canvas, -2, MainTexture, ListKeyBindings.Left,
183 ListKeyBindings.Top - 26, SKeyBindings);
184 LoweredTextOut(Canvas, -2, MainTexture, ButtonFullscreen.Left + 32,
185 ButtonFullscreen.Top - 4, SFullScreen);
186 UnderlinedTitleValue(Canvas, SGamma, IntToStr(LocalGamma) + '%',
187 Up2Btn.Left - 150 - 4, Up2Btn.Top + 2, 150);
188 LoweredTextOut(Canvas, -2, MainTexture, EditShortCutPrimary.Left,
189 EditShortCutPrimary.Top - 26, SShortCutPrimary);
190 LoweredTextOut(Canvas, -2, MainTexture, EditShortCutSecondary.Left,
191 EditShortCutSecondary.Top - 26, SShortCutSecondary);
192end;
193
194procedure TSettingsDlg.FormShow(Sender: TObject);
195begin
196 Caption := Phrases2.Lookup('ACTIONHEADER_CONFIG');
197 ReloadLanguages;
198 StartDlg.Translator.LanguageListToStrings(ListLanguages.Items);
199 ListLanguages.Font.Color := MainTexture.ColorMark;
200 ListKeyBindings.Font.Color := MainTexture.ColorMark;
201 LoadData;
202 LocalKeyBindings.LoadToStrings(ListKeyBindings.Items);
203 EditShortCutPrimary.Font.Color := MainTexture.ColorMark;
204 EditShortCutSecondary.Font.Color := MainTexture.ColorMark;
205end;
206
207procedure TSettingsDlg.ListKeyBindingsSelectionChange(Sender: TObject;
208 User: Boolean);
209begin
210 if Assigned(CurrentKeyBinding) then begin
211 CurrentKeyBinding.ShortCut := TextToShortCut(EditShortCutPrimary.Text);
212 CurrentKeyBinding.ShortCut2 := TextToShortCut(EditShortCutSecondary.Text);
213 end;
214
215 if ListKeyBindings.ItemIndex >= 0 then
216 CurrentKeyBinding := LocalKeyBindings[ListKeyBindings.ItemIndex]
217 else CurrentKeyBinding := nil;
218
219 if Assigned(CurrentKeyBinding) then begin
220 if CurrentKeyBinding.ShortCut <> 0 then
221 EditShortCutPrimary.Text := ShortCutToText(CurrentKeyBinding.ShortCut)
222 else EditShortCutPrimary.Text := '';
223 EditShortCutPrimary.Enabled := True;
224 if CurrentKeyBinding.ShortCut2 <> 0 then
225 EditShortCutSecondary.Text := ShortCutToText(CurrentKeyBinding.ShortCut2)
226 else EditShortCutSecondary.Text := '';
227 EditShortCutSecondary.Enabled := True;
228 end else begin
229 EditShortCutPrimary.Text := '';
230 EditShortCutPrimary.Enabled := False;
231 EditShortCutSecondary.Text := '';
232 EditShortCutSecondary.Enabled := False;
233 end;
234end;
235
236procedure TSettingsDlg.ButtonOkClick(Sender: TObject);
237begin
238 SaveData;
239 ModalResult := mrOk;
240end;
241
242procedure TSettingsDlg.Up2BtnClick(Sender: TObject);
243begin
244 if LocalGamma < 150 then begin
245 Inc(LocalGamma);
246 Invalidate;
247 end;
248end;
249
250procedure TSettingsDlg.UpdateShortCutItem;
251begin
252 if Assigned(CurrentKeyBinding) then begin
253 if CurrentKeyBinding.ShortCut > 0 then
254 LocalKeyBindings.RemoveShortCut(CurrentKeyBinding.ShortCut);
255 if CurrentKeyBinding.ShortCut2 > 0 then
256 LocalKeyBindings.RemoveShortCut(CurrentKeyBinding.ShortCut2);
257 CurrentKeyBinding.ShortCut := TextToShortCut(EditShortCutPrimary.Text);
258 CurrentKeyBinding.ShortCut2 := TextToShortCut(EditShortCutSecondary.Text);
259 LocalKeyBindings.LoadToStrings(ListKeyBindings.Items);
260 end;
261end;
262
263procedure TSettingsDlg.LoadData;
264begin
265 StartDlg.Translator.Language := StartDlg.Translator.Languages.SearchByCode(LocaleCode);
266 StartDlg.Translator.LanguageListToStrings(ListLanguages.Items, False);
267 ListLanguages.ItemIndex := ListLanguages.Items.IndexOfObject(StartDlg.Translator.Language);
268 if ListLanguages.ItemIndex = -1 then ListLanguages.ItemIndex := 0;
269 if FullScreen then ButtonFullscreen.ButtonIndex := 3
270 else ButtonFullscreen.ButtonIndex := 2;
271 LocalGamma := Gamma;
272 LocalKeyBindings.Assign(KeyBindings);
273end;
274
275procedure TSettingsDlg.SaveData;
276var
277 NeedRestart: Boolean;
278begin
279 NeedRestart := Gamma <> LocalGamma;
280 if ListLanguages.ItemIndex <> -1 then begin
281 StartDlg.Translator.Language := TLanguage(ListLanguages.Items.Objects[ListLanguages.ItemIndex]);
282 LocaleCode := StartDlg.Translator.Language.Code;
283 end else begin
284 StartDlg.Translator.Language := nil;
285 LocaleCode := '';
286 end;
287 FullScreen := (ButtonFullscreen.ButtonIndex and 1) = 1;
288 Gamma := LocalGamma;
289 if NeedRestart then SimpleMessage(SRestartMsg);
290 KeyBindings.Assign(LocalKeyBindings);
291end;
292
293end.
294
Note: See TracBrowser for help on using the repository browser.