Recent

Author Topic: High DPI Help  (Read 3635 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
High DPI Help
« on: August 18, 2021, 02:54:10 pm »
Hello Guys :)

I tried this Tutorial : https://wiki.lazarus.freepascal.org/High_DPI/de#SCHRITT_1_-_Deklarieren_Sie_High_DPI_Awareness

But it did just work half way. If windows is trying to Scale the Application it gets blurred (if i don't mistake  :-[ ... sorry heard of this the first time today). i will add some attachements with Pictures how it looks.

I do achiev to get a Sharp(non blurred) picture, but thats all. I did not Fully understand the Tutorail so i wanted to ask if some1 could tell me how i should handle every Single Control in relation to the Scaling. I did Position every Single Component with "Anchors".

here some Code which might impact this

Form Resize Procedure:
Code: Pascal  [Select][+][-]
  1. procedure TStartUp.FormResize(Sender: TObject);
  2. var
  3.    i : Integer;
  4. begin
  5.    // Größe und Position der Steuerelemente anpassen
  6.    GroupBox1.Width := Self.Width - 16;
  7.    TxProjectNr.Width := round(160 + (GroupBox1.Width - 920) / 3);
  8.    TxClient.Width := TxProjectNr.Width;
  9.    TxPosition.Width := TxProjectNr.Width;
  10.    TxBuilding.Width := TxProjectNr.Width;
  11.    TxArrange.Width := TxProjectNr.Width;
  12.  
  13.    // Devicedata Box
  14.    ZLDeviceData.Width := round((Self.Width - 24) / 2);
  15.    ALDeviceData.Width := ZLDeviceData.Width;
  16.  
  17.    //Zuluft
  18.    TxSUairflow.Width := round((ZLDeviceData.Width - (920 / 2)) / 3.5);
  19.    LblSUtype.Width := TxSUairflow.Width;
  20.    TxSUdpext.Width:= round((ZLDeviceData.Width - (920 / 2)) / 3.5);
  21.    TxSUdptot.Width:= TxSUairflow.Width;
  22.    CBSUacc.Width:= TxSUairflow.Width;
  23.    CBSUconn.Width:= TxSUairflow.Width;
  24.    BtnSUsize.Width:= round((TxSUdptot.Width / 3) * 2) - 4;
  25.    SUSize.Width:= round(TxSUdptot.Width / 3) - 4;
  26.  
  27.    //Abluft
  28.    TxEXairflow.Width := round((ZLDeviceData.Width - (920 / 2)) / 3.5);
  29.    LblEXtype.Width := TxEXairflow.Width;
  30.    TxEXdpext.Width:= round((ZLDeviceData.Width - (920 / 2)) / 3.5);
  31.    TxEXdptot.Width:= TxEXairflow.Width;
  32.    CBEXacc.Width:= TxEXairflow.Width;
  33.    CBEXconn.Width:= TxEXairflow.Width;
  34.    BtnEXsize.Width:= round((TxEXdptot.Width / 3) * 2) - 4;
  35.    EXSize.Width:= round(TxEXdptot.Width / 3) - 4;
  36.  
  37.    // Zeichenfläche
  38.    Drw.Top:= ZLDeviceData.Top + ZLDeviceData.Height + 8;
  39.    Drw.Width := Self.Width - 24 - GBAirDir.Width;
  40.    Drw.Height := Self.Height - Drw.top - 30;
  41.  
  42.    // Skalierung der Zeichenfläche anpassen
  43.    ScaleDRW;
  44.  
  45.    // Größe der Icons anpassen (müssen nochmals neu geladen werden)
  46.    InitBTLIcons;
  47.    InitBTLWkzIcons;
  48. end;
  49.  

Wrote this in FormCreate of MainForm (Just to test on main Form) :

ScaleDPI(Self, 96); // 96 DesignTime DPI Wert

Any Help would be Welcome (Excuse my English ... still young, still learning)

Ps: Pictures Size was to large --> 4 Pics in the Zip
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: High DPI Help
« Reply #1 on: August 18, 2021, 03:55:07 pm »
Lazarus v1.8+ has built-in High-DPI support. All you have to do is to check the "Use LCL scaling" box in the project options, and on Windows, select one of the "on" choices in the "DPI awareness" combobox. Do not use the scaling routines of the wiki article, read the English article (https://wiki.lazarus.freepascal.org/High_DPI#High_DPI_in_Lazarus_1.8_and_above), the German translation is outdated (a severe problem in the wiki infrastructure...).

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: High DPI Help
« Reply #2 on: August 18, 2021, 04:26:59 pm »
Thnak you very much wp :)

Does it rescale my Application if i change DPI at runtime ?

Edit: Tested it but did not work(Attached Picture of Settings).
Form is Scaled but i gueass by Windows because everything is blurry on 125% and 150% is just a mess. My Customers need both. Any idea what i could have done wrong ?

Does setting Font Size at DesignTime a Difference (its 0 so should i set it to 9) ?
« Last Edit: August 18, 2021, 04:46:45 pm by Weitentaaal »
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: High DPI Help
« Reply #3 on: August 18, 2021, 05:20:27 pm »
When fonts are blurred then Windows does not reckognize that the application is scaled and does the scaling itself. IIRC there is a Highi-DPI compatibility option in the properties of the application: right-click on the application in the explorer to open the Properties dialog of the app, select page "Compatibility". In Win10, there is a "Change High-DPI settings" button. In the next dialog nothing is checked on my system. There is also a link "Open extended scaling settings" into the system settings which contains a button "Windows can try to correct blurred app" which is checked on my system. I remember that the exact steps have changed during the evolution of Win10.

(Note that the Windows texts are translated to English and may be slightly different in reality).

In the attachment I show a screenshot of the MyDBFStudio application which was compiled at 96ppi; the screenshot was taken at 144ppi and is perfectly clear.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: High DPI Help
« Reply #4 on: August 18, 2021, 05:22:39 pm »
Love to See it .. thanks for your time :)

i will update this Post and tell if it worked :)
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: High DPI Help
« Reply #5 on: August 19, 2021, 07:33:45 am »
When fonts are blurred then Windows does not reckognize that the application is scaled and does the scaling itself. IIRC there is a Highi-DPI compatibility option in the properties of the application: right-click on the application in the explorer to open the Properties dialog of the app, select page "Compatibility". In Win10, there is a "Change High-DPI settings" button. In the next dialog nothing is checked on my system. There is also a link "Open extended scaling settings" into the system settings which contains a button "Windows can try to correct blurred app" which is checked on my system. I remember that the exact steps have changed during the evolution of Win10.

(Note that the Windows texts are translated to English and may be slightly different in reality).

In the attachment I show a screenshot of the MyDBFStudio application which was compiled at 96ppi; the screenshot was taken at 144ppi and is perfectly clear.

"In the next dialog nothing is checked on my system."
"There is also a link "Open extended scaling settings" into the system settings which contains a button "Windows can try to correct blurred app" which is checked on my system."

Same here

Only time it worked was when i used the old code from this :  https://wiki.lazarus.freepascal.org/High_DPI/de#SCHRITT_1_-_Deklarieren_Sie_High_DPI_Awareness

I did change Settings to let Lazarus handle High DPI
Porpertys  of exe are the same as u described yours

what did i forget ?
is there some danger in using the old Code ?
Mybe this CodeLine has an impact : "Application.Scaled:=True;"?

« Last Edit: August 19, 2021, 07:36:13 am by Weitentaaal »
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: High DPI Help
« Reply #6 on: August 19, 2021, 07:41:30 am »
Update : Got it Now

I just played around in the Settings but do not know exactly what was wrong.

Any Tips on how i should Handle the Sizes of the different Components.

I positioned them with Anchor Docking but the width i calculate on my own, without success. :-[
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

dseligo

  • Hero Member
  • *****
  • Posts: 1194
Re: High DPI Help
« Reply #7 on: August 19, 2021, 07:54:52 am »
Try to create new project and then set 'Use LCL scaling (Hi-DPI)' and 'DPI awareness'.
'Scaled' property of form must be true - it is default value.
Then change DPI of your system and see if your application is scaled.

I suggest to create new project because I had problems when I transferred one project from computer with different DPI.
There is property of form - 'DesignTimePPI', you can't see it in Object inspector, only in .lfm. It could be that your form's DPI is different from your system's DPI.
After I changed all forms' DPI to my current DPI it all worked.

dseligo

  • Hero Member
  • *****
  • Posts: 1194
Re: High DPI Help
« Reply #8 on: August 19, 2021, 07:56:18 am »
Any Tips on how i should Handle the Sizes of the different Components.

I positioned them with Anchor Docking but the width i calculate on my own, without success. :-[

From https://wiki.lazarus.freepascal.org/High_DPI#High_DPI_in_Lazarus_1.8_and_above:
Quote
If you create controls run-time, scale all coordinates, sizes etc that have to be DPI-aware with TControl.Scale96ToForm() or ScaleDesignToForm() (depending on your choice of default PPI) or prepare your container (e.g. panel with controls) as it was with 96 PPI and then call TControl.AutoAdjustLayout(lapAutoAdjustForDPI, 96, ParentFormOfTheContainer.PixelsPerInch, 0, 0);
« Last Edit: August 19, 2021, 07:57:49 am by dseligo »

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: High DPI Help
« Reply #9 on: August 19, 2021, 08:43:33 am »
Thanks @dseligo, already got it Working but thanks for your replys. I will do it and make Sure it works everywhere perfect. :)

EDIT: In Some Forms i do get Access Violation and it Tells me That Some Labels aren't floats ? Error only occurs when im on high DPI like 150%
« Last Edit: August 19, 2021, 08:52:58 am by Weitentaaal »
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

dseligo

  • Hero Member
  • *****
  • Posts: 1194
Re: High DPI Help
« Reply #10 on: August 19, 2021, 10:03:55 am »
EDIT: In Some Forms i do get Access Violation and it Tells me That Some Labels aren't floats ? Error only occurs when im on high DPI like 150%

Please post exact errors you are getting.
Do you also manipulate controls' sizes in your code?

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: High DPI Help
« Reply #11 on: August 19, 2021, 11:05:14 am »
No but i just tested the High DPI for my main Form i will just go from form to form and make everything again with anchor Sides, maybe it Fixes the problem because i just drag and dropped all other Forms  :-[ (First Lazarus Project Sorrry ).

But another Question: What could i do if some of my Controls are not Always Visible ? Bc then it wont work like it Should.

EDIT: I Did Some Screenshots of the Error.

EDIT2: "Est1" is a TLabel

EDIT3: Does the LCL Scaling check if Form is in Window Mode or in FullScreen Mode ? Looks like the Windows Taskbar is not considered.
« Last Edit: August 19, 2021, 11:22:25 am by Weitentaaal »
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: High DPI Help
« Reply #12 on: August 19, 2021, 01:18:56 pm »
AFAIK, LCL scaling only looks for changes in the DPI of the used monitor. When there are issues with Window or FullScreen mode, then these are issues of your layout.

As long as you use the same OS version there is no need to anchor the controls, because text and controls grow or shrink with the same factor. But when you move to a different OS or a different theme, the font may have a different size and could no longer fit to the size of the controls (this is a general issue, it happens also in non-high-dpi screens). Therefore, it is always a good idea to use the anchor editor to attach the controls to each other.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: High DPI Help
« Reply #13 on: August 19, 2021, 02:12:05 pm »
Thanks wp and dseligo ... very helpfull !!! :)

Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

 

TinyPortal © 2005-2018