Supporting HiDPI programmatically (no UIDescription)

A user interface toolkit mainly for audio plug-ins (VST, AudioUnit, etc).
f.berti
Posts: 18
Joined: Thu Nov 02, 2017 5:50 pm

Supporting HiDPI programmatically (no UIDescription)

Postby f.berti » Wed Sep 05, 2018 8:58 am

Hello,

I'm looking for some guidance in order to start supporting hidpi displays like Retina in my VSTGUI based plug-ins.
I'm not using the xml descriptor, so I need to figure out how to support this programmatically.

AFAIK the standard approach is to use 2 (or more) versions of the same image with different resolutions and then somewhat decide what version to render according to the screen dpi at runtime.
Is there any example available? I couldn't find much info in this forum nor in the VSTGUI tutorials.

How can I check if I'm on a hidpi screen or not? What call should I perform?

Any help would be gratly appreciated.

Regards,
Federico

Arne Scheffler
Posts: 205
Joined: Mon Jun 20, 2016 7:53 am

Re: Supporting HiDPI programmatically (no UIDescription)

Postby Arne Scheffler » Thu Sep 06, 2018 10:37 am

Hi Federico,
CBitmap already supports HiDPI rendering. You only have to set it up to know about the bitmaps for the different scale factors. To do so, you have to create IPlatformBitmaps yourself set the scale factor accordingly and add it to the CBitmap instance.
For example, you have 2 bitmaps:
    - b1.png (for scale factor 1)
    - b2.png (for scale factor 2)
Then you can do:

Code: Select all

auto bitmap = makeOwned<CBitmap> (CResourceDescription ("b1.png"));
auto tmp = makeOwned<CBitmap> (CResourceDescription ("b2.png"));
if (auto platformBitmap = tmp->getPlatformBitmap ())
{
  platformBitmap->setScaleFactor (2.);
  bitmap->addBitmap (platformBitmap);
}

now the bitmap variable has 2 images set and will use b2.png when rendering on a screen with a scale factor of 2.

You can also register for scale factor changes via the IScaleFactorChangedListener interface on the CFrame instance and you can also ask the CFrame instance of the current scale factor with CFrame::getScaleFactor().

I hope this helps.

Cheers,
Arne


Return to “VSTGUI”

Who is online

Users browsing this forum: No registered users and 1 guest