Ignore:
Timestamp:
Dec 4, 2014, 11:26:54 AM (10 years ago)
Author:
chronos
Message:
  • Added: Unit project which should handle all project related operations.
  • Fixed: TScaleDPI to handle also lower then default DPI and different horizontal and vertical DPI.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UScaleDPI.pas

    r59 r61  
    1414  { TScaleDPI }
    1515
    16   TScaleDPI = class
     16  TScaleDPI = class(TComponent)
    1717  private
    1818    FAutoDetect: Boolean;
     
    2727    function ScaleX(Size: Integer; FromDPI: Integer): Integer;
    2828    function ScaleY(Size: Integer; FromDPI: Integer): Integer;
    29     constructor Create;
     29    constructor Create(AOwner: TComponent);
     30  published
    3031    property AutoDetect: Boolean read FAutoDetect write SetAutoDetect;
    3132  end;
    3233
     34procedure Register;
    3335
    3436implementation
     37
     38procedure Register;
     39begin
     40  RegisterComponents('Common', [TScaleDPI]);
     41end;
    3542
    3643procedure TScaleDPI.SetAutoDetect(AValue: Boolean);
     
    5966  I: Integer;
    6067begin
    61   if (DPI.X <= FromDPI.X * 1.1) or (DPI.Y <= FromDPI.Y * 1.1) then Exit;
    62 
    6368  NewWidth := ScaleX(ImgList.Width, FromDPI.X);
    6469  NewHeight := ScaleY(ImgList.Height, FromDPI.Y);
     
    97102function TScaleDPI.ScaleX(Size: Integer; FromDPI: Integer): Integer;
    98103begin
    99   if DPI.X <= FromDPI then
    100     Result := Size
    101   else
    102     Result := MulDiv(Size, DPI.X, FromDPI);
     104  Result := MulDiv(Size, DPI.X, FromDPI);
    103105end;
    104106
    105107function TScaleDPI.ScaleY(Size: Integer; FromDPI: Integer): Integer;
    106108begin
    107   if Screen.PixelsPerInch <= FromDPI then
    108     Result := Size
    109   else
    110     Result := MulDiv(Size, DPI.Y, FromDPI);
     109  Result := MulDiv(Size, DPI.Y, FromDPI);
    111110end;
    112111
     
    117116end;
    118117
    119 constructor TScaleDPI.Create;
     118constructor TScaleDPI.Create(AOwner: TComponent);
    120119begin
     120  inherited;
    121121  DPI := Point(96, 96);
    122122  DesignDPI := Point(96, 96);
     
    129129  ToolBarControl: TToolBar;
    130130begin
    131   if (DPI.X <= FromDPI.X) or (DPI.Y <= FromDPI.Y) then Exit;
    132 
    133131  with Control do begin
    134132    Left := ScaleX(Left, FromDPI.X);
Note: See TracChangeset for help on using the changeset viewer.