From 3f21545b7dc2312de535a2fa19d8f0dd8993eaf5 Mon Sep 17 00:00:00 2001 From: ondrej Date: Thu, 17 Aug 2017 10:39:39 +0000 Subject: [PATCH] synedit: high-DPI: implement DoAutoAdjustLayout. issue #31753 git-svn-id: trunk@55675 - --- components/synedit/synedit.pp | 15 ++++++++ components/synedit/syngutterbase.pp | 15 ++++++++ components/synedit/synguttercodefolding.pp | 40 ++++++++++++--------- components/synedit/syngutterlineoverview.pp | 10 +++++- 4 files changed, 62 insertions(+), 18 deletions(-) diff --git a/components/synedit/synedit.pp b/components/synedit/synedit.pp index d79198c05d..07fc5075e5 100644 --- a/components/synedit/synedit.pp +++ b/components/synedit/synedit.pp @@ -784,6 +784,8 @@ type property PaintLockOwner: TSynEditBase read GetPaintLockOwner write SetPaintLockOwner; property TextDrawer: TheTextDrawer read fTextDrawer; + procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy; + const AXProportion, AYProportion: Double); override; protected procedure CreateHandle; override; procedure CreateParams(var Params: TCreateParams); override; @@ -8229,6 +8231,19 @@ begin inherited DestroyWnd; end; +procedure TCustomSynEdit.DoAutoAdjustLayout( + const AMode: TLayoutAdjustmentPolicy; const AXProportion, AYProportion: Double + ); +begin + inherited DoAutoAdjustLayout(AMode, AXProportion, AYProportion); + + if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then + begin + FLeftGutter.ScalePPI(AXProportion); + FRightGutter.ScalePPI(AXProportion); + end; +end; + procedure TCustomSynEdit.DoBlockIndent; var BB,BE : TPoint; diff --git a/components/synedit/syngutterbase.pp b/components/synedit/syngutterbase.pp index 4a7cb342a2..336ec71485 100644 --- a/components/synedit/syngutterbase.pp +++ b/components/synedit/syngutterbase.pp @@ -71,6 +71,7 @@ type destructor Destroy; override; procedure Assign(Source: TPersistent); override; procedure RecalcBounds; + procedure ScalePPI(const AScaleFactor: Double); function MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo; HandleActionProc: TSynEditMouseActionHandler): Boolean; virtual; procedure ResetMouseActions; virtual; // set mouse-actions according to current Options / may clear them @@ -190,6 +191,7 @@ type property Height:Integer read FHeight; procedure Paint(Canvas: TCanvas; AClip: TRect; FirstLine, LastLine: integer); virtual abstract; + procedure ScalePPI(const AScaleFactor: Double); virtual; public // X/Y are relative to the gutter, not the gutter part function HasCustomPopupMenu(out PopMenu: TPopupMenu): Boolean; virtual; @@ -322,6 +324,14 @@ begin FMouseActions.ResetUserActions; end; +procedure TSynGutterBase.ScalePPI(const AScaleFactor: Double); +var + I: Integer; +begin + for I := 0 to PartCount-1 do + Parts[I].ScalePPI(AScaleFactor); +end; + procedure TSynGutterBase.RegisterResizeHandler(AHandler: TNotifyEvent); begin FOnResizeHandler.Add(TMethod(AHandler)); @@ -745,6 +755,11 @@ begin FMouseActions.ResetUserActions; end; +procedure TSynGutterPartBase.ScalePPI(const AScaleFactor: Double); +begin + Width := Round(Width*AScaleFactor); +end; + procedure TSynGutterPartBase.DoOnGutterClick(X, Y : integer); begin if Assigned(FOnGutterClick) then diff --git a/components/synedit/synguttercodefolding.pp b/components/synedit/synguttercodefolding.pp index 7351a75d09..a510f2087a 100644 --- a/components/synedit/synguttercodefolding.pp +++ b/components/synedit/synguttercodefolding.pp @@ -98,6 +98,7 @@ type function DoHandleMouseAction(AnAction: TSynEditMouseAction; var AnInfo: TSynEditMouseActionInfo): Boolean; override; procedure ResetMouseActions; override; // set mouse-actions according to current Options / may clear them + procedure ScalePPI(const AScaleFactor: Double); override; published property MarkupInfo; property MouseActionsExpanded: TSynEditMouseActions @@ -484,11 +485,17 @@ begin FMouseActionsCollapsed.ResetUserActions; end; +procedure TSynGutterCodeFolding.ScalePPI(const AScaleFactor: Double); +begin + AutoSize := False; + inherited ScalePPI(AScaleFactor); +end; + procedure TSynGutterCodeFolding.DrawNodeSymbol(Canvas: TCanvas; Rect: TRect; NodeType: TSynEditFoldLineCapability; SubType: TDrawNodeSymbolOptions); var Points: Array [0..3] of TPoint; - X, Y: Integer; + X, Y, LineBorder: Integer; AliasMode: TAntialiasingMode; OdlCosmetic: Boolean; begin @@ -506,6 +513,7 @@ begin Canvas.Rectangle(Rect); Canvas.Pen.Style := psSolid; Canvas.Pen.Cosmetic := OdlCosmetic; + LineBorder := Round((Rect.Right-Rect.Left) / 5); X := (Rect.Left - 1 + Rect.Right) div 2; Y := (Rect.Top - 1 + Rect.Bottom) div 2; @@ -513,8 +521,8 @@ begin cfFoldStart: begin // [-] - Canvas.MoveTo(X - 2, Y); - Canvas.LineTo(X + 3, Y); + Canvas.MoveTo(Rect.Left + LineBorder, Y); + Canvas.LineTo(Rect.Right - LineBorder, Y); end; cfHideStart: begin @@ -525,10 +533,10 @@ begin cfCollapsedFold: begin // [+] - Canvas.MoveTo(X - 2, Y); - Canvas.LineTo(X + 3, Y); - Canvas.MoveTo(X, Y - 2); - Canvas.LineTo(X, Y + 3); + Canvas.MoveTo(Rect.Left + LineBorder, Y); + Canvas.LineTo(Rect.Right - LineBorder, Y); + Canvas.MoveTo(X, Rect.Top + LineBorder); + Canvas.LineTo(X, Rect.Bottom - LineBorder); end; cfCollapsedHide: begin @@ -536,24 +544,22 @@ begin false: begin // [v] Points[0].X := X; - Points[0].y := Y + 2; - Points[1].X := X - 2; + Points[0].y := Rect.Bottom - LineBorder - 1; + Points[1].X := Rect.Left + LineBorder; Points[1].y := Y; - Points[2].X := X + 2; + Points[2].X := Rect.Right - LineBorder - 1; Points[2].y := Y; - Points[3].X := X; - Points[3].y := Y + 2; + Points[3] := Points[0]; end; true: begin // [v] Points[0].X := X; - Points[0].y := Y - 2; - Points[1].X := X - 2; + Points[0].y := Rect.Top + LineBorder; + Points[1].X := Rect.Left + LineBorder; Points[1].y := Y; - Points[2].X := X + 2; + Points[2].X := Rect.Right - LineBorder - 1; Points[2].y := Y; - Points[3].X := X; - Points[3].y := Y - 2; + Points[3] := Points[0]; end; end; Canvas.Polygon(Points); diff --git a/components/synedit/syngutterlineoverview.pp b/components/synedit/syngutterlineoverview.pp index aa0e496136..683f19c228 100644 --- a/components/synedit/syngutterlineoverview.pp +++ b/components/synedit/syngutterlineoverview.pp @@ -319,6 +319,7 @@ type procedure Assign(Source: TPersistent); override; procedure Paint(Canvas: TCanvas; AClip: TRect; FirstLine, LastLine: integer); override; procedure AddMark(AMark: TSynGutterLOvMark); + procedure ScalePPI(const AScaleFactor: Double); override; function MaybeHandleMouseAction(var AnInfo: TSynEditMouseActionInfo; HandleActionProc: TSynEditMouseActionHandler): Boolean; override; @@ -1041,7 +1042,7 @@ var begin if FFirstTextLineChanged > 0 then ReScan; - AClip.Right := AClip.Left + 3; + AClip.Right := Round((AClip.Right - AClip.Left) / 3); i := AClip.Top - TopOffset; imax := AClip.Bottom - TopOffset; if imax > high(FPixLineStates) then imax := high(FPixLineStates); @@ -1541,6 +1542,13 @@ begin Result := 10; end; +procedure TSynGutterLineOverview.ScalePPI(const AScaleFactor: Double); +begin + AutoSize := False; + FLineMarks.ItemHeight := Round(FLineMarks.ItemHeight*AScaleFactor); + inherited ScalePPI(AScaleFactor); +end; + procedure TSynGutterLineOverview.Assign(Source : TPersistent); begin if Assigned(Source) and (Source is TSynGutterLineOverview) then