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?
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.
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.
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?
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:
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.
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.