Changeset 405 for branches/highdpi/Settings.pas
- Timestamp:
- Nov 3, 2021, 11:22:02 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Settings.pas
r361 r405 7 7 uses 8 8 UDpiControls, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ScreenTools, Messg, ButtonA, Registry, fgl, Directories, DrawDlg, ButtonC; 9 LCLProc, ScreenTools, Messg, ButtonA, Registry, fgl, Directories, DrawDlg, 10 ButtonC, UKeyBindings, ULanguages; 10 11 11 12 type 12 TLanguage = class13 ShortName: string;14 FullName: string;15 Author: string;16 end;17 18 { TLanguages }19 20 TLanguages = class(TFPGObjectList<TLanguage>)21 procedure AddItem(const ShortName, FullName: string);22 procedure LoadToStrings(Strings: TStrings);23 function Search(ShortName: string): Integer;24 end;25 26 13 { TSettingsDlg } 27 14 … … 29 16 ButtonFullscreen: TButtonC; 30 17 Down2Btn: TButtonC; 31 List: TDpiListBox; 32 OKBtn: TButtonA; 33 CancelBtn: TButtonA; 18 EditShortCutPrimary: TDpiEdit; 19 EditShortCutSecondary: TDpiEdit; 20 ListLanguages: TDpiListBox; 21 ListKeyBindings: TDpiListBox; 22 ButtonOk: TButtonA; 23 ButtonCancel: TButtonA; 24 ButtonReset: TButtonA; 34 25 Up2Btn: TButtonC; 35 26 procedure ButtonFullscreenClick(Sender: TObject); 36 procedure CancelBtnClick(Sender: TObject); 27 procedure ButtonCancelClick(Sender: TObject); 28 procedure ButtonResetClick(Sender: TObject); 37 29 procedure Down2BtnClick(Sender: TObject); 30 procedure EditShortCutPrimaryKeyUp(Sender: TObject; var Key: Word; 31 Shift: TShiftState); 32 procedure EditShortCutSecondaryKeyUp(Sender: TObject; var Key: Word; 33 Shift: TShiftState); 34 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 38 35 procedure FormCreate(Sender: TObject); 39 36 procedure FormDestroy(Sender: TObject); 40 37 procedure FormPaint(Sender: TObject); 41 38 procedure FormShow(Sender: TObject); 42 procedure OKBtnClick(Sender: TObject); 39 procedure ListKeyBindingsSelectionChange(Sender: TObject; User: boolean); 40 procedure ButtonOkClick(Sender: TObject); 43 41 procedure Up2BtnClick(Sender: TObject); 44 42 private 45 43 LocalGamma: Integer; 44 LocalKeyBindings: TKeyBindings; 45 CurrentKeyBinding: TKeyBinding; 46 procedure UpdateShortCutItem; 46 47 public 47 Languages: TLanguages;48 48 procedure LoadData; 49 49 procedure SaveData; … … 53 53 SettingsDlg: TSettingsDlg; 54 54 55 55 56 implementation 56 57 57 58 {$R *.lfm} 58 59 59 { TLanguages }60 61 procedure TLanguages.AddItem(const ShortName, FullName: string);62 60 var 63 Language: TLanguage; 64 begin 65 Language := TLanguage.Create; 66 Language.ShortName := ShortName; 67 Language.FullName := FullName; 68 Add(Language); 69 end; 70 71 procedure TLanguages.LoadToStrings(Strings: TStrings); 72 var 73 I: Integer; 74 begin 75 Strings.Clear; 76 for I := 0 to Count - 1 do 77 Strings.Add(Items[I].FullName); 78 end; 79 80 function TLanguages.Search(ShortName: string): Integer; 81 var 82 I: Integer; 83 begin 84 I := 0; 85 while (I < Count) and (Items[I].ShortName <> ShortName) do Inc(I); 86 if I < Count then Result := I 87 else Result := -1; 61 SFullScreen, SGamma, SRestartMsg, SShortCutPrimary, SShortCutSecondary, 62 SLanguages, SKeyBindings: string; 63 64 procedure ReloadLanguages; 65 begin 66 SFullScreen := Phrases.Lookup('SETTINGS', 0); 67 SGamma := Phrases.Lookup('SETTINGS', 1); 68 SRestartMsg := Phrases.Lookup('SETTINGS', 2); 69 SShortCutPrimary := Phrases.Lookup('SETTINGS', 3); 70 SShortCutSecondary := Phrases.Lookup('SETTINGS', 4); 71 SLanguages := Phrases.Lookup('SETTINGS', 5); 72 SKeyBindings := Phrases.Lookup('SETTINGS', 6); 88 73 end; 89 74 … … 92 77 procedure TSettingsDlg.FormCreate(Sender: TObject); 93 78 begin 79 LocalKeyBindings := TKeyBindings.Create; 80 94 81 Canvas.Font.Assign(UniFont[ftNormal]); 95 82 Canvas.Brush.Style := bsClear; 96 83 97 Languages := TLanguages.Create; 98 Languages.AddItem('', 'System'); 99 Languages.AddItem('cs', 'Czech'); 100 Languages.AddItem('de', 'German'); 101 Languages.AddItem('en', 'English'); 102 Languages.AddItem('it', 'Italian'); 103 Languages.AddItem('ru', 'Russian'); 104 Languages.AddItem('zh-Hant', 'Traditional Chinese'); 105 Languages.AddItem('zh-Hans', 'Simplified Chinese'); 106 107 OKBtn.Caption := Phrases.Lookup('BTN_OK'); 108 CancelBtn.Caption := Phrases.Lookup('BTN_CANCEL'); 84 ButtonOk.Caption := Phrases.Lookup('BTN_OK'); 85 ButtonCancel.Caption := Phrases.Lookup('BTN_CANCEL'); 86 ButtonReset.Caption := Phrases.Lookup('BTN_RESET'); 109 87 InitButtons; 110 88 end; 111 89 112 procedure TSettingsDlg. CancelBtnClick(Sender: TObject);90 procedure TSettingsDlg.ButtonCancelClick(Sender: TObject); 113 91 begin 114 92 ModalResult := mrCancel; 93 end; 94 95 procedure TSettingsDlg.ButtonResetClick(Sender: TObject); 96 begin 97 ListLanguages.ItemIndex := 0; 98 ButtonFullscreen.ButtonIndex := 3; 99 LocalGamma := 100; 100 ListKeyBindings.ItemIndex := -1; 101 ListKeyBindingsSelectionChange(nil, False); 102 LocalKeyBindings.ResetToDefault; 103 LocalKeyBindings.LoadToStrings(ListKeyBindings.Items); 104 Repaint; 115 105 end; 116 106 … … 124 114 end; 125 115 116 procedure TSettingsDlg.EditShortCutPrimaryKeyUp(Sender: TObject; var Key: Word; 117 Shift: TShiftState); 118 begin 119 if Assigned(CurrentKeyBinding) and not (Key in [16..18]) then begin 120 CurrentKeyBinding.ShortCut := Key or 121 (scShift * Integer(ssShift in Shift)) or 122 (scCtrl * Integer(ssCtrl in Shift)) or 123 (scAlt * Integer(ssAlt in Shift)); 124 EditShortCutPrimary.Text := ShortCutToText(CurrentKeyBinding.ShortCut); 125 Key := 0; 126 UpdateShortCutItem; 127 end; 128 end; 129 130 procedure TSettingsDlg.EditShortCutSecondaryKeyUp(Sender: TObject; 131 var Key: Word; Shift: TShiftState); 132 begin 133 if Assigned(CurrentKeyBinding) and not (Key in [16..18]) then begin 134 CurrentKeyBinding.ShortCut2 := Key or 135 (scShift * Integer(ssShift in Shift)) or 136 (scCtrl * Integer(ssCtrl in Shift)) or 137 (scAlt * Integer(ssAlt in Shift)); 138 EditShortCutSecondary.Text := ShortCutToText(CurrentKeyBinding.ShortCut2); 139 Key := 0; 140 UpdateShortCutItem; 141 end; 142 end; 143 144 procedure TSettingsDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction 145 ); 146 begin 147 ListKeyBindings.ItemIndex := -1; 148 end; 149 126 150 procedure TSettingsDlg.ButtonFullscreenClick(Sender: TObject); 127 151 begin … … 131 155 procedure TSettingsDlg.FormDestroy(Sender: TObject); 132 156 begin 133 FreeAndNil(L anguages);157 FreeAndNil(LocalKeyBindings); 134 158 end; 135 159 136 160 procedure TSettingsDlg.FormPaint(Sender: TObject); 137 var138 S: string;139 161 begin 140 162 PaintBackground(self, 3, 3, ClientWidth - 6, ClientHeight - 6); … … 144 166 Frame(Canvas, 2, 2, ClientWidth - 3, ClientHeight - 3, 145 167 MainTexture.ColorBevelLight, MainTexture.ColorBevelShade); 146 EditFrame(Canvas, List .BoundsRect, MainTexture);147 BtnFrame(Canvas, OKBtn.BoundsRect, MainTexture);148 BtnFrame(Canvas, CancelBtn.BoundsRect, MainTexture);168 EditFrame(Canvas, ListLanguages.BoundsRect, MainTexture); 169 BtnFrame(Canvas, ButtonOk.BoundsRect, MainTexture); 170 BtnFrame(Canvas, ButtonCancel.BoundsRect, MainTexture); 149 171 150 172 RFrame(Canvas, ButtonFullscreen.Left - 1, ButtonFullscreen.Top - 1, … … 152 174 MainTexture.ColorBevelLight); 153 175 154 S := Phrases.Lookup('SETTINGS', 0); 176 LoweredTextOut(Canvas, -2, MainTexture, ListLanguages.Left, 177 ListLanguages.Top - 26, SLanguages); 178 LoweredTextOut(Canvas, -2, MainTexture, ListKeyBindings.Left, 179 ListKeyBindings.Top - 26, SKeyBindings); 155 180 LoweredTextOut(Canvas, -2, MainTexture, ButtonFullscreen.Left + 32, 156 ButtonFullscreen.Top - 4, S); 157 158 // Gamma 159 UnderlinedTitleValue(Canvas, Phrases.Lookup('SETTINGS', 1), IntToStr(LocalGamma) + '%', 181 ButtonFullscreen.Top - 4, SFullScreen); 182 UnderlinedTitleValue(Canvas, SGamma, IntToStr(LocalGamma) + '%', 160 183 Up2Btn.Left - 150 - 4, Up2Btn.Top + 2, 150); 184 LoweredTextOut(Canvas, -2, MainTexture, EditShortCutPrimary.Left, 185 EditShortCutPrimary.Top - 26, SShortCutPrimary); 186 LoweredTextOut(Canvas, -2, MainTexture, EditShortCutSecondary.Left, 187 EditShortCutSecondary.Top - 26, SShortCutSecondary); 161 188 end; 162 189 163 190 procedure TSettingsDlg.FormShow(Sender: TObject); 164 191 begin 165 Languages.LoadToStrings(List.Items); 166 List.Font.Color := MainTexture.ColorMark; 192 ReloadLanguages; 193 Languages.LoadToStrings(ListLanguages.Items); 194 ListLanguages.Font.Color := MainTexture.ColorMark; 195 ListKeyBindings.Font.Color := MainTexture.ColorMark; 167 196 LoadData; 168 end; 169 170 procedure TSettingsDlg.OKBtnClick(Sender: TObject); 197 LocalKeyBindings.LoadToStrings(ListKeyBindings.Items); 198 end; 199 200 procedure TSettingsDlg.ListKeyBindingsSelectionChange(Sender: TObject; 201 User: boolean); 202 begin 203 if Assigned(CurrentKeyBinding) then begin 204 CurrentKeyBinding.ShortCut := TextToShortCut(EditShortCutPrimary.Text); 205 CurrentKeyBinding.ShortCut2 := TextToShortCut(EditShortCutSecondary.Text); 206 end; 207 208 if ListKeyBindings.ItemIndex >= 0 then 209 CurrentKeyBinding := LocalKeyBindings[ListKeyBindings.ItemIndex] 210 else CurrentKeyBinding := nil; 211 212 if Assigned(CurrentKeyBinding) then begin 213 if CurrentKeyBinding.ShortCut <> 0 then 214 EditShortCutPrimary.Text := ShortCutToText(CurrentKeyBinding.ShortCut) 215 else EditShortCutPrimary.Text := ''; 216 EditShortCutPrimary.Enabled := True; 217 if CurrentKeyBinding.ShortCut2 <> 0 then 218 EditShortCutSecondary.Text := ShortCutToText(CurrentKeyBinding.ShortCut2) 219 else EditShortCutSecondary.Text := ''; 220 EditShortCutSecondary.Enabled := True; 221 end else begin 222 EditShortCutPrimary.Text := ''; 223 EditShortCutPrimary.Enabled := False; 224 EditShortCutSecondary.Text := ''; 225 EditShortCutSecondary.Enabled := False; 226 end; 227 end; 228 229 procedure TSettingsDlg.ButtonOkClick(Sender: TObject); 171 230 begin 172 231 SaveData; … … 182 241 end; 183 242 243 procedure TSettingsDlg.UpdateShortCutItem; 244 begin 245 if Assigned(CurrentKeyBinding) then begin 246 if CurrentKeyBinding.ShortCut > 0 then 247 LocalKeyBindings.RemoveShortCut(CurrentKeyBinding.ShortCut); 248 if CurrentKeyBinding.ShortCut2 > 0 then 249 LocalKeyBindings.RemoveShortCut(CurrentKeyBinding.ShortCut2); 250 CurrentKeyBinding.ShortCut := TextToShortCut(EditShortCutPrimary.Text); 251 CurrentKeyBinding.ShortCut2 := TextToShortCut(EditShortCutSecondary.Text); 252 LocalKeyBindings.LoadToStrings(ListKeyBindings.Items); 253 end; 254 end; 255 184 256 procedure TSettingsDlg.LoadData; 185 257 begin 186 List .ItemIndex := Languages.Search(LocaleCode);187 if (List .ItemIndex = -1) and (Languages.Count > 0) then188 List .ItemIndex := 0;258 ListLanguages.ItemIndex := Languages.Search(LocaleCode); 259 if (ListLanguages.ItemIndex = -1) and (Languages.Count > 0) then 260 ListLanguages.ItemIndex := 0; 189 261 if FullScreen then ButtonFullscreen.ButtonIndex := 3 190 262 else ButtonFullscreen.ButtonIndex := 2; 191 263 LocalGamma := Gamma; 264 LocalKeyBindings.Assign(KeyBindings); 192 265 end; 193 266 … … 197 270 begin 198 271 NeedRestart := Gamma <> LocalGamma; 199 LocaleCode := Languages[List .ItemIndex].ShortName;272 LocaleCode := Languages[ListLanguages.ItemIndex].ShortName; 200 273 FullScreen := (ButtonFullscreen.ButtonIndex and 1) = 1; 201 274 Gamma := LocalGamma; 202 if NeedRestart then SimpleMessage(Phrases.Lookup('SETTINGS', 2)); 275 if NeedRestart then SimpleMessage(SRestartMsg); 276 KeyBindings.Assign(LocalKeyBindings); 203 277 end; 204 278
Note:
See TracChangeset
for help on using the changeset viewer.