From 8c5aa34fba56ed9945fbb77d24a15d39c6a327bc Mon Sep 17 00:00:00 2001 From: ondrej Date: Tue, 5 Jun 2018 07:31:39 +0000 Subject: [PATCH] LCL: TLCLGlyphs: fix loading images. Issue #33826 git-svn-id: trunk@58131 - --- lcl/imglist.pp | 2 ++ lcl/include/imglist.inc | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lcl/imglist.pp b/lcl/imglist.pp index 8470a23fdb..9e95bc27b5 100644 --- a/lcl/imglist.pp +++ b/lcl/imglist.pp @@ -298,6 +298,7 @@ type const ACanvasScaleFactor: Double): TScaledImageListResolution; function GetWidthForPPI(AImageWidth, APPI: Integer): Integer; function GetHeightForPPI(AImageWidth, APPI: Integer): Integer; + function GetHeightForWidth(AWidth: Integer): Integer; function GetCount: Integer; function GetSizeForPPI(AImageWidth, APPI: Integer): TSize; function GetBestIconIndexForSize(AIcon: TCustomIcon; AWidth: Integer): Integer; // the icon must be sorted @@ -400,6 +401,7 @@ type property DrawingStyle: TDrawingStyle read FDrawingStyle write SetDrawingStyle default dsNormal; property Height: Integer read FHeight write SetHeight default 16; property HeightForPPI[AImageWidth, APPI: Integer]: Integer read GetHeightForPPI; + property HeightForWidth[AWidth: Integer]: Integer read GetHeightForWidth; property Width: Integer read FWidth write SetWidth default 16; property WidthForPPI[AImageWidth, APPI: Integer]: Integer read GetWidthForPPI; property SizeForPPI[AImageWidth, APPI: Integer]: TSize read GetSizeForPPI; diff --git a/lcl/include/imglist.inc b/lcl/include/imglist.inc index fe6a13733f..b32fcbf4e2 100644 --- a/lcl/include/imglist.inc +++ b/lcl/include/imglist.inc @@ -1183,7 +1183,7 @@ begin Result.FImageList := FImageList; Result.FWidth := AImageWidth; if FImageList.Width<>0 then - Result.FHeight := FImageList.Height * AImageWidth div FImageList.Width + Result.FHeight := FImageList.GetHeightForWidth(AImageWidth) else Result.FHeight := 0; Result.FAutoCreatedInDesignTime := AutoCreatedInDesignTime and (AImageWidth<>FImageList.Width); @@ -1804,12 +1804,15 @@ begin if FData.Find(AImageWidth, I) then Result := FData[I].Height else - begin - if FWidth<>0 then - Result := AImageWidth * FHeight div FWidth - else - Result := 0; - end; + Result := GetHeightForWidth(AImageWidth) +end; + +function TCustomImageList.GetHeightForWidth(AWidth: Integer): Integer; +begin + if FWidth<>0 then + Result := AWidth * FHeight div FWidth + else + Result := 0; end; procedure TCustomImageList.GetIcon(Index: Integer; Image: TIcon; AEffect: TGraphicsDrawEffect); @@ -2724,12 +2727,15 @@ function TLCLGlyphs.GetImageIndex(const AResourceName: string): Integer; function AddNewBtnImage(Resolution: TResolution): Integer; var G: TCustomBitmap; + ImageRect: TRect; begin G := GetDefaultGlyph(AResourceName, Resolution.ScaleSuffix, True); if G=nil then Exit(-1); try - Result := AddSliceCentered(G); + ImageRect := Rect(0, 0, Resolution.Width, GetHeightForWidth(Resolution.Width)); + OffsetRect(ImageRect, (G.Width-ImageRect.Right) div 2, (G.Height-ImageRect.Bottom) div 2); + Result := AddSlice(G, ImageRect); finally G.Free; end;