View Single Post
  #1 (permalink)  
Old 04-24-2009, 07:05 AM
Erel's Avatar
Erel Erel is offline
Administrator
 
Join Date: Apr 2007
Posts: 4,831
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default AutoScale compilation mode and external libraries

The new version includes an important new compilation mode: AutoScale.
Some explanation about this mode:
When the program starts it checks the device's screen dpi.
It saves these two values in two variables: screenX and screenY.
QVGA screens will return 1 for screenX and screenY.
VGA screens will return 2 for screenX and screenY.
Other values are also possible.
There are another two relevant variables: fixX and fixY.
In the regular compilation mode these variables are constants and equal 1.
In AutoScale compilation these variables are equal to screenX/Y variables.

When a control is created its location and size values will be multiplied with these values.
For example:
Button1.Width = 70 will be translated to Button1.Width = 70 * fixX.
Button1.Left = 20 will be translated to Button1.Height = 20 * fixY.

So the result is that the QVGA layout will appear identical on high resolution screens as well.

External controls libraries should also deal with the different dpis.
Simple solution (this is how ControlsEx.dll deals with it):
Mark your library by adding:
Code:
C#: public static object B4P_AutoScale = null;
VB .Net: Public Shared B4P_AutoScale As Object
Now all parameters that are named (case insensitive) width, height, left or top will automatically be converted as required.

For more complex libraries that need to deal with the different values you can access these 4 values with:
Code:
double scaleX = (double)(Thread.GetData(Thread.GetNamedDataSlot("scaleX")));
double scaleY = (double)(Thread.GetData(Thread.GetNamedDataSlot("scaleY")));
double fixX = (double)(Thread.GetData(Thread.GetNamedDataSlot("fixX")));
double fixY = (double)(Thread.GetData(Thread.GetNamedDataSlot("fixY")));
For example the TreeView controls has this code in the constructor which sets the default size of the images to look the same on VGA and QVGA:
Code:
double scaleX = (double)(Thread.GetData(Thread.GetNamedDataSlot("scaleX")));
double scaleY = (double)(Thread.GetData(Thread.GetNamedDataSlot("scaleY")));
il.ImageSize = new Size((int)(il.ImageSize.Width * scaleX), (int)(il.ImageSize.Height * scaleY));
Note that the boolean value cPPC can also be fetched in the same way.
__________________
Basic4ppc reference list
Reply With Quote