Skip to content

Commit d150cb8

Browse files
committed
Fixed issue #1203: Grid lines do not scale
1 parent 741c8ac commit d150cb8

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

Source/VirtualTrees.BaseTree.pas

+22-7
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor)
11151115
procedure InternalRemoveFromSelection(Node: PVirtualNode); virtual;
11161116
procedure InterruptValidation(pWaitForValidationTermination: Boolean = True);
11171117
procedure InvalidateCache;
1118+
function LineWidth(): TDimension;
11181119
procedure Loaded; override;
11191120
procedure MainColumnChanged; virtual;
11201121
procedure MarkCutCopyNodes; override;
@@ -11478,7 +11479,7 @@ procedure TBaseVirtualTree.DrawGridHLine(const PaintInfo: TVTPaintInfo; Left, Ri
1147811479
var
1147911480
R: TRect;
1148011481
begin
11481-
R := Rect(Min(Left, Right), Top, Max(Left, Right) + 1, Top + 1);
11482+
R := Rect(Min(Left, Right), Top, Max(Left, Right) + LineWidth, Top + LineWidth);
1148211483
DrawGridLine(PaintInfo.Canvas, R)
1148311484
end;
1148411485

@@ -11490,7 +11491,7 @@ procedure TBaseVirtualTree.DrawGridVLine(const PaintInfo: TVTPaintInfo; Top, Bot
1149011491
var
1149111492
R: TRect;
1149211493
begin
11493-
R := Rect(Left, Min(Top, Bottom), Left + 1, Max(Top, Bottom) + 1);
11494+
R := Rect(Left, Min(Top, Bottom), Left + LineWidth, Max(Top, Bottom) + LineWidth);
1149411495
if pFixedColumn and (TVtPaintOption.toShowVertGridLines in TreeOptions.PaintOptions) then // In case we showe grid lines, we must use a color for the fixed column that differentiates from the normal gridlines
1149511496
StyleServices.DrawElement(PaintInfo.Canvas.Handle, StyleServices.GetElementDetails(tlGroupHeaderLineOpenHot), R {$IF CompilerVersion >= 34}, @R, CurrentPPI{$IFEND})
1149611497
else begin
@@ -19150,6 +19151,20 @@ function TBaseVirtualTree.LevelNodes(NodeLevel: Cardinal): TVTVirtualNodeEnumera
1915019151
Result.FNodeLevel := NodeLevel;
1915119152
end;
1915219153

19154+
function TBaseVirtualTree.LineWidth: TDimension;
19155+
// Returns the width in pixels that should be used to draw grid lines, see issue #1203
19156+
begin
19157+
// Always use line width of 1 for older Delphi versions.
19158+
{$if CompilerVersion < 31}
19159+
Exit(1);
19160+
{$else}
19161+
if FCurrentPPI < 200 then
19162+
Exit(1) // Always use 1 pixel is scaled <=200%
19163+
else
19164+
Exit(MulDiv(1, Self.FCurrentPPI, 132)); // Use 132 dpi instead of the typical 96 so that line width increase slightly slower than the actual scaling, so we have a 3px line at 400%
19165+
{$ifend}
19166+
end;
19167+
1915319168
//----------------------------------------------------------------------------------------------------------------------
1915419169

1915519170
function TBaseVirtualTree.NoInitNodes(ConsiderChildrenAbove: Boolean): TVTVirtualNodeEnumeration;
@@ -20493,15 +20508,15 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe
2049320508
begin
2049420509
if BidiMode = bdLeftToRight then
2049520510
begin
20496-
DrawGridHLine(PaintInfo, CellRect.Left + PaintInfo.Offsets[ofsCheckBox] - fImagesMargin, CellRect.Right - 1, CellRect.Bottom - 1);
20511+
DrawGridHLine(PaintInfo, CellRect.Left + PaintInfo.Offsets[ofsCheckBox] - fImagesMargin, CellRect.Right - LineWidth, CellRect.Bottom - LineWidth);
2049720512
end
2049820513
else
2049920514
begin
20500-
DrawGridHLine(PaintInfo, CellRect.Left, CellRect.Right - IfThen(toFixedIndent in FOptions.PaintOptions, 1, IndentSize) * FIndent - 1, CellRect.Bottom - 1);
20515+
DrawGridHLine(PaintInfo, CellRect.Left, CellRect.Right - IfThen(toFixedIndent in FOptions.PaintOptions, LineWidth, IndentSize) * FIndent - 1, CellRect.Bottom - LineWidth);
2050120516
end;
2050220517
end
2050320518
else
20504-
DrawGridHLine(PaintInfo, CellRect.Left, CellRect.Right, CellRect.Bottom - 1);
20519+
DrawGridHLine(PaintInfo, CellRect.Left, CellRect.Right, CellRect.Bottom - LineWidth);
2050520520

2050620521
Dec(CellRect.Bottom);
2050720522
Dec(ContentRect.Bottom);
@@ -20531,7 +20546,7 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe
2053120546
begin
2053220547
if (BidiMode = bdLeftToRight) or not ColumnIsEmpty(Node, Column) then
2053320548
begin
20534-
DrawGridVLine(PaintInfo, CellRect.Top, CellRect.Bottom, CellRect.Right - 1, ColumnIsFixed and (NextColumn >= 0));
20549+
DrawGridVLine(PaintInfo, CellRect.Top, CellRect.Bottom, CellRect.Right - LineWidth, ColumnIsFixed and (NextColumn >= 0));
2053520550
end;
2053620551

2053720552
Dec(CellRect.Right);
@@ -20547,7 +20562,7 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe
2054720562
begin
2054820563
if (BidiMode = bdLeftToRight) or not ColumnIsEmpty(Node, Column) then
2054920564
begin
20550-
DrawGridVLine(PaintInfo, CellRect.Top, CellRect.Bottom, CellRect.Right - 1, ColumnIsFixed and (NextColumn >= 0));
20565+
DrawGridVLine(PaintInfo, CellRect.Top, CellRect.Bottom, CellRect.Right - LineWidth, ColumnIsFixed and (NextColumn >= 0));
2055120566
end;
2055220567
Dec(CellRect.Right);
2055320568
end;

0 commit comments

Comments
 (0)