From 8c898cd63a8fcde16767c0915168e9e33a9c34b3 Mon Sep 17 00:00:00 2001 From: wp_xyz Date: Thu, 25 Aug 2022 09:57:47 +0200 Subject: [PATCH] Designer: TScrollingWinControl paints design-time grid only on visible area. Issue #39866. Based on work by German forum user "siro". (cherry picked from commit b9c4368fce7b01c883147d229616ce416b3f9978) --- designer/designer.pp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/designer/designer.pp b/designer/designer.pp index edc90ce761..5fa8b620ca 100644 --- a/designer/designer.pp +++ b/designer/designer.pp @@ -3185,6 +3185,11 @@ begin end; end; +function RoundToMultiple(AValue, ABasis: Integer): Integer; inline; +begin + Result := AValue div ABasis * ABasis; +end; + procedure TDesigner.PaintClientGrid(AWinControl: TWinControl; aDDC: TDesignerDeviceContext); var @@ -3192,6 +3197,8 @@ var Count: integer; i: integer; CurControl: TControl; + R, R1: TRect; + P: TPoint; begin if (AWinControl=nil) or (not (csAcceptsControls in AWinControl.ControlStyle)) @@ -3218,8 +3225,11 @@ begin ADDC.Canvas.Pen.Color := GridColor; ADDC.Canvas.Pen.Width := 1; ADDC.Canvas.Pen.Style := psSolid; - DrawGrid(ADDC.Canvas.Handle, TWinControlAccess(AWinControl).GetLogicalClientRect, - GridSizeX, GridSizeY); + P := TWinControlAccess(AWinControl).GetClientScrollOffset; + R := AWinControl.ClientRect; + R.BottomRight := R.BottomRight + Point(GridSizeX, GridSizeY); + OffsetRect(R, RoundToMultiple(P.X, GridSizeX), RoundToMultiple(P.Y, GridSizeY)); + DrawGrid(ADDC.Canvas.Handle, R, GridSizeX, GridSizeY); end; if ShowBorderSpacing then