How to use CachedComponentImage for retina

Ok, enabling the Juce feature Component::setBufferedToImage(true); works very well most of the time to accelerate the performance of otherwise slow to paint components.

However, due to the bogusness of iOS retina x2 UI scaling, enabling this feature makes it all “big and chunky”.

Unfortunately, i don’t see how Juce can magically fix this. So here’s some hacks that get around this by building a special CachedComponentImage called, `ScalingCachedComponentImage’.

Here’s what i do,

The ScalingCachedComponentImage, is a copy of the Juce version except it multiples the `bounds’ its using by the UI scale factor (normally 1).

Then it does the same as before, except it finally renders using:

int w = image.getWidth(); int h = image.getHeight(); g.drawImage(image, 0, 0, w/_scale, h/_scale, 0, 0, w, h, false);

normally, no scale will apply. but for retina, it will describe a halving transform, which is then conveniently ignored.

ok, if this is all that’s needed then Juce could do it. but there’s more. my component that uses this must lie to itself about its bounds.

first it must assign the CachedComponentImage,

setCachedComponentImage(new ScalingCachedComponentImage(*this, scale));
Then it must lie about its dimensions. i achieve this by consistently, throughout all methods, using a private version of `getLocalBounds’ that scales the bounding rectangle by the UI scale factor.

As a result of these nasties, everything works. and there’s no penalty for x1 scale.

i’m wondering if anyone else has any better ideas. retina x2 scaling really sucks :frowning:

– hugh.


I’ve not investigated it yet, but isn’t there a way to tell the OS that your app is “retina-aware”, and just handle the 2x scaling manually?

Yes, im really hoping to discover some property i can add to the project/plist (whatever), that has the effect of; work in native pixel resolution on all devices.

This is how i’d much prefer it always. that way i can make all layout decisions programmatically.

Unfortunately, i’ve yet to discover a way (anyone?). Sadly, i think there might not be one, otherwise existing iOS versions would already have to support it for it to work on platforms already in the field.


– hugh.

Perhaps there’s a setting in the plist?