Recent

Author Topic: DPI/PPI on Windows  (Read 409 times)

Alienizering

  • New member
  • *
  • Posts: 8
DPI/PPI on Windows
« on: May 17, 2022, 06:33:32 pm »
Using the latest Lazarus on Windows, for Windows, is it safe to create an app on any DPI and it will be scaled properly on other DPI or do I still need to create my apps at 96ppi?

I use a 4K TV with Windows fonts at 200%, which is 192ppi and it seems to look ok when I set the font to 100%

Basically, what are the multi-dpi development rules now for the latest Lazarus?

Thanks.

wp

  • Hero Member
  • *****
  • Posts: 9734
Re: DPI/PPI on Windows
« Reply #1 on: May 17, 2022, 07:22:52 pm »
Read this: https://wiki.lazarus.freepascal.org/High_DPI#High_DPI_in_Lazarus_1.8_and_above

I am not sure whether the last sentence "Do not develop under HighDPI Mode, always develop under normal mode and only test under HighDPI" is correct. For a test I had written a simple application at 150% (144ppi), and switched to 100% (96ppi), and did not see issues. It has been reported in the forum sometimes that a team with computers at various ppi could be a problem. But I don't have much experience in that myself since I normally work at 96ppi.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Alienizering

  • New member
  • *
  • Posts: 8
Re: DPI/PPI on Windows
« Reply #2 on: May 17, 2022, 07:52:28 pm »
Thank you so much, I appreciate you taking the time to help.

I have another question. When saving forms and controls size and position, say, to the registry, to we write as-is or converted like, with designto96 or anything? What about when reading back these values from the registry?

[Edited to add the "another question" post which the OP deleted after WP answered below.]
« Last Edit: May 18, 2022, 12:47:04 am by trev »

wp

  • Hero Member
  • *****
  • Posts: 9734
Re: DPI/PPI on Windows
« Reply #3 on: May 17, 2022, 09:53:53 pm »
Good question!

When you save form geometry to a cfg file or registry the values are written in units of the current ppi of that particular system. When you later run the project again on the same machine with the same ppi the form will have exactly this size.

Somebody else on a machine with different ppi stores the geometry in his written in his ppi. He will write different numbers than you, but due to his different ppi he sees the form at the size stored upon reload.

So, when both config files are distinct, everything is fine. And this is the normal case: every user writes his own cfg to his own machine.

But when both users share the same cfg file, for example, because the cfg is stored on a network drive, you must be careful because every user interprets the stored numbers in his own ppi units. Even if nobody changed the form size one of them will be surprised because the form when reloaded will have a different size than when the application was closed.

So either don't share cfg files, or write the current ppi to the cfg along with the dimensions, or rescale the dimensions to standard ppi, say 96 ppi (using the Scale96To***/Scale***To96 functions).
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Alienizering

  • New member
  • *
  • Posts: 8
Re: DPI/PPI on Windows
« Reply #4 on: May 18, 2022, 12:59:34 am »
I see what you mean. What about converting the values to 96ppi using ScaleFormTo96 before saving and then when loading these values, apply the reverse, Scale96ToForm? would that work even if the app was developed on a different PPI?

Like I'm on 192ppi because I run Windows at 200% fonts on my 4k TV. When I modify my forms, I have to set Windows font to 100% and save the form. Then I can go back to 200% and compile, it all looks fine. But if I modify my form at 200% it changes the ppi from 96 to 192 and it's huge at 100%

 

TinyPortal © 2005-2018