It’s called Dpi,
You will usually access the 2nd one, as
Container property is both in
TCastleWindowBase and in
TCastleControlBase, in the first case it uses CGE
CastleWindow code, in the 2nd case it uses LCL PixelsPerInch).
It works on all desktops and mobile. On desktops, the implementation was actually done looking at what LCL does. It is correct – at least as much as underlying platform APIs are correct. So when it’s not precise, you can at least rest assured that all the other applications see the same value.
- E.g. as far as I recall, it is not precise on some Android models.
- E.g. on desktops, DPI is adjustable by user (both Linux and Windows allow to change what application sees), and whether it makes any sense (whether it corresponds to real physical size) is up to user. It’s the same with LCL
Note 1: The question is not really related to CGE
RenderRect is a property available at each TCastleUserInterface, and it specifies the control size in pixels. (real final pixels, not scaled.)
Note 2: Using UI scaling is very much advised to have a good starting point for a cross-platform UI, that scales and adjusts to various window sizes and aspects. Our templates, examples all use it. https://castle-engine.io/manual_2d_user_interface.php , https://castle-engine.io/manual_castle_settings.php all use it. It’s not based on physical size, instead it adjusts itself to window sizes, scales things without distorting proportions, and relies on proper anchors to keep the correct layout. I very much advise to use it, and it was enough in all our Cat-astrophe Games games (on production, on various platforms ). This is also similar to what Unity offers.
Of course it will not address the fact that various physical screen sizes will result in various physical text sizes. If you design a text that has height 1/4 screen, it will be 1/4 height on phone, and 1/4 height in tablet, so will be physically much larger on tablet. You can indeed try to fight with this using
Dpi and adjusting sizes at runtime.
But warning: counteracting this, using
Dpi, is usually low-priority IMHO. It’s better to design UI that just makes sense on all platforms, using our existing scalable UI. Most games that I know of also don’t try to adjust to physical size.