From 9fea3ea40ca93ca7db67a3e32cfa17e003f7a41d Mon Sep 17 00:00:00 2001 From: ondrej Date: Thu, 17 Aug 2017 17:40:05 +0000 Subject: [PATCH] synedit: high-DPI fixes. issue #31753 git-svn-id: trunk@55677 - --- components/synedit/synguttercodefolding.pp | 63 ++++++++++++++------- components/synedit/syngutterlineoverview.pp | 2 +- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/components/synedit/synguttercodefolding.pp b/components/synedit/synguttercodefolding.pp index a510f2087a..c14abe896b 100644 --- a/components/synedit/synguttercodefolding.pp +++ b/components/synedit/synguttercodefolding.pp @@ -27,8 +27,9 @@ unit SynGutterCodeFolding; interface uses - SysUtils, Classes, Controls, Graphics, Menus, LCLIntf, SynGutterBase, SynEditMiscProcs, - SynEditFoldedView, SynEditMouseCmds, SynEditHighlighterFoldBase, LCLProc, LCLType, ImgList; + SysUtils, Classes, Controls, Graphics, Menus, LCLIntf, SynGutterBase, + SynEditMiscProcs, SynEditFoldedView, SynEditMouseCmds, + SynEditHighlighterFoldBase, LCLProc, LCLType, ImgList, Forms; type @@ -59,6 +60,11 @@ type TDrawNodeSymbolOptions = set of (nsoSubtype, nsoLostHl, nsoBlockSel); + TSynGutterImageList = class(TImageList) + public + InitPPI: Integer; + end; + { TSynGutterCodeFolding } TSynGutterCodeFolding = class(TSynGutterPartBase) @@ -68,8 +74,9 @@ type FPopUp: TPopupMenu; FMenuInf: Array of TFoldViewNodeInfo; FIsFoldHidePreviousLine: Boolean; - FPopUpImageList: TImageList; + FPopUpImageList: TSynGutterImageList; FReversePopMenuOrder: Boolean; + procedure FPopUpOnPopup(Sender: TObject); function GetMouseActionsCollapsed: TSynEditMouseActions; function GetMouseActionsExpanded: TSynEditMouseActions; procedure SetMouseActionsCollapsed(const AValue: TSynEditMouseActions); @@ -77,7 +84,7 @@ type function FoldTypeForLine(AScreenLine: Integer): TSynEditFoldLineCapability; function IsFoldHidePreviousLine(AScreenLine: Integer): Boolean; function IsSingleLineHide(AScreenLine: Integer): Boolean; - procedure InitPopUpImageList; + procedure InitPopUpImageList(const APPI: Integer); procedure DrawNodeSymbol(Canvas: TCanvas; Rect: TRect; NodeType: TSynEditFoldLineCapability; SubType: TDrawNodeSymbolOptions); @@ -114,7 +121,7 @@ uses SynEdit; var - GlobalPopUpImageList: TImageList = nil; + GlobalPopUpImageList: TSynGutterImageList = nil; { TSynGutterCodeFolding } @@ -185,6 +192,15 @@ begin end; end; +procedure TSynGutterCodeFolding.FPopUpOnPopup(Sender: TObject); +var + MonitorPPI: Integer; +begin + MonitorPPI := Screen.MonitorFromPoint(FPopUp.PopupPoint).PixelsPerInch; + if (FPopUpImageList.Count=0) or (FPopUpImageList.InitPPI<>MonitorPPI) then + InitPopUpImageList(MonitorPPI); +end; + function TSynGutterCodeFolding.IsFoldHidePreviousLine(AScreenLine: Integer): Boolean; begin FoldTypeForLine(AScreenLine); @@ -205,40 +221,49 @@ begin Result := True; end; -procedure TSynGutterCodeFolding.InitPopUpImageList; +procedure TSynGutterCodeFolding.InitPopUpImageList(const APPI: Integer); var img: TBitmap; + R: TRect; procedure NewImg; begin img := TBitmap.Create; - img.SetSize(16, 16); + img.SetSize(FPopUpImageList.Width, FPopUpImageList.Height); img.Canvas.Brush.Color := clWhite; - img.Canvas.FillRect(0,0,16,16); - img.TransparentColor := clWhite; + img.Canvas.FillRect(img.Canvas.ClipRect); img.Canvas.Pen.Color := clBlack; img.Canvas.Pen.Width := 1; end; begin FPopUpImageList.DrawingStyle := dsTransparent; + FPopUpImageList.Clear; + FPopUpImageList.Width := MulDiv(16, APPI, 96); + FPopUpImageList.Height := FPopUpImageList.Width; + FPopUpImageList.InitPPI := APPI; + + R.Left := MulDiv(3, APPI, 96); + R.Top := R.Left; + R.Right := MulDiv(14, APPI, 96); + R.Bottom := R.Right; NewImg; - DrawNodeSymbol(img.Canvas, Rect(3,3,14,14), cfFoldStart, []); // [-] - FPopUpImageList.Add(img, nil); + DrawNodeSymbol(img.Canvas, R, cfFoldStart, []); // [-] + FPopUpImageList.AddMasked(img, img.TransparentColor); img.Free; NewImg; - DrawNodeSymbol(img.Canvas, Rect(3,3,14,14), cfCollapsedFold, []); // [+] - FPopUpImageList.Add(img, nil); + DrawNodeSymbol(img.Canvas, R, cfCollapsedFold, []); // [+] + FPopUpImageList.AddMasked(img, img.TransparentColor); img.Free; NewImg; - DrawNodeSymbol(img.Canvas, Rect(3,3,14,14), cfHideStart, []); // [.] - FPopUpImageList.Add(img, nil); + DrawNodeSymbol(img.Canvas, R, cfHideStart, []); // [.] + FPopUpImageList.AddMasked(img, img.TransparentColor); img.Free; NewImg; - DrawNodeSymbol(img.Canvas, Rect(3,3,14,14), cfCollapsedHide, []); // [v] - FPopUpImageList.Add(img, nil); + DrawNodeSymbol(img.Canvas, R, cfCollapsedHide, []); // [v] + FPopUpImageList.AddMasked(img, img.TransparentColor); img.Free; end; @@ -268,15 +293,15 @@ begin if not assigned(GlobalPopUpImageList) then begin // Todo: Add a flag, when using global list, or make list ref-counted // See Destroy - GlobalPopUpImageList := TImageList.Create(nil); + GlobalPopUpImageList := TSynGutterImageList.Create(nil); FPopUpImageList := GlobalPopUpImageList; - InitPopUpImageList; end else FPopUpImageList := GlobalPopUpImageList; APopUp := TPopupMenu.Create(nil); APopUp.Images := FPopUpImageList; + APopUp.OnPopup := @FPopUpOnPopup; end else APopUp.Items.Clear; diff --git a/components/synedit/syngutterlineoverview.pp b/components/synedit/syngutterlineoverview.pp index 683f19c228..8c3a7238ca 100644 --- a/components/synedit/syngutterlineoverview.pp +++ b/components/synedit/syngutterlineoverview.pp @@ -1042,7 +1042,7 @@ var begin if FFirstTextLineChanged > 0 then ReScan; - AClip.Right := Round((AClip.Right - AClip.Left) / 3); + AClip.Right := AClip.Left + Round((AClip.Right - AClip.Left) / 3); i := AClip.Top - TopOffset; imax := AClip.Bottom - TopOffset; if imax > high(FPixLineStates) then imax := high(FPixLineStates);