getWidth() does not correspond to retina resolution?


#1

Hello,
I have Macbook Pro 13 with retina display. And according to documentation it has 2560 x 1600 pixels. But when I set my Component window to setSize(2560, 1600) my window appears much bigger than my screen.
So what exactly means one pixel in Juce? In other words:
1 pixel in Juce is equal to how many real retina pixels?

Great thanks for any help in advance.


#2

Desktop::getInstance().getDisplays().getMainDisplay().scale

https://docs.juce.com/master/structDesktop_1_1Displays_1_1Display.html


#3

OK, thanks but it doesn’t work for me.
When I use Desktop::Displays::Display::scale I get error: Invalid use of non-static data member ‘scale’

So I tried to inherit my AudioProcessorEditor by : public Desktop::Displays::Display

But then scale is equal to zero.


#4

You can read this value. It is not meant for you to change it, since if you move your window from one screen to another, this value might change, but you still want your component to appear at the same size. The docs _matkatmusic linked above state:

If you create a component with size 1x1, this scale factor indicates the actual size of the component in terms of physical pixels. For higher-resolution displays, it may be a value greater than 1.0

For example, if it says 2.0, your Component’s getWidth() would be just half of your number of screen pixels to fill the screen.


#5

OK, but as I told, it says zero. So does it means my Component’s getWidth() would be infinity?


#6

Because by trying to inherit, you hid the actual value. Remove that.


#7

But how to get that real value?
I tried also that:
Desktop::Displays::Display myDisplay;

And then DBG(myDisplay.scale); and it gives me zero - 0


#8

When I just use DBG(Desktop::Displays::Display::scale); I get error Invalid use of non-static data member ‘scale’


#9

find the display, where your Component shows. Note: to interact with the Display, use the singleton Desktop::getInstance()

auto display = Desktop::getInstance().getDisplays().findDisplayForRect (getScreenBounds());
DBG ("Scale is: " << display.scale);

But to be honest, you shouldn’t need to know about it, because the system is designed to avoid the need to deal with physical pixels, since they are different on each screen (even on the same machine). Just keep thinking in logical pixels and all is good.

Hope that helps


#10

Oh man it’s crazy :slight_smile: , how did you figure it out?
I don’t want to use scale in any way. I just make my small investigation about my display.


#11

I gave you the exact line of code required to get the current scale of your primary display… Why don’t you search the demo projects for that line to see how to use it?


#12

Matka, yes you are right :slight_smile: Sorry for that. I’d just seen the link and immediately jump there and did not notice your line of code.


#13

But there is still something wrong.
Desktop::getInstance().getDisplays().getMainDisplay().dpi;
It gives me 144. But according to documentation of Macbook Pro 13 late 2012 it is 227.
And that:
Desktop::getInstance().getDisplays().getMainDisplay().totalArea.getWidth()
Should give me 2560. But it displays the value which is here:

So how to get real physical number of pixels?


#14

And you have set your display to “scaled”, so it reduces the dpi for logical pixels from the max possible 227 to 144, so the content appears bigger.

Little maths:
2560 dots / 227 dots per inch = 11.27 inch (13" is diagonal)
1680 dots / 144 dots per inch = 11.67 inch
So probably there is a rounding in some of the values Apple specifies, but roughly the numbers add up.
Try your test again with “Resolution: default for display” selected.


#15

Maybe there isn’t a physical number.
Maybe the scale is a non-integer value
Maybe your window is rotated at 20 degrees so that the physical pixels don’t even line up with the virtual ones.
Maybe the resolution is so high that a human can’t even see the pixels.
Maybe the display gets scaled in hardware so that the physical pixels it reports don’t actually correspond to the ones on the screen (this is common in phones)

I get so tired of these “physical pixel” questions - they always turn out to be someone trying to make some graphics fit the pixels on the display they’re currently staring at, without considering where else it might be used.

Physical pixels mattered in the 1990s when VGA was still a thing, but people have all kinds of displays now, you need to think about your graphics in a more abstract way.