Line | |
---|
1 | unit uscaledpi;
|
---|
2 |
|
---|
3 | {$mode objfpc}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Forms, Graphics, Controls;
|
---|
9 |
|
---|
10 | procedure HighDPI(FromDPI: integer);
|
---|
11 | procedure ScaleDPI(Control: TControl; FromDPI: integer);
|
---|
12 |
|
---|
13 | implementation
|
---|
14 |
|
---|
15 | uses BGRABitmap, BGRABitmapTypes;
|
---|
16 |
|
---|
17 | procedure HighDPI(FromDPI: integer);
|
---|
18 | var
|
---|
19 | i: integer;
|
---|
20 | begin
|
---|
21 | for i := 0 to Screen.FormCount - 1 do
|
---|
22 | ScaleDPI(Screen.Forms[i], FromDPI);
|
---|
23 | end;
|
---|
24 |
|
---|
25 | procedure ScaleDPI(Control: TControl; FromDPI: integer);
|
---|
26 | var
|
---|
27 | i: integer;
|
---|
28 | WinControl: TWinControl;
|
---|
29 | begin
|
---|
30 | if Screen.PixelsPerInch = FromDPI then
|
---|
31 | exit;
|
---|
32 |
|
---|
33 | with Control do
|
---|
34 | begin
|
---|
35 | Left := ScaleX(Left, FromDPI);
|
---|
36 | Top := ScaleY(Top, FromDPI);
|
---|
37 | Width := ScaleX(Width, FromDPI);
|
---|
38 | Height := ScaleY(Height, FromDPI);
|
---|
39 | //Font.Height := ScaleY(Font.GetTextHeight('Hg'),FromDPI);
|
---|
40 | end;
|
---|
41 |
|
---|
42 | if Control is TWinControl then
|
---|
43 | begin
|
---|
44 | WinControl := TWinControl(Control);
|
---|
45 | if WinControl.ControlCount = 0 then
|
---|
46 | exit;
|
---|
47 | for i := 0 to WinControl.ControlCount - 1 do
|
---|
48 | ScaleDPI(WinControl.Controls[i], FromDPI);
|
---|
49 | end;
|
---|
50 | end;
|
---|
51 |
|
---|
52 | end.
|
---|
Note:
See
TracBrowser
for help on using the repository browser.