Changeset 467


Ignore:
Timestamp:
Dec 4, 2014, 5:19:20 PM (10 years ago)
Author:
chronos
Message:
  • Fixed: TScaleDPI can now also use lower DPI then original.
  • Fixed: TScaleDPI DPI can be different for horizontal and vertical direction.
  • Modified: Register TScaleDPI as design component to Common group.
Location:
Common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Common/Common.lpk

    r463 r467  
    1212        <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
    1313      </SearchPaths>
    14       <Other>
    15         <CompilerMessages>
    16           <UseMsgFile Value="True"/>
    17         </CompilerMessages>
    18         <CompilerPath Value="$(CompPath)"/>
    19       </Other>
    2014    </CompilerOptions>
    2115    <Description Value="Various libraries"/>
    2216    <License Value="GNU/GPL"/>
    2317    <Version Minor="7"/>
    24     <Files Count="19">
     18    <Files Count="20">
    2519      <Item1>
    2620        <Filename Value="StopWatch.pas"/>
     
    106100        <UnitName Value="UFindFile"/>
    107101      </Item19>
     102      <Item20>
     103        <Filename Value="UScaleDPI.pas"/>
     104        <HasRegisterProc Value="True"/>
     105        <UnitName Value="UScaleDPI"/>
     106      </Item20>
    108107    </Files>
    109108    <i18n>
  • Common/Common.pas

    r463 r467  
    1111  UMemory, UResetableThread, UPool, ULastOpenedList, URegistry,
    1212  UJobProgressView, UXMLUtils, UApplicationInfo, USyncCounter, UListViewSort,
    13   UPersistentForm, UFindFile, LazarusPackageIntf;
     13  UPersistentForm, UFindFile, UScaleDPI, LazarusPackageIntf;
    1414
    1515implementation
  • Common/UScaleDPI.pas

    r466 r467  
    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.