Ignore:
Timestamp:
Dec 4, 2023, 12:13:15 PM (13 months ago)
Author:
chronos
Message:
  • Added: Custom DPI configuration in Settings dialog.
  • Fixed: Better High DPI support.
File:
1 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);
Note: See TracChangeset for help on using the changeset viewer.