Ignore:
Timestamp:
Jan 6, 2024, 12:07:04 AM (11 months ago)
Author:
chronos
Message:
  • Fixed: Make fractional scaling work also on Windows.
  • Modified: By default use system DPI setting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/DpiControls/Dpi.Common.pas

    r516 r518  
    186186  SrcWidth, SrcHeight: Integer;
    187187begin
    188   {$IFDEF WINDOWS}
    189   // LCLIntf.BitBlt is slower than direct Windows BitBlt
    190   Result := Windows.BitBlt(DestDC, ScaleToNative(X), ScaleToNative(Y),
    191     ScaleToNative(Width), ScaleToNative(Height), SrcDC,
    192     ScaleToNative(XSrc), ScaleToNative(YSrc), Rop);
    193   {$ELSE}
    194 
    195188  DstWidth := ScaleToNativeDist(X, Width);
    196189  DstHeight := ScaleToNativeDist(Y, Height);
    197190  SrcWidth := ScaleToNativeDist(XSrc, Width);
    198191  SrcHeight := ScaleToNativeDist(YSrc, Height);
     192
    199193  if (DstWidth = SrcWidth) and (DstHeight = SrcHeight) then begin
     194    {$IFDEF WINDOWS}
     195    // On Windows LCLIntf.BitBlt is slower than direct Windows BitBlt
     196    Result := Windows.BitBlt(DestDC, ScaleToNative(X), ScaleToNative(Y),
     197      DstWidth, DstHeight, SrcDC,
     198      ScaleToNative(XSrc), ScaleToNative(YSrc), Rop);
     199    {$ELSE}
    200200    Result := LCLIntf.BitBlt(DestDC, ScaleToNative(X), ScaleToNative(Y),
    201201      DstWidth, DstHeight, SrcDC,
    202202      ScaleToNative(XSrc), ScaleToNative(YSrc), Rop);
     203    {$ENDIF}
    203204  end else begin
     205    {$IFDEF WINDOWS}
     206    // On Windows LCLIntf.BitBlt is slower than direct Windows BitBlt
     207    Result := Windows.BitBlt(DestDC, ScaleToNative(X), ScaleToNative(Y),
     208      Min(SrcWidth, DstWidth), Min(DstHeight, SrcHeight), SrcDC,
     209      ScaleToNative(XSrc), ScaleToNative(YSrc), Rop);
     210
     211    // Instead calling StretchBlt for entire region try to draw missing part with BitBlt
     212    if DstWidth > SrcWidth then begin
     213      Windows.BitBlt(DestDC, ScaleToNative(X) + SrcWidth, ScaleToNative(Y),
     214        DstWidth - SrcWidth, DstHeight, SrcDC,
     215        ScaleToNative(XSrc) + SrcWidth - (DstWidth - SrcWidth), ScaleToNative(YSrc), Rop);
     216    end;
     217    if DstHeight > SrcHeight then begin
     218      Windows.BitBlt(DestDC, ScaleToNative(X), ScaleToNative(Y) + SrcHeight,
     219        DstWidth, DstHeight - SrcHeight, SrcDC,
     220        ScaleToNative(XSrc), ScaleToNative(YSrc) + SrcHeight - (DstHeight - SrcHeight), Rop);
     221    end;
     222    {$ELSE}
    204223    Result := LCLIntf.BitBlt(DestDC, ScaleToNative(X), ScaleToNative(Y),
    205       SrcWidth, SrcHeight, SrcDC,
     224      Min(SrcWidth, DstWidth), Min(DstHeight, SrcHeight), SrcDC,
    206225      ScaleToNative(XSrc), ScaleToNative(YSrc), Rop);
    207226
     
    217236        ScaleToNative(XSrc), ScaleToNative(YSrc) + SrcHeight - (DstHeight - SrcHeight), Rop);
    218237    end;
    219   {  Result := LCLIntf.StretchBlt(DestDC, ScaleToNative(X), ScaleToNative(Y),
    220       DstWidth, DstHeight, SrcDC,
    221       ScaleToNative(XSrc), ScaleToNative(YSrc),
    222       SrcWidth, SrcHeight, Rop);}
     238    {$ENDIF}
    223239  end;
    224 
    225 {  Result := LCLIntf.BitBlt(DestDC, ScaleToNative(X), ScaleToNative(Y),
    226     ScaleToNative(Width), ScaleToNative(Height), SrcDC,
    227     ScaleToNative(XSrc), ScaleToNative(YSrc), Rop);
    228  }
    229   {$ENDIF}
    230240end;
    231241
Note: See TracChangeset for help on using the changeset viewer.