mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 17:19:22 +02:00
IdeIntf: High-DPI: support scale factors above 200%. Issue #32280
git-svn-id: trunk@55674 -
This commit is contained in:
parent
d969149f29
commit
f215e1f571
@ -46,6 +46,7 @@ type
|
|||||||
function GetImages_24: TCustomImageList;
|
function GetImages_24: TCustomImageList;
|
||||||
|
|
||||||
class function CreateBitmapFromRes(const ImageName: string): TCustomBitmap;
|
class function CreateBitmapFromRes(const ImageName: string): TCustomBitmap;
|
||||||
|
class function CreateBestBitmapForScalingFromRes(const ImageName: string; const aDefScale: Integer; out aBitmap: TCustomBitmap): Integer;
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -121,7 +122,7 @@ begin
|
|||||||
if ScreenInfo.PixelsPerInchX <= 168 then
|
if ScreenInfo.PixelsPerInchX <= 168 then
|
||||||
Result := 150 // 126%-175% (144-168 DPI): 150% scaling
|
Result := 150 // 126%-175% (144-168 DPI): 150% scaling
|
||||||
else
|
else
|
||||||
Result := 200; // 200%: 200% scaling
|
Result := Round(ScreenInfo.PixelsPerInchX/96) * 100; // 200, 300, 400, ...
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TIDEImages.LoadImage(ImageSize: Integer; ImageName: String): Integer;
|
function TIDEImages.LoadImage(ImageSize: Integer; ImageName: String): Integer;
|
||||||
@ -134,28 +135,17 @@ class function TIDEImages.CreateImage(ImageName: String; ImageSize: Integer
|
|||||||
var
|
var
|
||||||
Grp: TCustomBitmap;
|
Grp: TCustomBitmap;
|
||||||
GrpScaledNewInstance: Boolean;
|
GrpScaledNewInstance: Boolean;
|
||||||
ScalePercent: Integer;
|
ScalePercent, GrpScale: Integer;
|
||||||
begin
|
begin
|
||||||
ScalePercent := GetScalePercent;
|
ScalePercent := GetScalePercent;
|
||||||
|
|
||||||
Grp := nil;
|
Grp := nil;
|
||||||
try
|
try
|
||||||
if ScalePercent<>100 then
|
GrpScale := CreateBestBitmapForScalingFromRes(ImageName, ScalePercent, Grp);
|
||||||
begin
|
|
||||||
Grp := CreateBitmapFromRes(ImageName+'_'+IntToStr(ScalePercent));
|
|
||||||
if Grp<>nil then
|
|
||||||
begin
|
|
||||||
Result := Grp;
|
|
||||||
Grp := nil;
|
|
||||||
Exit; // found
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
Grp := CreateBitmapFromRes(ImageName);
|
|
||||||
if Grp<>nil then
|
if Grp<>nil then
|
||||||
begin
|
begin
|
||||||
Result := ScaleImage(Grp, GrpScaledNewInstance,
|
Result := ScaleImage(Grp, GrpScaledNewInstance,
|
||||||
ImageSize*ScalePercent div 100, ImageSize * ScalePercent div 100, ScalePercent / 100);
|
MulDiv(ImageSize, ScalePercent, GrpScale), MulDiv(ImageSize, ScalePercent, GrpScale), ScalePercent / GrpScale);
|
||||||
if not GrpScaledNewInstance then
|
if not GrpScaledNewInstance then
|
||||||
Grp := nil;
|
Grp := nil;
|
||||||
Exit; // found
|
Exit; // found
|
||||||
@ -223,6 +213,24 @@ begin
|
|||||||
Result := CreateBitmapFromResourceName(HInstance, ImageName);
|
Result := CreateBitmapFromResourceName(HInstance, ImageName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function TIDEImages.CreateBestBitmapForScalingFromRes(
|
||||||
|
const ImageName: string; const aDefScale: Integer; out aBitmap: TCustomBitmap
|
||||||
|
): Integer;
|
||||||
|
begin
|
||||||
|
aBitmap := nil;
|
||||||
|
Result := aDefScale;
|
||||||
|
while (Result > 100) do
|
||||||
|
begin
|
||||||
|
aBitmap := CreateBitmapFromRes(ImageName+'_'+IntToStr(Result));
|
||||||
|
if aBitmap<>nil then Exit;
|
||||||
|
if (Result>300) and ((Result div 100) mod 2 = 1) then // 500, 700, 900 ...
|
||||||
|
Result := Result + 100;
|
||||||
|
Result := Result div 2;
|
||||||
|
end;
|
||||||
|
aBitmap := CreateBitmapFromRes(ImageName);
|
||||||
|
Result := 100;
|
||||||
|
end;
|
||||||
|
|
||||||
class function TIDEImages.CreateImage(ImageSize: Integer; ImageName: String
|
class function TIDEImages.CreateImage(ImageSize: Integer; ImageName: String
|
||||||
): TCustomBitmap;
|
): TCustomBitmap;
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user