Changeset 473 for trunk/Packages


Ignore:
Timestamp:
Dec 4, 2023, 12:13:15 PM (12 months ago)
Author:
chronos
Message:
  • Added: Custom DPI configuration in Settings dialog.
  • Fixed: Better High DPI support.
Location:
trunk/Packages
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/CevoComponents/ScreenTools.pas

    r468 r473  
    104104procedure UnshareBitmap(Bitmap: TBitmap);
    105105procedure Gtk2Fix;
     106procedure LoadConfig(Key: string);
     107procedure SaveConfig(Key: string);
    106108
    107109const
     
    193195  UniFont: array [TFontType] of TFont;
    194196  Gamma: Integer; // global gamma correction (cent)
     197  CustomDpiEnabled: Boolean;
     198  CustomDpi: Integer;
    195199
    196200procedure LoadAssets;
     
    204208uses
    205209  {$IFDEF DPI}Dpi.PixelPointer,{$ELSE}PixelPointer,{$ENDIF}
    206   Directories, Sound;
     210  Directories, Sound, Registry;
    207211
    208212var
     
    15501554procedure PaintLogo(Canvas: TCanvas; X, Y, LightColor, ShadeColor: Integer);
    15511555begin
     1556  if not Assigned(LogoBuffer) then Exit;
    15521557  UnshareBitmap(LogoBuffer);
    15531558  BitBltCanvas(LogoBuffer.Canvas, 0, 0, Logo.Width, Logo.Height, Canvas, X, Y);
     
    17321737end;
    17331738
     1739procedure LoadConfig(Key: string);
     1740var
     1741  Reg: TRegistry;
     1742begin
     1743  Reg := TRegistry.Create;
     1744  with Reg do try
     1745    OpenKey(Key, True);
     1746    if ValueExists('Gamma') then Gamma := ReadInteger('Gamma')
     1747      else Gamma := 100;
     1748    if Gamma <> 100 then InitGammaLookupTable;
     1749    if ValueExists('CustomDpiEnabled') then CustomDpiEnabled := Reg.ReadBool('CustomDpiEnabled')
     1750       else CustomDpiEnabled := False;
     1751    if ValueExists('CustomDpi') then CustomDpi := Reg.ReadInteger('CustomDpi')
     1752       else CustomDpi := 96;
     1753    {$IFDEF DPI}
     1754    if CustomDpiEnabled then Screen.Dpi := CustomDpi
     1755      else Screen.Dpi := Screen.GetSystemDpi;
     1756    {$ENDIF}
     1757  finally
     1758    Reg.Free;
     1759  end;
     1760end;
     1761
     1762procedure SaveConfig(Key: string);
     1763var
     1764  Reg: TRegistry;
     1765begin
     1766  Reg := TRegistry.Create;
     1767  with Reg do try
     1768    OpenKey(Key, True);
     1769    WriteInteger('Gamma', Gamma);
     1770    WriteBool('CustomDpiEnabled', CustomDpiEnabled);
     1771    WriteInteger('CustomDpi', CustomDpi);
     1772  finally
     1773    Free;
     1774  end;
     1775end;
     1776
    17341777procedure LoadAssets;
    17351778begin
     
    17521795  end;
    17531796
     1797  LogoBuffer := TBitmap.Create;
     1798  LogoBuffer.PixelFormat := TPixelFormat.pf24bit;
     1799  LogoBuffer.SetSize(BigBook.Width, BigBook.Height);
     1800
    17541801  LoadGraphicFile(Colors, GetGraphicsDir + DirectorySeparator + 'Colors.png');
    17551802  LoadGraphicFile(Paper, GetGraphicsDir + DirectorySeparator + 'Paper.jpg');
     
    18011848
    18021849  LoadAssets;
    1803 
    1804   LogoBuffer := TBitmap.Create;
    1805   LogoBuffer.PixelFormat := TPixelFormat.pf24bit;
    1806   LogoBuffer.SetSize(BigBook.Width, BigBook.Height);
    18071850end;
    18081851
     
    18141857  FreeAndNil(Phrases);
    18151858  FreeAndNil(Phrases2);
    1816   FreeAndNil(LogoBuffer);
     1859  if Assigned(LogoBuffer) then FreeAndNil(LogoBuffer);
    18171860  FreeAndNil(BigImp);
    18181861  FreeAndNil(Paper);
  • trunk/Packages/DpiControls/Dpi.Common.pas

    r468 r473  
    77
    88const
    9   FixedDpi = 2*96;
    109  DpiControlsComponentPaletteName = 'DpiControls';
    1110
  • trunk/Packages/DpiControls/Dpi.Forms.pas

    r468 r473  
    228228    constructor Create;
    229229    destructor Destroy; override;
    230     procedure UpdateScreen;
    231230    procedure UpdateActiveFormFromNativeScreen;
    232231    function DisableForms(SkipForm: TForm; DisabledList: Classes.TList = nil): Classes.TList;
    233232    procedure EnableForms(var AFormList: Classes.TList);
     233    function GetSystemDpi: Integer;
    234234    property FormCount: Integer read GetFormCount;
    235235    property Forms[Index: Integer]: TForm read GetForms;
     
    400400begin
    401401  GetNativeApplication.Initialize;
    402   Screen.UpdateScreen;
    403402end;
    404403
     
    442441      FCreatingForm := TForm(Instance);
    443442    Instance.Create(Self);
    444     Ok := true;
     443    Ok := True;
    445444  finally
    446445    if not Ok then begin
     
    978977end;
    979978
     979function TScreen.GetSystemDpi: Integer;
     980begin
     981  Result := LCLScreen.PixelsPerInch;
     982end;
     983
    980984constructor TScreen.Create;
    981985begin
     
    993997  FreeAndNil(FPrevActiveForms);
    994998  inherited;
    995 end;
    996 
    997 procedure TScreen.UpdateScreen;
    998 begin
    999   if FixedDpi = -1 then Dpi := LCLScreen.PixelsPerInch
    1000     else Dpi := FixedDpi;
    1001999end;
    10021000
Note: See TracChangeset for help on using the changeset viewer.