Recent

Author Topic: High DPI problems  (Read 9347 times)

JD

  • Hero Member
  • *****
  • Posts: 1848
High DPI problems
« on: March 07, 2017, 06:06:58 pm »
Hi there everyone,

I have an application that was designed in 96 DPI i.e 100%. Everything has been going fine until one of the users bought a new Windows 10 computer and set the display to 150% (144 DPI). Now my application looks mangled.

Can anyone tell me how I can make my application High DPI aware. I've read http://wiki.lazarus.freepascal.org/High_DPI but I'm yet to see any code that can help me.

Thanks,

JD
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: High DPI problems
« Reply #1 on: March 07, 2017, 06:13:33 pm »
Enable HiDPI in settings ( or manually in your .lpr file Application.Scaled := True)

balazsszekely

  • Guest
Re: High DPI problems
« Reply #2 on: March 07, 2017, 06:17:14 pm »
You need Lazarus trunk for that. To test the High DPI feature create a secondary install with FPCDeluxe, it won't interfere with your primary install.

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: High DPI problems
« Reply #3 on: March 07, 2017, 06:24:15 pm »
Enable HiDPI in settings ( or manually in your .lpr file Application.Scaled := True)

I had already set some DPI setting in Project -> Project Options -> Application (see screenshot). The project's LPR file is as shown below:

Code: Pascal  [Select][+][-]
  1. begin
  2.   // Set French as the default language
  3.   TranslateLCL;
  4.   HighDPI(96);      // High DPI for all forms at once
  5.   RequireDerivedFormResource := True;
  6.   Application.Initialize;
  7.   Application.CreateForm(TfrmMain, frmMain);
  8.   Application.Run;
  9. end;
  10.  

I added Application.Scaled to it and the debugger says Error: identifier idents no member "Scaled".

P.S. I got the HighDPI some years ago and 96 was the default setting and I just kept it because it seemed to work until now.

JD

Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: High DPI problems
« Reply #4 on: March 07, 2017, 06:25:24 pm »
Can anyone tell me how I can make my application High DPI aware. I've read http://wiki.lazarus.freepascal.org/High_DPI but I'm yet to see any code that can help me.

The mantainer of the High DPI features removed all the code from the Wiki.

If you're in 1.6.4 do this OnCreate event:

Code: Pascal  [Select][+][-]
  1. Self.AutoAdjustLayout(lapAutoAdjustForDPI, Self.DesignTimeDPI, Screen.PixelsPerInch, Self.Width, ScaleX(Self.Width, Self.DesignTimeDPI));

In 1.7:

Code: Pascal  [Select][+][-]
  1. Self.AutoAdjustLayout(lapAutoAdjustForDPI, 96, Screen.PixelsPerInch, Self.Width, ScaleX(Self.Width, 96), False);
  2.  

In Project Options enable DPI awareness options.

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: High DPI problems
« Reply #5 on: March 07, 2017, 06:27:11 pm »
You need Lazarus trunk for that. To test the High DPI feature create a secondary install with FPCDeluxe, it won't interfere with your primary install.

I was hoping to avoid that because of portabilty of some components I've used for the project. I mostly use fpcupdeluxe as a Sandbox for testing mORMot. I guess I'll have to give it a shot on production code.  :(
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: High DPI problems
« Reply #6 on: March 07, 2017, 06:33:15 pm »
@lainz

I can do that too in Lazarus 1.6.2

I'll put that in the code and test on a high DPI screen tomorrow.

Thanks,

JD
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: High DPI problems
« Reply #7 on: March 13, 2017, 10:12:30 am »
Looks like I spoke too soon. It is not available in Lazarus 1.6.2/FPC 3.0

I cannot move the project completely to Lazarus Lazarus 1.6.4/FPC 3.0.2 yet because I'm still trying to resolve the {$codepage UTF8} issues.

Is there any other way I can incorporate high DPI into Lazarus 1.6.2/FPC 3.0?

Thanks,

JD
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: High DPI problems
« Reply #8 on: March 13, 2017, 02:45:55 pm »
Looks like I spoke too soon. It is not available in Lazarus 1.6.2/FPC 3.0

I cannot move the project completely to Lazarus Lazarus 1.6.4/FPC 3.0.2 yet because I'm still trying to resolve the {$codepage UTF8} issues.

Is there any other way I can incorporate high DPI into Lazarus 1.6.2/FPC 3.0?

Thanks,

JD

What exactly is not available?

AutoAdjustLayout was implemented a lot of time ago, even before 1.6.

You're still designing the form at 96 dpi?

And here is another code for HighDPI:
https://github.com/bgrabitmap/lazpaint/blob/master/lazpaint/uscaledpi.pas
« Last Edit: March 13, 2017, 02:58:55 pm by lainz »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4468
  • I like bugs.
Re: High DPI problems
« Reply #9 on: March 13, 2017, 03:04:45 pm »
Looks like I spoke too soon. It is not available in Lazarus 1.6.2/FPC 3.0
I cannot move the project completely to Lazarus Lazarus 1.6.4/FPC 3.0.2 yet because I'm still trying to resolve the {$codepage UTF8} issues.
Nonsense! I have explained to you in another thread that the improved unicode support happened already in Lazarus 1.6.0.
Lazarus 1.6.4 is perfectly compatible with Lazarus 1.6.2 unicode-wise.
Did you even read my post in the other thread?

Quote
Is there any other way I can incorporate high DPI into Lazarus 1.6.2/FPC 3.0?
No. Use trunk for improved DPI.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: High DPI problems
« Reply #10 on: March 13, 2017, 03:09:05 pm »
Quote
Is there any other way I can incorporate high DPI into Lazarus 1.6.2/FPC 3.0?
No. Use trunk for improved DPI.

HighDPI was working for all of us in 1.6 with user submitted code to the wiki, and is still working. But ondrej deleted all these codes from the wiki.

Of course in trunk works better, but that doesn't means that's unusable on 1.6

His problem is not clear, he seems to don't understand how to debug an high dpi application.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4468
  • I like bugs.
Re: High DPI problems
« Reply #11 on: March 13, 2017, 04:06:08 pm »
HighDPI was working for all of us in 1.6 with user submitted code to the wiki, and is still working. But ondrej deleted all these codes from the wiki.
The HighDPI support is revamped and improved substantially. Anybody who has problems with HighDPI should use trunk.
It makes no sense to add new code with the old workarounds any more.
This fact should be emphasized for JD as well.

Lazarus 1.8 may be forked already next month (April). After that the fixes_1_8 branch can be used instead of trunk.

JD keeps telling that Lazarus 1.6.4 broke the unicode support. I don't think so. There is something funny going on in his code.
« Last Edit: March 13, 2017, 05:51:55 pm by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: High DPI problems
« Reply #12 on: March 19, 2017, 07:44:09 pm »
JD keeps telling that Lazarus 1.6.4 broke the unicode support. I don't think so. There is something funny going on in his code.

I never said that. Besides in that thread I remember saying that I'll keep both 1.6.2 and 1.6.4 until I can find out why the UTF 8 string was not being properly displayed. Meaning I take the responsibility for correcting whatever I did wrong. I never said the problem was with Lazarus 1.6.4.

Finally, I asked 2 different questions relating to 2 different projects so please don't mix things.
« Last Edit: March 19, 2017, 07:50:52 pm by JD »
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

JD

  • Hero Member
  • *****
  • Posts: 1848
Re: High DPI problems
« Reply #13 on: March 19, 2017, 07:49:04 pm »
His problem is not clear, he seems to don't understand how to debug an high dpi application.

Let me reiterate. An application developed in 96 DPI i.e 100% does not look good in 150% (144 DPI) even though HighDPI is in the main application file as shown below

Code: Pascal  [Select][+][-]
  1.     begin
  2.       // Set French as the default language
  3.       TranslateLCL;
  4.       HighDPI(96);      // High DPI for all forms at once
  5.       RequireDerivedFormResource := True;
  6.       Application.Initialize;
  7.       Application.CreateForm(TfrmMain, frmMain);
  8.       Application.Run;
  9.     end;
  10.  

I've already started to migrate this particular project to 1.6.4 so that I can use the new feature described earlier.
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: High DPI problems
« Reply #14 on: March 19, 2017, 11:44:26 pm »
As I understood the HighDPI-procedure it steps trough all already created Forms,
So you need to call it AFTER the forms are created:
Code: Pascal  [Select][+][-]
  1. begin
  2.   // Set French as the default language
  3.       TranslateLCL;
  4.       RequireDerivedFormResource := True;
  5.       Application.Initialize;
  6.       Application.CreateForm(TfrmMain, frmMain);
  7.       HighDPI(96);      // High DPI for all forms at once <---- New place
  8.       Application.Run;
  9. end.
  10.  
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

 

TinyPortal © 2005-2018