Changeset 546


Ignore:
Timestamp:
Apr 20, 2024, 6:20:48 PM (7 months ago)
Author:
chronos
Message:
  • Modified: Optimized scaling functions.
Location:
trunk/Packages/DpiControls
Files:
2 edited

Legend:

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

    r545 r546  
    248248function ScaleToNative(Value: Integer): Integer;
    249249begin
    250   Result := Ceil(Value * ScreenInfo.Dpi / 96);
     250  Result := Ceil(Value * ScreenInfo.ToNative);
    251251end;
    252252
     
    258258function ScaleFromNative(Value: Integer): Integer;
    259259begin
    260   Result := Floor(Value * 96 / ScreenInfo.Dpi);
     260  Result := Floor(Value * ScreenInfo.FromNative);
    261261end;
    262262
     
    303303function ScaleFloatToNative(Value: Double): Double;
    304304begin
    305   Result := Value * ScreenInfo.Dpi / 96;
     305  Result := Value * ScreenInfo.ToNative;
    306306end;
    307307
    308308function ScaleFloatFromNative(Value: Double): Double;
    309309begin
    310   Result := Value * 96 / ScreenInfo.Dpi;
     310  Result := Value * ScreenInfo.FromNative;
    311311end;
    312312
  • trunk/Packages/DpiControls/Dpi.Graphics.pas

    r538 r546  
    340340  end;
    341341
     342  { TScreenInfo }
     343
    342344  TScreenInfo = record
    343     Dpi: Integer;
     345  private
     346    FDpi: Integer;
     347    procedure SetDpi(AValue: Integer);
     348  public
     349    ToNative: Double;
     350    FromNative: Double;
     351    property Dpi: Integer read FDpi write SetDpi;
    344352  end;
    345353
     
    13251333end;
    13261334
     1335{ TScreenInfo }
     1336
     1337procedure TScreenInfo.SetDpi(AValue: Integer);
     1338begin
     1339  if FDpi = AValue then Exit;
     1340  FDpi := AValue;
     1341  ToNative := ScreenInfo.Dpi / 96;
     1342  FromNative := 96 / ScreenInfo.Dpi;
     1343end;
     1344
    13271345{ TPortableNetworkGraphic }
    13281346
Note: See TracChangeset for help on using the changeset viewer.