Ignore:
Timestamp:
Oct 11, 2016, 4:13:32 PM (8 years ago)
Author:
chronos
Message:

Modified: Synchronized content of Common package.

File:
1 edited

Legend:

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

    r104 r106  
    1717  TControlDimension = class
    1818    BoundsRect: TRect;
    19     AuxSize: TPoint;
    2019    FontHeight: Integer;
    2120    Controls: TObjectList; // TList<TControlDimension>
     21    // Class specifics
     22    ButtonSize: TPoint; // TToolBar
     23    CoolBandWidth: Integer;
     24    ConstraintsMin: TPoint; // TForm
     25    ConstraintsMax: TPoint; // TForm
    2226    constructor Create;
    2327    destructor Destroy; override;
     
    7478destructor TControlDimension.Destroy;
    7579begin
    76   Controls.Free;
     80  FreeAndNil(Controls);
    7781  inherited Destroy;
    7882end;
     
    113117  Dimensions.Controls.Clear;
    114118  if Control is TToolBar then
    115     Dimensions.AuxSize := Point(TToolBar(Control).ButtonWidth, TToolBar(Control).ButtonHeight);
    116 
     119    Dimensions.ButtonSize := Point(TToolBar(Control).ButtonWidth, TToolBar(Control).ButtonHeight);
     120  if Control is TForm then begin
     121    Dimensions.ConstraintsMin := Point(TForm(Control).Constraints.MinWidth,
     122      TForm(Control).Constraints.MinHeight);
     123    Dimensions.ConstraintsMax := Point(TForm(Control).Constraints.MaxWidth,
     124      TForm(Control).Constraints.MaxHeight);
     125  end;
    117126  if Control is TWinControl then
    118127  for I := 0 to TWinControl(Control).ControlCount - 1 do begin
    119     if TWinControl(Control).Controls[I] is TControl then begin
     128    if TWinControl(Control).Controls[I] is TControl then
     129    // Do not scale docked forms twice
     130    if not (TWinControl(Control).Controls[I] is TForm) then begin
    120131      NewControl := TControlDimension.Create;
    121132      Dimensions.Controls.Add(NewControl);
     
    133144  Control.Font.Height := Dimensions.FontHeight;
    134145  if Control is TToolBar then begin
    135     TToolBar(Control).ButtonWidth := Dimensions.AuxSize.X;
    136     TToolBar(Control).ButtonHeight := Dimensions.AuxSize.Y;
     146    TToolBar(Control).ButtonWidth := Dimensions.ButtonSize.X;
     147    TToolBar(Control).ButtonHeight := Dimensions.ButtonSize.Y;
     148  end;
     149  if Control is TForm then begin
     150    TForm(Control).Constraints.MinWidth := Dimensions.ConstraintsMin.X;
     151    TForm(Control).Constraints.MinHeight := Dimensions.ConstraintsMin.Y;
     152    TForm(Control).Constraints.MaxWidth := Dimensions.ConstraintsMax.X;
     153    TForm(Control).Constraints.MaxHeight := Dimensions.ConstraintsMax.Y;
    137154  end;
    138155  if Control is TWinControl then
    139156  for I := 0 to TWinControl(Control).ControlCount - 1 do begin
    140     if TWinControl(Control).Controls[I] is TControl then begin
     157    if TWinControl(Control).Controls[I] is TControl then
     158    // Do not scale docked forms twice
     159    if not (TWinControl(Control).Controls[I] is TForm) then begin
    141160      RestoreDimensions(TWinControl(Control).Controls[I], TControlDimension(Dimensions.Controls[I]));
    142161    end;
     
    152171  Control.Font.Height := ScaleY(Dimensions.FontHeight, DesignDPI.Y);
    153172  if Control is TToolBar then begin
    154     TToolBar(Control).ButtonWidth := ScaleX(Dimensions.AuxSize.X, DesignDPI.X);
    155     TToolBar(Control).ButtonHeight := ScaleY(Dimensions.AuxSize.Y, DesignDPI.Y);
     173    TToolBar(Control).ButtonWidth := ScaleX(Dimensions.ButtonSize.X, DesignDPI.X);
     174    TToolBar(Control).ButtonHeight := ScaleY(Dimensions.ButtonSize.Y, DesignDPI.Y);
     175  end;
     176  if Control is TCoolBar then begin
     177    with TCoolBar(Control) do
     178    for I := 0 to Bands.Count - 1 do
     179    with TCoolBand(Bands[I]) do begin
     180      MinWidth := ScaleX(Dimensions.ButtonSize.X, DesignDPI.X);
     181      MinHeight := ScaleY(Dimensions.ButtonSize.Y, DesignDPI.Y);
     182      //Width := ScaleX(Dimensions.BoundsRect.Left -
     183    end;
     184  end;
     185  if Control is TForm then begin
     186    TForm(Control).Constraints.MinWidth := ScaleX(Dimensions.ConstraintsMin.X, DesignDPI.X);
     187    TForm(Control).Constraints.MaxWidth := ScaleX(Dimensions.ConstraintsMax.X, DesignDPI.X);
     188    TForm(Control).Constraints.MinHeight := ScaleY(Dimensions.ConstraintsMin.Y, DesignDPI.Y);
     189    TForm(Control).Constraints.MaxHeight := ScaleY(Dimensions.ConstraintsMax.Y, DesignDPI.Y);
    156190  end;
    157191  if Control is TWinControl then
    158192  for I := 0 to TWinControl(Control).ControlCount - 1 do begin
    159     if TWinControl(Control).Controls[I] is TControl then begin
     193    if TWinControl(Control).Controls[I] is TControl then
     194    // Do not scale docked forms twice
     195    if not (TWinControl(Control).Controls[I] is TForm) then begin
    160196      ScaleDimensions(TWinControl(Control).Controls[I], TControlDimension(Dimensions.Controls[I]));
    161197    end;
     
    183219
    184220  SetLength(Temp, ImgList.Count);
    185   TempBmp := TBitmap.Create;
    186221  for I := 0 to ImgList.Count - 1 do
    187222  begin
     223    TempBmp := TBitmap.Create;
     224    TempBmp.PixelFormat := pf32bit;
    188225    ImgList.GetBitmap(I, TempBmp);
    189     //TempBmp.PixelFormat := pfDevice;
    190226    Temp[I] := TBitmap.Create;
    191227    Temp[I].SetSize(NewWidth, NewHeight);
    192     Temp[I].TransparentColor := clFuchsia;// TempBmp.TransparentColor;
     228    Temp[I].PixelFormat := pf32bit;
     229    Temp[I].TransparentColor := TempBmp.TransparentColor;
    193230    //Temp[I].TransparentMode := TempBmp.TransparentMode;
    194231    Temp[I].Transparent := True;
     
    199236    if (Temp[I].Width = 0) or (Temp[I].Height = 0) then Continue;
    200237    Temp[I].Canvas.StretchDraw(Rect(0, 0, Temp[I].Width, Temp[I].Height), TempBmp);
    201   end;
    202   TempBmp.Free;
     238    TempBmp.Free;
     239  end;
    203240
    204241  ImgList.Clear;
     
    247284  WinControl: TWinControl;
    248285  ToolBarControl: TToolBar;
    249 begin
    250   Control.BoundsRect := ScaleRect(Control.BoundsRect, DesignDPI);
    251   Control.Font.Height := ScaleY(Control.Font.Height, DesignDPI.Y);
     286  OldAnchors: TAnchors;
     287  OldAutoSize: Boolean;
     288begin
     289  //if Control is TMemo then Exit;
     290  //if Control is TForm then
     291  //  Control.DisableAutoSizing;
     292  with Control do begin
     293    //OldAutoSize := AutoSize;
     294    //AutoSize := False;
     295    //Anchors := [];
     296    Left := ScaleX(Left, FromDPI.X);
     297    Top := ScaleY(Top, FromDPI.Y);
     298    //if not (akRight in Anchors) then
     299    Width := ScaleX(Width, FromDPI.X);
     300    //if not (akBottom in Anchors) then
     301    Height := ScaleY(Height, FromDPI.Y);
     302    {$IFDEF LCL Qt}
     303      Font.Size := 0;
     304    {$ELSE}
     305      Font.Height := ScaleY(Font.GetTextHeight('Hg'), FromDPI.Y);
     306    {$ENDIF}
     307    //Anchors := OldAnchors;
     308    //AutoSize := OldAutoSize;
     309  end;
    252310
    253311  if Control is TToolBar then begin
Note: See TracChangeset for help on using the changeset viewer.