How to write High-DPI aware plugins

Post your questions and problem reports here

Moderator: kfury77

Forum rules
Please try to follow these guidelines. This will help to receive faster and more accurate response.

  • Check the Support section of the corresponding product first. Chances are you will find your answer there;
  • Do not create new topics for already reported problems. Add your comments to the existing topics instead;
  • Create separate topic for each problem request. Do NOT post a number of non-related problem reports in a single topic;
  • Give your topic a meaningful title. Titles such as "A question," "Bug report" and "Help!" provide others no clue what your message is about;
  • Include the version number of the software you are using;
  • This is not an official customer support helpdesk. If you need a prompt and official response, please contact our support team directly instead. It may take a while until you receive a reply in the forum;

How to write High-DPI aware plugins

Postby Aivars » Mon Nov 14, 2016 7:42 pm

If you're writing plugins and you've seen an issue like this:
Image

this happens because user has enabled Text Zoom in Windows settings. The problem arises from the fact that Windows automatically scales text according to user settings, but not forms and control placement (which you specify in pixels in plugins).

Take a look at this regular plugin code dealing with GUI:

Code: Select all
    f = new TForm(WeBuilder);
    f.Width = 600;
    f.Height = 670;

    var pnlCurrentWBProject = new TPanel(f);
    pnlCurrentWBProject.Parent = f;
    pnlCurrentWBProject.SetBounds(14, 10, 568, 80);


Everything is fine on normal screens, but if someone (like me) would execute this code on Surface Pro, every normal pixel is twice as small on this screen so the text zoom is set to 200%, which means that for this form I will see a tiny form with tiny controls (two times smaller in width and height than on a regular screen) due to my DPI.

Here's how to fix it and make it DPI-aware:

Code: Select all
    f = new TForm(WeBuilder);
    var mul = Round(f.PixelsPerInch / 96);
    f.Width = 600 * mul;
    f.Height = 670 * mul;

    var pnlCurrentWBProject = new TPanel(f);
    pnlCurrentWBProject.Parent = f;
    pnlCurrentWBProject.SetBounds(14 * mul, 10 * mul, 568 * mul, 80 * mul);


The main thing to pay attention to is TForm.PixelsPerInch property. It is 96 on regular screens but bigger (according to Text Zoom setting) on High-DPI screens.

I hope that helps!
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
 
Posts: 2452
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: How to write High-DPI aware plugins

Postby pmk65 » Tue Nov 15, 2016 5:50 pm

Great. But shouldn't the "96" you divide with, match the "PixelsPerInch" of the system the plugin is created on?

If I do:
Code: Select all
f = new TForm(WeBuilder);
Script.Message(_t(f.PixelsPerInch));


I get the value "120". So I would assume that's the value I have to use in my plugins?
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
pmk65
 
Posts: 678
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: How to write High-DPI aware plugins

Postby Aivars » Tue Nov 15, 2016 8:29 pm

It means that you have set Windows Text Zoom to 125%. I don't think it matters much if you use 120 or 96 as baseline, you just get a different multiplier and you accordingly would use different dimensions and coordinates. To convert existing scripts, in your case it might be easier to use 120, but if you're writing a new script, I would recommend using 96 because that's 100% (no zoom).
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
 
Posts: 2452
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia


Return to HTMLPad / Rapid CSS / Rapid PHP / WeBuilder Support

Who is online

Users browsing this forum: No registered users and 4 guests