SourceEdit, completion: Scale icons to match font height.

This commit is contained in:
Martin 2023-12-10 19:48:09 +01:00
parent 2f37d08e22
commit 31f39995af

View File

@ -36,9 +36,9 @@ unit SourceEditProcs;
interface interface
uses uses
Classes, SysUtils, RegExpr, Types, Classes, SysUtils, RegExpr, Types, Math,
// LCL // LCL
LCLType, Graphics, Controls, LCLIntf, LCLType, Graphics, Controls, LCLIntf, ImgList,
// LazUtils // LazUtils
LazFileUtils, LazStringUtils, LazFileUtils, LazStringUtils,
// SynEdit // SynEdit
@ -185,6 +185,34 @@ var
Result := aCompletion.TheForm.Scale96ToForm(APadding); Result := aCompletion.TheForm.Scale96ToForm(APadding);
end; end;
function GetImgListRes(const AImages: TLCLGlyphs; ALineHeight: integer): TScaledImageListResolution;
const
//AllowedHeights: array[0..4] of Integer = (8, 12, 16, 24, 32);
AllowedHeights: array[0..8] of Integer = (8, 10, 12, 14, 16, 20, 24, 28, 32);
var
Scale: Double;
PPI, I, ImageHeight: Integer;
begin
Scale := 1;
PPI := 96;
ALineHeight := max(ALineHeight, aCompletion.FontHeight);
if ALineHeight > 16 then
ALineHeight := max(16, ALineHeight - GetPaddingScaled(1));
ImageHeight := AllowedHeights[0];
for I := High(AllowedHeights) downto Low(AllowedHeights) do
if AllowedHeights[I] <= ALineHeight then
begin
ImageHeight := AllowedHeights[I];
break;
end;
// don't set PPI here -> we don't want to scale the image anymore
if ACanvas is TControlCanvas then
Scale := TControlCanvas(ACanvas).Control.GetCanvasScaleFactor;
Result := AImages.ResolutionForPPI[ImageHeight, PPI, Scale];
end;
procedure SetFontColor(NewColor: TColor; Force: boolean = false); procedure SetFontColor(NewColor: TColor; Force: boolean = false);
{procedure IncreaseDiff(var Value: integer; BaseValue: integer); {procedure IncreaseDiff(var Value: integer; BaseValue: integer);
@ -302,12 +330,12 @@ var
IsReadOnly: boolean; IsReadOnly: boolean;
UseImages: boolean; UseImages: boolean;
ImageIndex, ImageIndexCC: longint; ImageIndex, ImageIndexCC: longint;
ImageScaledSize: TSize;
Token: String; Token: String;
PrefixPosition: Integer; PrefixPosition: Integer;
HintModifiers: TPascalHintModifiers; HintModifiers: TPascalHintModifiers;
HintModifier: TPascalHintModifier; HintModifier: TPascalHintModifier;
HelperForNode: TCodeTreeNode; HelperForNode: TCodeTreeNode;
ScaledImgList: TScaledImageListResolution;
begin begin
SetBkMode(ACanvas.Handle, TRANSPARENT); SetBkMode(ACanvas.Handle, TRANSPARENT);
@ -537,17 +565,19 @@ begin
s:=''; s:='';
end; end;
ImageScaledSize := IDEImages.Images_16.SizeForPPI[16, aCompletion.TheForm.PixelsPerInch]; ScaledImgList := GetImgListRes(IDEImages.Images_16, Result.Y);
if UseImages then if UseImages then
begin begin
// drawing type image // drawing type image
if MeasureOnly then if MeasureOnly then
Inc(Result.X, ImageScaledSize.Width + (ImageScaledSize.Width div 4)) Inc(Result.X, ScaledImgList.Width + round(ScaledImgList.Width / 4))
else else
if ImageIndexCC >= 0 then begin
IDEImages.Images_16.DrawForPPI (ACanvas, x+GetPaddingScaled(1), y+(Result.Y-ImageScaledSize.Height) div 2, ImageIndexCC, 16, aCompletion.TheForm.PixelsPerInch, 1); if ImageIndexCC >= 0 then
Inc(x, ImageScaledSize.Width + (ImageScaledSize.Width div 4)) ScaledImgList.Draw(ACanvas, x+1, y+(Result.Y-ScaledImgList.Height) div 2, ImageIndexCC);
end;
Inc(x,ScaledImgList.Width + round(ScaledImgList.Width / 4));
end end
else else
begin begin
@ -612,12 +642,12 @@ begin
begin begin
if ImageIndex>=0 then if ImageIndex>=0 then
if MeasureOnly then if MeasureOnly then
Inc(Result.X, ImageScaledSize.Width + (ImageScaledSize.Width div 4)) Inc(Result.X, ScaledImgList.Width + GetPaddingScaled(2))
else begin else begin
IDEImages.Images_16.DrawForPPI (ACanvas, x+GetPaddingScaled(1), y+(Result.Y-ImageScaledSize.Height) div 2, ImageIndex, 16, aCompletion.TheForm.PixelsPerInch, 1); ScaledImgList.Draw(ACanvas,x+1,y+(Result.Y-ScaledImgList.Height) div 2,ImageIndex);
Inc(x, ImageScaledSize.Width + (ImageScaledSize.Width div 4)); inc(x,ScaledImgList.Width + GetPaddingScaled(2));
if x>MaxX then exit; if x>MaxX then exit;
end; end;
end; end;
// finally paint the type/value/parameters // finally paint the type/value/parameters