Changeset 88 for trunk/UCore.pas


Ignore:
Timestamp:
Aug 29, 2017, 10:33:39 PM (7 years ago)
Author:
chronos
Message:
  • Modified: Enabled DPI scaling.
  • Modified: Moved ImageListMain to Core unit and introduced Core Init method.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r87 r88  
    77uses
    88  Classes, SysUtils, FileUtil, UApplicationInfo, ULastOpenedList, UProject,
    9   UCoolTranslator, UTarget, URegistry, Registry, Graphics, UScaleDPI,
     9  UCoolTranslator, UTarget, URegistry, Registry, Graphics, Controls, UScaleDPI,
    1010  UPersistentForm;
    1111
     
    1717    ApplicationInfo: TApplicationInfo;
    1818    CoolTranslator1: TCoolTranslator;
     19    ImageListMain: TImageList;
    1920    LastOpenedList: TLastOpenedList;
    2021    PersistentForm1: TPersistentForm;
     22    ScaleDPI1: TScaleDPI;
    2123    procedure DataModuleCreate(Sender: TObject);
    2224    procedure DataModuleDestroy(Sender: TObject);
    2325  private
    2426    FCurrentTarget: TTarget;
     27    StoredDimension: TControlDimension;
    2528    procedure SetCurrentTarget(AValue: TTarget);
     29    procedure ScaleDPI;
    2630  public
    27     ScaleDPI: TScaleDPI;
    2831    Project: TProject;
    2932    Targets: TTargetList;
     
    3235    CellSize: Integer;
    3336    MemorySize: Integer;
     37    procedure Init;
    3438    procedure LoadFromRegistry(Root: HKEY; Key: string);
    3539    procedure SaveToRegistry(Root: HKEY; Key: string);
     
    5963begin
    6064  Project := TProject.Create;
    61   ScaleDPI := TScaleDPI.Create(nil);
    6265  Targets := TTargetList.Create;
     66  StoredDimension := TControlDimension.Create;
     67
    6368  // Init targets list
    6469  Targets.Add(TTargetInterpretter.Create);
     
    8388begin
    8489  SaveToRegistry(HKEY(ApplicationInfo.RegistryRoot), ApplicationInfo.RegistryKey);
    85   Targets.Free;
    86   Project.Free;
    87   ScaleDPI.Free;
     90  FreeAndNil(Targets);
     91  FreeAndNil(Project);
     92  FreeAndNil(StoredDimension);
    8893end;
    8994
     
    98103      CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''))
    99104      else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('');
    100     ScaleDPI.DPI := Point(ReadIntegerWithDefault('DPIX', 96),
     105    ScaleDPI1.DPI := Point(ReadIntegerWithDefault('DPIX', 96),
    101106      ReadIntegerWithDefault('DPIY', 96));
    102     ScaleDPI.AutoDetect := ReadBoolWithDefault('DPIAuto', True);
     107    ScaleDPI1.AutoDetect := ReadBoolWithDefault('DPIAuto', True);
    103108    OptimizationLevel := TCompilerOptimization(ReadIntegerWithDefault('OptimizationLevel', Integer(coNormal)));
    104109    MemorySize := ReadIntegerWithDefault('MemorySize', 30000);
     
    121126    OpenKey(Key, True);
    122127    WriteBool('OpenProjectOnStart', OpenProjectOnStart);
    123     WriteBool('DPIAuto', ScaleDPI.AutoDetect);
    124     WriteInteger('DPIX', ScaleDPI.DPI.X);
    125     WriteInteger('DPIY', ScaleDPI.DPI.Y);
     128    WriteBool('DPIAuto', ScaleDPI1.AutoDetect);
     129    WriteInteger('DPIX', ScaleDPI1.DPI.X);
     130    WriteInteger('DPIY', ScaleDPI1.DPI.Y);
    126131    WriteInteger('OptimizationLevel', Integer(OptimizationLevel));
    127132    WriteInteger('MemorySize', MemorySize);
     
    157162end;
    158163
     164procedure TCore.ScaleDPI;
     165var
     166  I: Integer;
     167begin
     168  with ScaleDPI1 do begin
     169    //DesignDPI := Point(144, 144);
     170    if (DesignDPI.X <> DPI.X) or (DesignDPI.Y <> DPI.Y) then begin
     171      //ApplyToAll(DesignDPI);
     172      for I := 0 to Screen.FormCount - 1 do
     173      if (Screen.Forms[I].WindowState = wsNormal) or
     174        (Screen.Forms[I].WindowState = wsMinimized) then begin
     175        StoreDimensions(Screen.Forms[I], StoredDimension);
     176        ScaleDimensions(Screen.Forms[I], StoredDimension);
     177      end;
     178      ScaleImageList(ImageListMain, DesignDPI);
     179    end;
     180  end;
     181end;
     182
     183procedure TCore.Init;
     184begin
     185  ScaleDPI;
     186  CoolTranslator1.Translate;
     187end;
    159188
    160189end.
Note: See TracChangeset for help on using the changeset viewer.