Ignore:
Timestamp:
Apr 25, 2022, 6:22:53 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Update Common package to version 0.10.
  • Modified: fgl unit replaced by Generics.Collections.
File:
1 edited

Legend:

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

    r423 r424  
    66
    77uses
    8   Classes, Forms, Graphics, Controls, ComCtrls, LCLType, SysUtils, StdCtrls,
    9   Contnrs;
     8  Classes, Forms, Graphics, Controls, ComCtrls, LCLType, SysUtils,
     9  Generics.Collections;
    1010
    1111type
     12  TControlDimensions = class;
    1213
    1314  { TControlDimension }
     
    1617    BoundsRect: TRect;
    1718    FontHeight: Integer;
    18     Controls: TObjectList; // TList<TControlDimension>
     19    Controls: TControlDimensions;
    1920    // Class specifics
    2021    ButtonSize: TPoint; // TToolBar
     
    2425    constructor Create;
    2526    destructor Destroy; override;
     27  end;
     28
     29  TControlDimensions = class(TObjectList<TControlDimension>)
    2630  end;
    2731
     
    7175constructor TControlDimension.Create;
    7276begin
    73   Controls := TObjectList.Create;
     77  Controls := TControlDimensions.Create;
    7478end;
    7579
     
    7781begin
    7882  FreeAndNil(Controls);
    79   inherited Destroy;
     83  inherited;
    8084end;
    8185
     
    210214  TempBmp: TBitmap;
    211215  Temp: array of TBitmap;
    212   NewWidth, NewHeight: integer;
     216  NewWidth: Integer;
     217  NewHeight: Integer;
    213218  I: Integer;
    214219begin
    215220  ImgList.BeginUpdate;
    216   NewWidth := ScaleX(ImgList.Width, FromDPI.X);
    217   NewHeight := ScaleY(ImgList.Height, FromDPI.Y);
    218 
    219   SetLength(Temp, ImgList.Count);
    220   for I := 0 to ImgList.Count - 1 do
    221   begin
    222     TempBmp := TBitmap.Create;
    223     TempBmp.PixelFormat := pf32bit;
    224     ImgList.GetBitmap(I, TempBmp);
    225     Temp[I] := TBitmap.Create;
    226     Temp[I].SetSize(NewWidth, NewHeight);
    227     {$IFDEF UNIX}
    228     Temp[I].PixelFormat := pf24bit;
    229     {$ELSE}
    230     Temp[I].PixelFormat := pf32bit;
    231     {$ENDIF}
    232     Temp[I].TransparentColor := TempBmp.TransparentColor;
    233     //Temp[I].TransparentMode := TempBmp.TransparentMode;
    234     Temp[I].Transparent := True;
    235     Temp[I].Canvas.Brush.Style := bsSolid;
    236     Temp[I].Canvas.Brush.Color := Temp[I].TransparentColor;
    237     Temp[I].Canvas.FillRect(0, 0, Temp[I].Width, Temp[I].Height);
    238 
    239     if (Temp[I].Width = 0) or (Temp[I].Height = 0) then Continue;
    240     Temp[I].Canvas.StretchDraw(Rect(0, 0, Temp[I].Width, Temp[I].Height), TempBmp);
    241     TempBmp.Free;
    242   end;
    243 
    244   ImgList.Clear;
    245   ImgList.Width := NewWidth;
    246   ImgList.Height := NewHeight;
    247 
    248   for I := 0 to High(Temp) do
    249   begin
    250     ImgList.Add(Temp[I], nil);
    251     Temp[i].Free;
    252   end;
    253   ImgList.EndUpdate;
     221  try
     222    NewWidth := ScaleX(ImgList.Width, FromDPI.X);
     223    NewHeight := ScaleY(ImgList.Height, FromDPI.Y);
     224
     225    Temp := nil;
     226    SetLength(Temp, ImgList.Count);
     227    for I := 0 to ImgList.Count - 1 do
     228    begin
     229      TempBmp := TBitmap.Create;
     230      try
     231        TempBmp.PixelFormat := pf32bit;
     232        ImgList.GetBitmap(I, TempBmp);
     233        Temp[I] := TBitmap.Create;
     234        Temp[I].SetSize(NewWidth, NewHeight);
     235        {$IFDEF UNIX}
     236        Temp[I].PixelFormat := pf24bit;
     237        {$ELSE}
     238        Temp[I].PixelFormat := pf32bit;
     239        {$ENDIF}
     240        Temp[I].TransparentColor := TempBmp.TransparentColor;
     241        //Temp[I].TransparentMode := TempBmp.TransparentMode;
     242        Temp[I].Transparent := True;
     243        Temp[I].Canvas.Brush.Style := bsSolid;
     244        Temp[I].Canvas.Brush.Color := Temp[I].TransparentColor;
     245        Temp[I].Canvas.FillRect(0, 0, Temp[I].Width, Temp[I].Height);
     246
     247        if (Temp[I].Width = 0) or (Temp[I].Height = 0) then Continue;
     248        Temp[I].Canvas.StretchDraw(Rect(0, 0, Temp[I].Width, Temp[I].Height), TempBmp);
     249      finally
     250        TempBmp.Free;
     251      end;
     252    end;
     253
     254    ImgList.Clear;
     255    ImgList.Width := NewWidth;
     256    ImgList.Height := NewHeight;
     257
     258    for I := 0 to High(Temp) do
     259    begin
     260      ImgList.Add(Temp[I], nil);
     261      Temp[i].Free;
     262    end;
     263  finally
     264    ImgList.EndUpdate;
     265  end;
    254266end;
    255267
     
    329341  with TCoolBar(Control) do begin
    330342    BeginUpdate;
    331     for I := 0 to Bands.Count - 1 do
    332       with Bands[I] do begin
    333         MinWidth := ScaleX(MinWidth, FromDPI.X);
    334         MinHeight := ScaleY(MinHeight, FromDPI.Y);
    335         // Workaround to bad band width auto sizing
    336         //Width := ScaleX(Width, FromDPI.X);
    337         Width := ScaleX(Control.Width + 28, FromDPI.X);
    338         //Control.Invalidate;
     343    try
     344      for I := 0 to Bands.Count - 1 do
     345        with Bands[I] do begin
     346          MinWidth := ScaleX(MinWidth, FromDPI.X);
     347          MinHeight := ScaleY(MinHeight, FromDPI.Y);
     348          // Workaround to bad band width auto sizing
     349          //Width := ScaleX(Width, FromDPI.X);
     350          Width := ScaleX(Control.Width + 28, FromDPI.X);
     351          //Control.Invalidate;
     352        end;
     353      // Workaround for bad autosizing of coolbar
     354      if AutoSize then begin
     355        AutoSize := False;
     356        Height := ScaleY(Height, FromDPI.Y);
     357        AutoSize := True;
    339358      end;
    340     // Workaround for bad autosizing of coolbar
    341     if AutoSize then begin
    342       AutoSize := False;
    343       Height := ScaleY(Height, FromDPI.Y);
    344       AutoSize := True;
    345     end;
    346     EndUpdate;
     359    finally
     360      EndUpdate;
     361    end;
    347362  end;
    348363
Note: See TracChangeset for help on using the changeset viewer.