Resolution independence

LiveCode 6.5, and beyond…

One of the features listed in Chapter 1, LiveCode Fundamentals, has already been developed and is present in LiveCode 6.5. The new feature is Resolution Independence.

Now, after seeing the two complex ways of adjusting the screen size, you may be able to forget all of it. In LiveCode 6.5, a new feature called Resolution Independence was introduced, and the correct use of this feature will make many of the layout difficulties go away.

There are two approaches in place to help you deal with different device sizes and aspect ratios: the Multiple Density Support and the Full Screen Scaling Mode. Some of the concepts are a little tricky, but a few screenshots will hopefully make them clear!

Multiple density support

So far in this chapter, we overlooked the issue of the DPI (dots per inch) of devices. For Android devices, there are hundreds of different resolutions and DPI values. With iOS, there are only a few variations of DPI and resolution. The simplest these problem cases to examine, is where you want the same app to look like and work in the same manner as iPhone 3GS and iPhone 4 Retina or later versions of iPhones. Both have the same size screen, but iPhone 4's retina display has twice the DPI. This URL shows you the difference between all the current iPhones: http://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions.

With the MobGUI and Geometry Manager solution, you are effectively storing layout values or instructions behind the scenes that are ready to adapt to the user's device screen size. The Multiple Density Support in LiveCode 6.5 is an easier way to solve this issue.

Pixels and points

A pixel is an illuminated dot in an image or of a screen, whereas a point is a unit of measurement in print, generally, 1/72nd of an inch. If a screen has exactly 72 DPI, the two would be the same, and in the earlier days of Macintosh computers, this was pretty much the case. More modern Macs and PCs and most mobile devices are a lot more detailed than 72 DPI. With LiveCode 6.5, and its later versions, you can now make a stack that works in points, that will then fill the device screen by taking the image of each card and by applying a scaling factor to it.

While doing such scaling, something must be assumed to be of natural size. For iOS, LiveCode uses non-Retina screens as a scale factor of 1X and Retina screens are a scale factor of 2X. iPhone 5 and 6 introduced more sizes. A scale factor of 3X is required for iPhone 6 Plus. With Android, things are more complicated as it has at least seven levels of scaling factor.

In fact, really, there are an infinite number of scaling factors going on behind the scenes. However, you generally don't have to worry about them because LiveCode automatically gives you the ability to show different versions of an image depending on the DPI of the device in question.

Image naming convention

LiveCode will look at the file names of the included images (that have been added in the Copy Files part of the Standalone Application Settings dialog) and will load in the appropriately named version of the image. In the example shown here, two images have been added, icon.png and [email protected]. To make it easier to spot which one you are seeing, 512 and 1024 have been added to what would otherwise be two resolutions of the same icon:

Image naming convention

This image is slightly magnified here to help you see that the 512 version of the image is lower resolution than the 1024 version.

The names used for iOS are:

The first one is considered as the 1X scaled version and the @2x name is considered as the 2X scaled version and the same goes for the @3x version.

Note

Note that you also need to specify the appropriate Splash Screen files in the LiveCode Standalone Application Settings. Otherwise, the iPhone will use lower resolution images. This can be verified by examining the screenRect of the device. Even though iPhone 6 Plus has a physical resolution of 1080 x 1920, use the 3x image sizes of 1242 x 2208. The phone automatically downsizes the image. 2x images will be displayed fine on iPhone 6.

The names and scaling factors used for Android are more varied:

In actual practice, you may find that you only need two or three versions of an image to make an image look good enough on a wide range of DPI devices.

The full-screen scaling mode

Prior to LiveCode 6.5 and its multiple density support, you had to do all the hard work by yourself! At least now you can design for just iPhone or iPad and have Retina versions of these devices looked after by LiveCode. With Android though, you still need to have a variety of layouts or alternately, have code that would position the interface elements based on the aspect ratio and pixel dimensions of the device.

With the density support, you only have to take care of the aspect ratio, but there are still a lot of these to be taken care of. For utility-like applications, you will most likely have to go to this trouble, so that users get the expected experience. However, there are many types of applications that are more graphical and that can take advantage of the full screen scaling modes: empty, exactFit, showAll, noBorder, and noScale. Let's take a look at what these are…

Syntax

The general syntax, by the way, is to type this in your stack script:

on preopenstack
  set the fullscreenmode of the current stack to "showAll"
end preopenstack

The quotes are required for the four active modes. The empty mode does not need quotes.

The empty mode

If fullscreenmode is empty, the card area is changed to match the device screen. That is, the top left card is in the top-left corner of the device screen and the card width and height match the actual pixel width and height of the device. Well, except if you have taken advantage of the multiple density support discussed earlier! Essentially, empty is the existing behavior in the earlier versions of LiveCode.

The showAll mode

This mode arrived slightly later than the other modes and is present in LiveCode 6.6 and its later versions. With showAll, as the fullscreenmode, the card's contents will be scaled, so that all of it is within the device's screen. For devices that have a different aspect ratio than your card, elements that were outside of the card area are revealed. Suppose you create a graphical book app where you want the full height of the card to exactly fill the height of the device screen, but you don't want black bars down the sides on a wider device, then you could extend the background pattern beyond the left- and right-hand side of the card area. On a narrower device, such as iPad, you would see the 4:3 area of the card. On a wider device, say iPhone 5, the extra background would be revealed. The following illustration shows which area of the background image will be seen on different devices:

The showAll mode

The letterbox mode

The letterbox mode is identical to showAll except that the areas beyond the card area are hidden and leave you with the typical movie letterbox effect, hence the name!

The noBorder mode

The noBorder mode is very useful, but takes some time to get used to. Let's say you are making a graphical adventure game, along the lines of Myst, and you want to use the same graphics for all devices. You could create a scene that has an aspect ratio of 14:9 and make sure that the important content is not too close to the edges. When the scene is viewed in the noBorder mode on an iPad, you would see the full height of the scene and most of the width. When viewed on iPhone 5, you would see the full width of the scene and most of the height. As the name suggests, the card area would be scaled, so that there are no borders, as there would be in the letterbox mode. The following illustration shows which areas of an original 14:9 photograph would be visible for a 4:3 iPad and a 16:9 iPhone:

The noBorder mode

The exactFit mode

As the name implies, exactFit would take the card's content and squish it to fill the device's screen. It's hard to think of a use case for this mode, but perhaps, if you perform some sort of artistic visualizer, the squishing wouldn't matter much!

Note

As mentioned previously, the Geometry Manager has a lot of powerful features. If your interest is also in desktop applications, take a look at the lesson at:

http://lessons.runrev.com/s/lessons/m/4067/l/19026-Geometry-Manager

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.51.117