Example code

There are three example projects associated with this chapter, which are described in the following sections.

The Font project

The first example project demonstrates the use of the IwGxFont API and can be seen in the following screenshot. This example demonstrates how to use multiple fonts in a project, preparing text for printing, and scaling a font up and down in size:

The Font project

The UI project

The UI example implements a user interface library that adheres to the discussion on how to implement UI code presented earlier in this chapter. It also presents a fully functional localization library, including a Python script that can convert an XLS spreadsheet into separate language datafiles. The script also produces a file for each language detailing all the characters that were used by any of the strings for that language. This can be very useful when generating a font resource to display the text.

The UI and localization library have been implemented as Marmalade subprojects (called GUI and Localise), which makes them very easy to re-use in other projects. If you find either of them useful, feel free to make use of them in your own projects.

The text strings are contained in an XLS file contained in the data/text directory. English and French strings have been included, though apologies to any French-speaking readers if these strings are not a 100 percent correct, as they were generated using an online translation engine

In the Windows Simulator it is possible to see the program running using both of the supplied language files. With the application running, go to Configuration | Deviceā€¦. In the dialog that appears, there is a drop-down box labeled Reported Device Language. Choose ENGLISH or FRENCH in this list and then click on the OK button. Quit the program and run it again and the selected language will be used.

A screenshot of this sample in action is as follows:

The UI project

The Skiing project

Finally we come to our evolving Skiing! game, which now has a simple yet much nicer looking user interface thanks to the GUI and Localise modules created for the UI example. The following screenshot shows the new main menu screen:

The Skiing project
..................Content has been hidden....................

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