Skip to content

Commit

Permalink
Fixed get resolution from TImageList
Browse files Browse the repository at this point in the history
  • Loading branch information
salvadorbs committed Jul 23, 2023
1 parent fd9322e commit 919c047
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
19 changes: 11 additions & 8 deletions Source/VirtualTrees.BaseTree.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,9 @@ TVirtualTreeColumnCracker = class(TVirtualTreeColumn);
'VT_CHECK_DARK' //ckSystemDefault
);

//LCL: Workaround for drawing blank hot node button in PaintNodeButton()
TVP_HOTGLYPH = TVP_GLYPH;

var
gWatcher: TCriticalSection = nil;
//ToDo upgrade: Remove SystemCheckImages and using only FCheckImages?
Expand Down Expand Up @@ -2661,9 +2664,9 @@ procedure TBaseVirtualTree.CalculateVerticalAlignments(var PaintInfo: TVTPaintIn
if (ImageInfo[iiNormal].Index >= 0) or (ImageInfo[iiState].Index >= 0) then
begin
if (ImageInfo[iiNormal].Index >= 0) then
VAlign := ImageInfo[iiNormal].Images.Height
VAlign := GetRealImagesHeight
else
VAlign := ImageInfo[iiState].Images.Height;
VAlign := GetRealStateImagesHeight;
VAlign := MulDiv((NodeHeight[Node] - VAlign), Node.Align, 100) + Divide(VAlign, 2);
end
else
Expand Down Expand Up @@ -3052,7 +3055,7 @@ function TBaseVirtualTree.CollectSelectedNodesRTL(MainColumn: Integer; NodeLeft,
// Don't check the events here as descendant trees might have overriden the DoGetImageIndex method.
WithStateImages := Assigned(FStateImages) or Assigned(OnGetImageIndexEx);
if WithCheck then
CheckOffset := FCheckImages.Width + FImagesMargin
CheckOffset := GetRealCheckImagesWidth + FImagesMargin
else
CheckOffset := 0;
AutoSpan := FHeader.UseColumns and (toAutoSpanColumns in FOptions.AutoOptions);
Expand Down Expand Up @@ -3766,7 +3769,7 @@ procedure TBaseVirtualTree.GetOffsets(pNode: PVirtualNode; out pOffsets: TVTOffs
Inc(pOffsets[TVTElement.ofsCheckBox], fImagesMargin);

// right of checkbox, left of state image
pOffsets[TVTElement.ofsStateImage] := pOffsets[TVTElement.ofsCheckBox] + FCheckImages.Width + fImagesMargin;
pOffsets[TVTElement.ofsStateImage] := pOffsets[TVTElement.ofsCheckBox] + GetRealCheckImagesWidth + fImagesMargin;
end else
pOffsets[TVTElement.ofsStateImage] := pOffsets[TVTElement.ofsCheckBox];
if pElement <= TVTElement.ofsStateImage then
Expand Down Expand Up @@ -12533,7 +12536,7 @@ procedure TBaseVirtualTree.GetImageIndex(var Info: TVTPaintInfo; Kind: TVTImageK

CustomImages := DoGetImageIndex(Node, Kind, Column, ImageInfo[InfoIndex].Ghosted, ImageInfo[InfoIndex].Index);
if Assigned(CustomImages) then
ImageInfo[InfoIndex].Images := CustomImages
ImageInfo[InfoIndex].Images := CustomImages;
end;
end;

Expand Down Expand Up @@ -12762,7 +12765,7 @@ function TBaseVirtualTree.GetRealImageListWidth(ImageList: TCustomImageList): In
Result := 0
else
{$IF LCL_FullVersion >= 2000000}
Result := ImageList.ResolutionForPPI[ImageList.Width, Font.PixelsPerInch, GetCanvasScaleFactor].Height;
Result := ImageList.ResolutionForPPI[ImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Width;
{$ELSE}
Result := ImageList.Height;
{$IFEND}
Expand All @@ -12774,7 +12777,7 @@ function TBaseVirtualTree.GetRealImageListHeight(ImageList: TCustomImageList): I
Result := 0
else
{$IF LCL_FullVersion >= 2000000}
Result := ImageList.ResolutionForPPI[ImageList.Height, Font.PixelsPerInch, GetCanvasScaleFactor].Height;
Result := ImageList.ResolutionForPPI[ImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor].Height;
{$ELSE}
Result := ImageList.Height;
{$IFEND}
Expand Down Expand Up @@ -21579,7 +21582,7 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe

CalculateVerticalAlignments(PaintInfo, ButtonY);
// Take the space for the tree lines into account.
PaintInfo.AdjustImageCoordinates();
PaintInfo.AdjustImageCoordinates(GetRealImageListHeight(Images));
if UseColumns then
begin
ClipRect := CellRect;
Expand Down
11 changes: 9 additions & 2 deletions Source/VirtualTrees.Header.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3046,13 +3046,20 @@ function TVirtualTreeColumn.GetCaptionWidth : TDimension;
if not FCheckBox then
begin
if Assigned(Images) then
HeaderGlyphSize := Point(Images.Width, Images.Height);
begin
{$IF LCL_FullVersion >= 2000000}
with Images.ResolutionForPPI[FImagesWidth, Font.PixelsPerInch, Self.Owner.Header.TreeView.GetCanvasScaleFactor] do
HeaderGlyphSize := Point(Width, Height);
{$ELSE}
HeaderGlyphSize := Point(FImages.Width, FImages.Height)
{$IFEND}
end
end
else
with Self.TreeViewControl do
begin
if Assigned(CheckImages) then
HeaderGlyphSize := Point(CheckImages.Width, CheckImages.Height);
HeaderGlyphSize := Point(GetRealCheckImagesWidth, GetRealCheckImagesHeight);
end
else
HeaderGlyphSize := Point(0, 0);
Expand Down
15 changes: 9 additions & 6 deletions Source/VirtualTrees.Types.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface
{$else}
FakeActiveX,
{$endif}
SysUtils, Graphics, ImgList;
SysUtils, Graphics, ImgList, LCLVersion;

const
{$I lclconstants.inc}
Expand Down Expand Up @@ -1121,6 +1121,8 @@ TVTImageInfo = record
);
TVTInternalPaintOptions = set of TVTInternalPaintOption;

{ TVTPaintInfo }

TVTPaintInfo = record
Canvas: TCanvas; // the canvas to paint on
PaintOptions: TVTInternalPaintOptions; // a copy of the paint options passed to PaintTree
Expand All @@ -1137,7 +1139,7 @@ TVTPaintInfo = record
ImageInfo: array[TVTImageInfoIndex] of TVTImageInfo; // info about each possible node image
Offsets: TVTOffsets; // The offsets of the various elements of a tree node
VAlign: TDimension;
procedure AdjustImageCoordinates();
procedure AdjustImageCoordinates(RealImagesHeight: Integer);
end;

TElementEdge = (
Expand Down Expand Up @@ -1278,7 +1280,7 @@ function TVTImageInfo.Equals(const pImageInfo2: TVTImageInfo): Boolean;

{ TVTPaintInfo }

procedure TVTPaintInfo.AdjustImageCoordinates();
procedure TVTPaintInfo.AdjustImageCoordinates(RealImagesHeight: Integer);
// During painting of the main column some coordinates must be adjusted due to the tree lines.
begin
ContentRect := CellRect;
Expand All @@ -1297,12 +1299,13 @@ procedure TVTPaintInfo.AdjustImageCoordinates();
ImageInfo[iiCheck].XPos := CellRect.Right - Offsets[TVTElement.ofsCheckBox] - (Offsets[TVTElement.ofsStateImage] - Offsets[TVTElement.ofsCheckBox]);
ContentRect.Right := CellRect.Right - Offsets[TVTElement.ofsLabel];
end;

if ImageInfo[iiNormal].Index > -1 then
ImageInfo[iiNormal].YPos := CellRect.Top + VAlign - ImageInfo[iiNormal].Images.Height div 2;
ImageInfo[iiNormal].YPos := CellRect.Top + VAlign - RealImagesHeight div 2;
if ImageInfo[iiState].Index > -1 then
ImageInfo[iiState].YPos := CellRect.Top + VAlign - ImageInfo[iiState].Images.Height div 2;
ImageInfo[iiState].YPos := CellRect.Top + VAlign - RealImagesHeight div 2;
if ImageInfo[iiCheck].Index > -1 then
ImageInfo[iiCheck].YPos := CellRect.Top + VAlign - ImageInfo[iiCheck].Images.Height div 2;
ImageInfo[iiCheck].YPos := CellRect.Top + VAlign - RealImagesHeight div 2;
end;

//----------------- TCustomVirtualTreeOptions --------------------------------------------------------------------------
Expand Down

0 comments on commit 919c047

Please sign in to comment.