Ignore:
Timestamp:
Jan 21, 2022, 9:54:27 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Build under Lazarus 2.2.0.
  • Modified: Updated Common package.
File:
1 edited

Legend:

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

    r210 r215  
    88
    99uses
    10   Classes, Forms, Graphics, Controls, ComCtrls, LCLType, SysUtils, StdCtrls,
    11   Contnrs;
     10  Classes, Forms, Graphics, Controls, ComCtrls, LCLType, SysUtils, fgl;
    1211
    1312type
     13  TControlDimensions = class;
    1414
    1515  { TControlDimension }
     
    1818    BoundsRect: TRect;
    1919    FontHeight: Integer;
    20     Controls: TObjectList; // TList<TControlDimension>
     20    Controls: TControlDimensions;
    2121    // Class specifics
    2222    ButtonSize: TPoint; // TToolBar
     
    2626    constructor Create;
    2727    destructor Destroy; override;
     28  end;
     29
     30  TControlDimensions = class(TFPGObjectList<TControlDimension>)
    2831  end;
    2932
     
    7376constructor TControlDimension.Create;
    7477begin
    75   Controls := TObjectList.Create;
     78  Controls := TControlDimensions.Create;
    7679end;
    7780
     
    7982begin
    8083  FreeAndNil(Controls);
    81   inherited Destroy;
     84  inherited;
    8285end;
    8386
     
    212215  TempBmp: TBitmap;
    213216  Temp: array of TBitmap;
    214   NewWidth, NewHeight: integer;
     217  NewWidth: Integer;
     218  NewHeight: Integer;
    215219  I: Integer;
    216220begin
    217221  ImgList.BeginUpdate;
    218   NewWidth := ScaleX(ImgList.Width, FromDPI.X);
    219   NewHeight := ScaleY(ImgList.Height, FromDPI.Y);
    220 
    221   SetLength(Temp, ImgList.Count);
    222   for I := 0 to ImgList.Count - 1 do
    223   begin
    224     TempBmp := TBitmap.Create;
    225     TempBmp.PixelFormat := pf32bit;
    226     ImgList.GetBitmap(I, TempBmp);
    227     Temp[I] := TBitmap.Create;
    228     Temp[I].SetSize(NewWidth, NewHeight);
    229     {$IFDEF Linux}
    230     Temp[I].PixelFormat := pf24bit;
    231     {$ELSE}
    232     Temp[I].PixelFormat := pf32bit;
    233     {$ENDIF}
    234     Temp[I].TransparentColor := TempBmp.TransparentColor;
    235     //Temp[I].TransparentMode := TempBmp.TransparentMode;
    236     Temp[I].Transparent := True;
    237     Temp[I].Canvas.Brush.Style := bsSolid;
    238     Temp[I].Canvas.Brush.Color := Temp[I].TransparentColor;
    239     Temp[I].Canvas.FillRect(0, 0, Temp[I].Width, Temp[I].Height);
    240 
    241     if (Temp[I].Width = 0) or (Temp[I].Height = 0) then Continue;
    242     Temp[I].Canvas.StretchDraw(Rect(0, 0, Temp[I].Width, Temp[I].Height), TempBmp);
    243     TempBmp.Free;
    244   end;
    245 
    246   ImgList.Clear;
    247   ImgList.Width := NewWidth;
    248   ImgList.Height := NewHeight;
    249 
    250   for I := 0 to High(Temp) do
    251   begin
    252     ImgList.Add(Temp[I], nil);
    253     Temp[i].Free;
    254   end;
    255   ImgList.EndUpdate;
     222  try
     223    NewWidth := ScaleX(ImgList.Width, FromDPI.X);
     224    NewHeight := ScaleY(ImgList.Height, FromDPI.Y);
     225
     226    Temp := nil;
     227    SetLength(Temp, ImgList.Count);
     228    for I := 0 to ImgList.Count - 1 do
     229    begin
     230      TempBmp := TBitmap.Create;
     231      try
     232        TempBmp.PixelFormat := pf32bit;
     233        ImgList.GetBitmap(I, TempBmp);
     234        Temp[I] := TBitmap.Create;
     235        Temp[I].SetSize(NewWidth, NewHeight);
     236        {$IFDEF UNIX}
     237        Temp[I].PixelFormat := pf24bit;
     238        {$ELSE}
     239        Temp[I].PixelFormat := pf32bit;
     240        {$ENDIF}
     241        Temp[I].TransparentColor := TempBmp.TransparentColor;
     242        //Temp[I].TransparentMode := TempBmp.TransparentMode;
     243        Temp[I].Transparent := True;
     244        Temp[I].Canvas.Brush.Style := bsSolid;
     245        Temp[I].Canvas.Brush.Color := Temp[I].TransparentColor;
     246        Temp[I].Canvas.FillRect(0, 0, Temp[I].Width, Temp[I].Height);
     247
     248        if (Temp[I].Width = 0) or (Temp[I].Height = 0) then Continue;
     249        Temp[I].Canvas.StretchDraw(Rect(0, 0, Temp[I].Width, Temp[I].Height), TempBmp);
     250      finally
     251        TempBmp.Free;
     252      end;
     253    end;
     254
     255    ImgList.Clear;
     256    ImgList.Width := NewWidth;
     257    ImgList.Height := NewHeight;
     258
     259    for I := 0 to High(Temp) do
     260    begin
     261      ImgList.Add(Temp[I], nil);
     262      Temp[i].Free;
     263    end;
     264  finally
     265    ImgList.EndUpdate;
     266  end;
    256267end;
    257268
     
    313324    //AutoSize := False;
    314325    //Anchors := [];
    315     BoundsRect := Bounds(ScaleX(Left, FromDPI.X), ScaleY(Top, FromDPI.Y),
    316       ScaleX(Width, FromDPI.X), ScaleY(Height, FromDPI.Y));
     326    Left := ScaleX(Left, FromDPI.X);
     327    Top := ScaleY(Top, FromDPI.Y);
     328    //if not (akRight in Anchors) then
     329    Width := ScaleX(Width, FromDPI.X);
     330    //if not (akBottom in Anchors) then
     331    Height := ScaleY(Height, FromDPI.Y);
    317332    {$IFDEF LCL Qt}
    318333      Font.Size := 0;
     
    327342  with TCoolBar(Control) do begin
    328343    BeginUpdate;
    329     for I := 0 to Bands.Count - 1 do
    330       with Bands[I] do begin
    331         MinWidth := ScaleX(MinWidth, FromDPI.X);
    332         MinHeight := ScaleY(MinHeight, FromDPI.Y);
    333         // Workaround to bad band width auto sizing
    334         //Width := ScaleX(Width, FromDPI.X);
    335         Width := ScaleX(Control.Width + 28, FromDPI.X);
    336         //Control.Invalidate;
     344    try
     345      for I := 0 to Bands.Count - 1 do
     346        with Bands[I] do begin
     347          MinWidth := ScaleX(MinWidth, FromDPI.X);
     348          MinHeight := ScaleY(MinHeight, FromDPI.Y);
     349          // Workaround to bad band width auto sizing
     350          //Width := ScaleX(Width, FromDPI.X);
     351          Width := ScaleX(Control.Width + 28, FromDPI.X);
     352          //Control.Invalidate;
     353        end;
     354      // Workaround for bad autosizing of coolbar
     355      if AutoSize then begin
     356        AutoSize := False;
     357        Height := ScaleY(Height, FromDPI.Y);
     358        AutoSize := True;
    337359      end;
    338     // Workaround for bad autosizing of coolbar
    339     if AutoSize then begin
    340       AutoSize := False;
    341       Height := ScaleY(Height, FromDPI.Y);
    342       AutoSize := True;
    343     end;
    344     EndUpdate;
     360    finally
     361      EndUpdate;
     362    end;
    345363  end;
    346364
     
    348366    ToolBarControl := TToolBar(Control);
    349367    with ToolBarControl do begin
    350       //SetButtonSize(ScaleX(ButtonWidth, FromDPI.X), ScaleY(ButtonHeight, FromDPI.Y));
     368      ButtonWidth := ScaleX(ButtonWidth, FromDPI.X);
     369      ButtonHeight := ScaleY(ButtonHeight, FromDPI.Y);
    351370    end;
    352371  end;
Note: See TracChangeset for help on using the changeset viewer.