Warning:
This tutorial covers only Tiny Mobile Widgets versions.
On Mobile Widgets, use scalability guidelines for 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 into Tiny Mobile Widgets.
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 128*128 or 128*176 (in pixels). It is called
"the 128-mode" afterwards.
128 mode devices are often those whith the worse CPU. So it is important to
avoid useless calculations, that's why default sizes and translations are set
for 128 mode. Calculations should be done only to manage other screen size.
How does widget know the screen size? the size of the area where they can
display ? The screen size can be accessed by the
Browser javascript
API, method Browser.getWidth() and Browser.getHeight().
The widget size is stored into cookies: Browser.getIntCooky('widgetWidth')
and Browser.getIntCooky('widgetHeight').
The following cooky can also be useful to position the widget icon into the
title bar: Browser.getIntCooky('iconSize').
Each widget has to position its icon, the system doesn't do that.
All these informations are automatically set by the system.
The system can notify each VRML scene that the size changed (switch from portait 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 useless calculations, we decided to have two calculation modes:
First, identify both following cases:
If a prototype displays one (or more) graphical element(s) depending on the
screen size, the position of the element in the screen must be set by its parent
(the scene calling the prototype, has a
Transform2D node node with a
translation one step over the prototype node).
If the parent need the children's size to position it:
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 attribut 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.