From 919c047f7842d4cf46801ac2a82820aadcb8ca43 Mon Sep 17 00:00:00 2001 From: Matteo Salvi Date: Mon, 24 Jul 2023 01:01:24 +0200 Subject: [PATCH] Fixed get resolution from TImageList --- Source/VirtualTrees.BaseTree.pas | 19 +++++++++++-------- Source/VirtualTrees.Header.pas | 11 +++++++++-- Source/VirtualTrees.Types.pas | 15 +++++++++------ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Source/VirtualTrees.BaseTree.pas b/Source/VirtualTrees.BaseTree.pas index bbd8e6b9..12b1ff97 100644 --- a/Source/VirtualTrees.BaseTree.pas +++ b/Source/VirtualTrees.BaseTree.pas @@ -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? @@ -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 @@ -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); @@ -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 @@ -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; @@ -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} @@ -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} @@ -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; diff --git a/Source/VirtualTrees.Header.pas b/Source/VirtualTrees.Header.pas index 957a5f7c..ea0abcd0 100644 --- a/Source/VirtualTrees.Header.pas +++ b/Source/VirtualTrees.Header.pas @@ -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); diff --git a/Source/VirtualTrees.Types.pas b/Source/VirtualTrees.Types.pas index f600a74b..4b159a32 100644 --- a/Source/VirtualTrees.Types.pas +++ b/Source/VirtualTrees.Types.pas @@ -16,7 +16,7 @@ interface {$else} FakeActiveX, {$endif} - SysUtils, Graphics, ImgList; + SysUtils, Graphics, ImgList, LCLVersion; const {$I lclconstants.inc} @@ -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 @@ -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 = ( @@ -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; @@ -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 --------------------------------------------------------------------------