setTransform question


I’m facing a problem with a scaling AffineTransform for my Android app, when the ration is < 1. The graphics are properly reduced, but the component itself is truncated.

This is for my Android app. I have a DocumentWindow, with a “skinned” (background image) component (with setContentOwned()). Images are all tailored for a default 320x480 pixels, but I use a transform to resize it for different screens. This works perfectly when the screen is larger, but on a 240x320 screen, only 3/4 of the image appear.

It looks like the clipping area or size of the component is transformed twice, because the actual part of the screen displayed is proportional to the transformation ratio (at 0.5, I only see a quarter of it, half height, half width).

I’m using the transform as follows:

Rectangle<int> monitorArea(0, 0, 240, 320); // for testing on desktop
//Rectangle<int> monitorArea = Desktop::getInstance().getMainMonitorArea(false);

float defaultWidth = 320;
float widthFactor = (float)monitorArea.getWidth() / defaultWidth;
AffineTransform trf = AffineTransform::scale(widthFactor, widthFactor);
contentComp->setSize(monitorArea.getWidth(), monitorArea.getHeight());
setSize(monitorArea.getWidth(), monitorArea.getHeight());

Am I applying this in a wrong way? Thanks for your help.


Oh, don’t try to set a transform on your content component! The DocumentWindow expects that component to just behave normally, so that it can just call setBounds on it to keep it in the correct size and position. (Actually, I should probably add an assertion to warn about this…)

If you’re going to transform a component, just put it inside your content component and it’ll all be fine.

Brilliant! Thanks for your support.

Now it works perfectly.