This repository has been archived by the owner on Mar 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuscaledpi.pas
79 lines (63 loc) · 1.69 KB
/
uscaledpi.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
unit uScaleDPI;
{$mode objfpc}{$H+}
interface
uses
Forms, Graphics, Controls, StdCtrls, ExtCtrls, ComCtrls;
procedure HighDPI(FromDPI: integer);
procedure ScaleDPI(Control: TControl; FromDPI: integer);
implementation
procedure HighDPI(FromDPI: integer);
var
i: integer;
begin
if Screen.PixelsPerInch = FromDPI then
exit;
for i := 0 to Screen.FormCount - 1 do
ScaleDPI(Screen.Forms[i], FromDPI);
end;
procedure ScaleDPI(Control: TControl; FromDPI: integer);
var
i: integer;
WinControl: TWinControl;
begin
if Screen.PixelsPerInch = FromDPI then
exit;
with Control do
begin
{$IF NOT Defined(DARWIN)}
if Control is TImage then
begin
(Control as TImage).AutoSize := False;
(Control as TImage).Proportional := True;
(Control as TImage).Stretch := True;
end;
{$ENDIF}
Left := ScaleX(Left, FromDPI);
{$IF NOT Defined(DARWIN)}
Top := ScaleY(Top, FromDPI);
{$ENDIF}
Width := ScaleX(Width, FromDPI);
{$IFDEF DARWIN}
if (not (Control is TPageControl) and not (Control is TTabSheet) and not (Control is TButton)) then
{$ENDIF}
Height := ScaleY(Height, FromDPI);
end;
if Control is TWinControl then
begin
WinControl := TWinControl(Control);
if WinControl.ControlCount = 0 then
exit;
for i := 0 to WinControl.ControlCount - 1 do
ScaleDPI(WinControl.Controls[i], FromDPI);
end;
end;
end.
{
uses
uScaleDPI;
procedure TForm1.FormCreate(Sender: TObject);
begin
ScaleDPI(Self, 96); // the designtime DPI
end;
Project - Project Options - Use manifest file to enable themes, Enabled DPI Awareness
}