Supporting HiDPI programmatically (no UIDescription)

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

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:

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