0

I have an Firemonkey HD application and deploy it on iPad 2. Works fine.

When I deploy the same app on iPad 4 with Retina display I get problems.

The point is I have some drawing operations on a form and need exact form width and height.

ShowMessage('form wh = ' + FloatToStr(TForm(FImage.Parent.Parent). Width) + ':' + FloatToStr(TForm(FImage.Parent.Parent).Height));

on both devices I get a message:

form wh = 1024:748

What I need is automatic form size change.

What should I do to get it?

UPDATE: I try to use Screen.Size.Width but have Screen.Size.Width=1024 on Retina display. What do I do wrong?

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
mad
  • 1,029
  • 3
  • 17
  • 38
  • The form should be full screen (auto-sizes to match screen). Between retina and non-retina screen, the size will be the same, it's the scale that changes. Can you describe the issue in more detail or include an image of the issue? – Marcus Adams Dec 20 '13 at 19:27
  • Yes, sure. The form is full screen. The strange point for me is I have Screen.Size.Width=1024 and Screen.Size.Height=768. What details do you want to get. I will provide them with pleasure. – mad Dec 20 '13 at 19:44
  • Since the form is full screen, it's obviously auto-sizing. What's the actual issue? This? http://docwiki.embarcadero.com/RADStudio/XE5/en/Mobile_Tutorial:_Using_Layout_to_Adjust_Different_Form_Sizes_or_Orientations_%28iOS_and_Android%29 – Marcus Adams Dec 20 '13 at 20:05
  • Closest solution is here http://stackoverflow.com/questions/20124191/how-to-find-resolution-under-delphi-xe5. But when I try to get screen structure I get an access violation (0x000000) exception... – mad Dec 20 '13 at 21:21
  • 1
    Wait, you mean that `SupportsPlatformService` call returned you True in that code and if you then tried to access `ScreenSvc` interface, it failed with an access violation ? That would be a critical bug, since the way provided in that code is a proper way... – TLama Dec 21 '13 at 01:29
  • See [Using Multi-resolution bitmaps](http://docwiki.embarcadero.com/RADStudio/XE5/en/Using_Multi-Resolution_Bitmaps) for a discussion of screen resolution (size, as in width and height), screen density (pixels per inch), and screen scale (logical vs physical coordinates and sizes). – Ken White Dec 21 '13 at 03:24
  • Also see [Working with Native and Custom FireMonkey Styles](http://docwiki.embarcadero.com/RADStudio/XE5/en/Working_with_Native_and_Custom_FireMonkey_Styles), which discusses Retina displays and resolution (1x vs 2x). – Ken White Dec 21 '13 at 03:32

1 Answers1

5

With respect to your 'update', you need to consider the difference between the number of 'device' pixels vs. the number of 'logical' pixels. Typically, a 'retina' display isn't physically larger than a non-'retina' one (or if it is, that's nothing to do with being 'retina' as such) - instead, it has a much higher resolution. Further, the point of this higher resolution isn't to cram more controls (views) into the same physical screen size - it's to make the display clearer, less 'blocky' up close.

As such, the number of logical pixels - the units used to size controls - does not go up just because of a 'retina' display. This is why IFMXScreenService.GetScreenSize is returning the same result with 'retina' and non-'retina' displays. However, IFMXScreenService has another method, GetScreenScale, that you can use to derive the screen size in 'device' pixels:

uses FMX.Platform;

function GetScreenSizeInDevicePixels: TPointF;
var
  Service: IFMXScreenService;
begin
  Service := IFMXScreenService(
    TPlatformServices.Current.GetPlatformService(IFMXScreenService));
  Result := Service.GetScreenSize * Service.GetScreenScale;
end;
Chris Rolliston
  • 4,788
  • 1
  • 16
  • 20