Warning:
This tutorial covers only Mobile Widgets versions.
For a Tiny Mobile Widgets, use scalability guidelines for Tiny Mobile Widgets.
Working on mobile phones leads to work on different screen sizes. It would be heavy and restrictive to develop one application per screen resolution. So we have introduced the scalability feature. Developers write the application code once and for all. Helped by using a Message node all VRML scenes can be aware of the size of the screen and calculate size and positions of graphical elements. And even better: it is a "screen size changed" Message. So that VRML scenes are aware of the screen size and also WHEN screen size changed (dynamic). This last ability is useful on mobile phones that can switch from portrait to landscape mode.
Keep in mind this project targets low-end devices. Please limit size and position calculations to the bare essentials. You can add filter TRUE to each ImageTexture node which is bad rendered. But use it sparingly because it generates a lots of calculations in memory.
Our reference size is 240*320 (in pixels). it is important to avoid useless calculations on most of devices, that's why default sizes and translations are set for the 240*320 size. Calculations should be done only to manage other screen size.
The screen size can be accessed by the Browser JavaScript API, method Browser.getWidth() and Browser.getHeight().
The system can notify each VRML scene that the size changed (switch from portrait to landscape mode for example). Therefore, the VRML scene has to contain the following Message Node:
This node listen to the "MEMOPLAYER" channel. You have to add a link message reception to a script function that does calculations. This link is done by the following ROUTE: (by convention, ROUTE are put at the end of the VRML scene)
Now, just add a new entry to the script in your VRML scene:
To avoid ugly stretches on images, don't forget to respect their aspect ratio. The image ratio is: imageWidth / imageHeight and vice versa. When you do scalability, you should calculate imageWidth or imageHeight and found the other helped by the ratio. It will keep the real aspect of the image. If it is bad rendered, you can use attribute filter TRUE inside the ImageTexture node. But filter uses a lot of CPU.
To support landscape and portrait mode, sometimes you will have to use the minimum between screen width and height to be sure that the scalable area fit with the real screen size.
The SizeNotifier prototype manages the screen size events. It uses the sizeHandler mechanism describes upper to get screen size value. The SizeNotifier prototype is used in many SDK prototypes. This is the SizeNotifier prototype interface:
screenSize and textScale events (eventOut) propagate the values. In many cases,
screenSize value is used in the script to compute sizes and positions of scene
items. Style is also useful to defines
values and ratios.
A good way to propagate the screen size is to defines each scene of a widget as
a prototype. This tip eases the screenSize and the textScale use: it could be
propagated with "IS" for script and for other protos.
See SizeNotifier prototype documentation for more informations about this prototype.
The MyScene file could be loaded like this, from the main.wrl for example: