Documentation/Maemo 5 Developer Guide/Using Multimedia Components/Using Games Start-up Screen

= Using Games Start-up Screen = The osso-games-startup application is a generic game start-up interface, providing a common hildonized user interface view for game start-up control and configuration.

Application Functionality
To execute the game, the osso-games-startup application should be called. The game configuration file should be passed as an argument. Once loaded, osso-games-startup will create a common interface for all games and, if needed, will load a specific plug-in for each game. Games are activated through an auto-activating D-BUS message, which tells the game either to start, restart or to continue. In cases where no clean-up routine within the plug-in exists, it can also start the game to clean its state data. In these cases, the game usually does not open its own window, but kills the state data in the background instead.

When the Play button is pressed, the D-BUS service defined in the configuration file will be executed. Games that do not use the glib mainloop must integrate some functionality to their mainloop (for more information about games without a glib mainloop see section ).

The service is called every time any communication between osso-games-startup and the game is needed.

The following diagram illustrates the operational execution flow of the osso-games-startup application.

Integration
The integration tasks depend on the toolkit the game is based on. The following sections describe the integration tasks for:


 * Games based on GTK+
 * Games based on other toolkits, such as SDL

Integrating GTK+ Games
To integrate games based on GTK+, a configuration file should be created, defining the information necessary for the osso-games-startup application. The following example illustrates the contents of the configuration file:

[Startup Entry] Name=example Version=0.2.0 Title=Example GettextPackage=example TitleId=example_title PluginPath=/usr/share/example/example_plugin.so Image=/usr/share/example/pixmaps/example.png ServiceName=com.domain.example PathName=/com/domain/example InterfaceName=com.domain.example
 * 1) the name of the application
 * 1) the current version of the application
 * 1) the title that will be used, if not specified by the GettextPackage
 * 1) the GettextPackage to be used to locate the title string
 * 1) if the TitleId is defined, it will search for it inside  the gettext package
 * 1) if the game has a plug-in
 * 1) the games-startup screen image
 * 1) the D-BUS service, path and interface names

The game should be integrated with libosso to enable it to receive and send D-BUS messages, such as "pause", "restart" and "continue". In order to receive messages from the osso-games-startup application, the game must register the service as defined in the configuration file.

When sending messages to osso-games-startup, the game must use the service, path and interface name defined in the configuration file, but with a "_startup" suffix.

Then a D-BUS service (a .service file) should be created, using the name of the service that executes the game binary, as defined in the configuration file. The following example illustrates the contents of the file:

[D-BUS Service] Name=com.domain.example Exec=/usr/games/wrapper/games/wrapper.l

Finally, the game must create a shell script that calls the osso-games-startup application executable, and passes the game configuration file as an argument. The following example illustrates the contents of the script:

/usr/bin/osso_games_startup /usr/share/example/example.conf

Integrating non-GTK+ Games
In order to integrate non-GTK+ applications to osso-games-startup, the only thing different is the actual game implementation. The same steps should be followed to create osso desktop files and registering dbus services as for GTK+ based games; the only difference is that Nokia is providing a hildon-games-wrapper library to deal with dbus messaging without the use of libosso.

To initialize game application to receive events from osso-games-startup, the developer can use following approach: snippets/games_integrating_non-gtk+-hgw__init

If and when hgw pointer is not null, the game is ready to receive dbus messages that are intended for the game application. The next step is to check, what state the game was started in. This happens by calling hgw_context_get_start_command. The return values indicate the state the game should be going into. This is necessery, for example, when the game has been paused previously, the state of the game has been saved and the player wishes to continue the current game or restart the on-going game. Again, check the header file for HgwStartCommand for possible start values.

In the game's event loop, the user has to check if events are available by calling hgw_msg_check_incoming. It will return HGW_ERR_COMMUNICATION if there are messages available, and other values if there are not or if there was error. (see hgw/hgw.h for more details about HgwError enum) Example: snippets/games_integrating_non-gtk+-HGW_ERR_

Pointer *msg will then hold information about the received dbus message and the game application should then be able to process and act accordingly. Actual information about the received events is stored in msg-&gt;e_val which is an enumeration mapped against HgwCallback.

When the game ends or the game is requested to pause or quit, a call to hgw_context_destroy should be made with initialized hgw as a parameter.

Also, hildon-games-wrapper library provides an interface to gconf. Gconf should be used to store persistent data like the level of difficulty, sounds on/off etc. This way is preferred, because the data stored in gconf is automatically backed up and restored, when the user so chooses (from desktop, back-up manager). However, this interface is read-only, as writing should be happening in the game-specific plug-in in the osso-games-startup screen.

Creating Game-Specific Plug-in
Each game can create a plug-in for specific settings, such as sound control or difficulty level (see figure [localhost#fig:games_startup_app_screen_with_simple_plug-in 8.2]). Basically, each plug-in must implement some pre-defined functions that are executed by the osso-games-startup application.

The functions that can be implemented by each plug-in are:


 * static GtkWidget *load_plugin (void) This function creates the game-specific plug-in.
 * static void unload_plugin (void) This function destroys global variables, if necessary.
 * static void write_config (void) This function saves the game configuration chosen by the player using the plug-in options.

If the game needs a submenu in the osso-games-startup screen main menu (see figure [localhost#fig:basic_osso-games-startup_app_screen 8.1]), the following functions must be used:


 * static GtkWidget **load_menu (guint *) This function creates the game-specific submenu that is added to the osso-games-startup main menu.
 * static void update_menu (void) This function updates the game-specific menu.

The struct below must be filled and sent to the osso-games-startup application. It specifies which plug-in functions the start-up must call. snippets/games_integrating_non-gtk+-StartupPluginInfo

The last item on the struct is necessary only if the game plug-in requires items such as "save", "save as" or "open" to be a submenu in the default Game submenu.

Each plug-in must contain a reference to the osso-games-startup info. The reference is given when STARTUP_INIT_PLUGIN is called. The following example illustrates a reference to osso-games-startup: snippets/games_integrating_non-gtk+-GameStartupInfo

The following example illustrates the STARTUP_INIT_PLUGIN that initializes the plug-in. The parameters, in the order they are shown, are:


 * Pointer for plug-in information (see the struct shown above)
 * GameStartupInfo
 * Definition on whether the osso-games-startup should send a D-BUS message on closing
 * Definition on whether the osso-games-startup menu has open/save game options

snippets/games_integrating_non-gtk+-STARTUP_INIT_PLUGIN

In order to inform osso-games-startup that the game has a plug-in, the .conf configuration file of the game must include the PluginPath entry, such as PluginPath=datadir/game01/game01_plugin.so.

Building Example Plug-in for CrazyParking
This section illustrates the plug-in for CrazyParking implementation. The plug-in allows the player to set the initial level of the game, and to define whether the game uses sounds.

Games Start-up screen with CrazyParking plug-in's level and sound configuration:



The following code examples illustrate how the Games Start-up screen works, but the best way to learn to use it is to tinker with the game itself. The source code can be used as wished: as a basic skeleton for the game, or simply to gain a better understanding of the game start-up.

Since the plug-in and osso-games-startup are written with GTK+-2.0, they must include startup_plugin.h from osso-games-startup. In addition, Gconf is used to save the user settings. crazyparking/src/plugin/plugin.c

   #include  &lt;stdio.h&gt;   #include  &lt;gtk/gtk.h&gt;   #include  &lt;startup_plugin.h&gt;   #include  &lt;gconf/gconf.h&gt;   #include  &lt;gconf/gconf-client.h&gt;   #define  MENU_SOUND 15 

The following example illustrates the labels for retrieving information at GConf: crazyparking/src/plugin/plugin.c

   #define  SETTINGS_LEVEL <font color="#FF0000">"/apps/osso/crazyparking/level"  <font color="#000080"> #define  SETTINGS_SOUND <font color="#FF0000">"/apps/osso/crazyparking/sound" </tt>

The following example illustrates the functions that are implemented:

  <font color="#0000FF">static  <font color="#008080">GtkWidget  <font color="#990000"> *   <font color="#000000">load_plugin           <font color="#990000">(  <font color="#009900">void  <font color="#990000">);  <font color="#0000FF">static  <font color="#009900">void         <font color="#000000">unload_plugin         <font color="#990000">(  <font color="#009900">void  <font color="#990000">);  <font color="#0000FF">static  <font color="#009900">void         <font color="#000000">write_config          <font color="#990000">(  <font color="#009900">void  <font color="#990000">);  <font color="#0000FF">static  <font color="#008080">GtkWidget  <font color="#990000"> **   <font color="#000000">load_menu             <font color="#990000">( guint <font color="#990000"> *);  <font color="#0000FF">static  <font color="#009900">void         <font color="#000000">update_menu           <font color="#990000">(  <font color="#009900">void  <font color="#990000">);  <font color="#0000FF">static  <font color="#009900">void         <font color="#000000">plugin_callback       <font color="#990000">(  <font color="#008080">GtkWidget  <font color="#990000"> * menu_item <font color="#990000">,  <font color="#008080">gpointer data <font color="#990000">);  <font color="#0000FF">static  <font color="#009900">void         <font color="#000000">settings_callback     <font color="#990000">(  <font color="#008080">GtkWidget  <font color="#990000"> * widget <font color="#990000">,  <font color="#008080">gpointer data <font color="#990000">);  <font color="#0000FF">static  <font color="#009900">void         <font color="#000000">sound_callback        <font color="#990000">(  <font color="#008080">GtkWidget  <font color="#990000"> * widget <font color="#990000">,  <font color="#008080">gpointer data <font color="#990000">); </tt>

The following example illustrates some global variables: crazyparking/src/plugin/plugin.c

 <font color="#008080">GConfClient <font color="#990000"> * gcc <font color="#990000"> = NULL <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * board_box <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * level_1_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * level_2_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * level_3_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * level_4_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * level_5_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * level_6_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * level_7_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * level_8_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * level_9_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * level_10_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * level_11_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * level_12_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * settings_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * settings_menu <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * difficulty_item <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * difficulty_menu <font color="#990000"> ;  <font color="#0000FF">static  <font color="#008080">GameStartupInfo gs <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * menu_items <font color="#990000">[  <font color="#993399">2  <font color="#990000">];  <font color="#0000FF">static  <font color="#009900">int changed <font color="#990000"> = FALSE <font color="#990000"> ; GSList <font color="#990000"> * group <font color="#990000"> = NULL <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * sound_check <font color="#990000"> = NULL <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * sound_item <font color="#990000"> ; </tt>

The implemented functions of the plug-in must be sent to osso-games-startup: in this case, a GTK_SPIN_BUTTON and a GTK_CHECK_ITEM. If the plug-in has no specific menu, load_menu and update_menu must be NULL. crazyparking/src/plugin/plugin.c

  <font color="#0000FF">static  <font color="#008080">StartupPluginInfo plugin_info <font color="#990000"> =  <font color="#FF0000">{ load_plugin <font color="#990000">, unload_plugin <font color="#990000">, write_config <font color="#990000">, load_menu <font color="#990000">, update_menu <font color="#990000">, NULL <font color="#FF0000">} <font color="#990000"> ; </tt>

The following example illustrates the initializing plug-in that informs the application that there is a plug-in: crazyparking/src/plugin/plugin.c

  <font color="#000000">STARTUP_INIT_PLUGIN  <font color="#990000">( plugin_info <font color="#990000">, gs <font color="#990000">, FALSE <font color="#990000">, FALSE <font color="#990000">); </tt>

The following example illustrates the function that initializes the widgets that localize the osso-games-startup standard buttons: crazyparking/src/plugin/plugin.c

  <font color="#0000FF">static  <font color="#008080">GtkWidget  <font color="#990000"> *   <font color="#000000">load_plugin   <font color="#990000">(  <font color="#009900">void  <font color="#990000">) <font color="#FF0000">{ <font color="#009900">int board <font color="#990000">, enable_sound <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * game_hbox <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * board_hbox <font color="#990000">,  <font color="#990000"> * board_label <font color="#990000"> ; <font color="#008080">GtkWidget <font color="#990000"> * sound_hbox <font color="#990000">,  <font color="#990000"> * sound_label <font color="#990000"> ;  <font color="#000000">g_type_init  <font color="#990000">; gcc <font color="#990000"> =  <font color="#000000">gconf_client_get_default   <font color="#990000">; board <font color="#990000"> =  <font color="#000000">gconf_client_get_int   <font color="#990000">( gcc <font color="#990000">, SETTINGS_LEVEL <font color="#990000">, NULL <font color="#990000">); enable_sound <font color="#990000"> =  <font color="#000000">gconf_client_get_int   <font color="#990000">( gcc <font color="#990000">, SETTINGS_SOUND <font color="#990000">, NULL <font color="#990000">); game_hbox <font color="#990000"> =  <font color="#000000">gtk_hbox_new   <font color="#990000">( TRUE <font color="#990000">,  <font color="#993399">0  <font color="#990000">);  <font color="#000000">g_assert  <font color="#990000">( game_hbox <font color="#990000">); board_hbox <font color="#990000"> =  <font color="#000000">gtk_hbox_new   <font color="#990000">( FALSE <font color="#990000">,  <font color="#993399">4  <font color="#990000">); board_box <font color="#990000"> =  <font color="#000000">gtk_spin_button_new_with_range   <font color="#990000">(  <font color="#993399">1  <font color="#990000">,  <font color="#993399">12  <font color="#990000">,  <font color="#993399">1  <font color="#990000">);  <font color="#000000">g_assert  <font color="#990000">( board_box <font color="#990000">);  <font color="#000000">gtk_spin_button_set_value  <font color="#990000">(   <font color="#000000">GTK_SPIN_BUTTON   <font color="#990000">( board_box <font color="#990000">), board <font color="#990000">);  <font color="#000000">g_signal_connect  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( board_box <font color="#990000">),  <font color="#FF0000">"value-changed"  <font color="#990000">,   <font color="#000000">G_CALLBACK   <font color="#990000">( settings_callback <font color="#990000">), NULL <font color="#990000">);  <font color="#000000">gtk_box_pack_end  <font color="#990000">(   <font color="#000000">GTK_BOX   <font color="#990000">( board_hbox <font color="#990000">), board_box <font color="#990000">, FALSE <font color="#990000">, FALSE <font color="#990000">,  <font color="#993399">0  <font color="#990000">); board_label <font color="#990000"> =  <font color="#000000">gtk_label_new   <font color="#990000">(  <font color="#FF0000">"Starting level"  <font color="#990000">);  <font color="#000000">g_assert  <font color="#990000">( board_label <font color="#990000">);  <font color="#000000">gtk_box_pack_end  <font color="#990000">(   <font color="#000000">GTK_BOX   <font color="#990000">( board_hbox <font color="#990000">), board_label <font color="#990000">, FALSE <font color="#990000">, FALSE <font color="#990000">,  <font color="#993399">0  <font color="#990000">);  <font color="#000000">gtk_box_pack_start  <font color="#990000">(   <font color="#000000">GTK_BOX   <font color="#990000">( game_hbox <font color="#990000">), board_hbox <font color="#990000">, FALSE <font color="#990000">, FALSE <font color="#990000">,  <font color="#993399">2  <font color="#990000">); sound_hbox <font color="#990000"> =  <font color="#000000">gtk_hbox_new   <font color="#990000">( FALSE <font color="#990000">,  <font color="#993399">4  <font color="#990000">); sound_check <font color="#990000"> =  <font color="#000000">gtk_check_button_new   <font color="#990000">;  <font color="#000000">g_assert  <font color="#990000">( sound_check <font color="#990000">);  <font color="#000000">gtk_toggle_button_set_active  <font color="#990000">(   <font color="#000000">GTK_TOGGLE_BUTTON   <font color="#990000">( sound_check <font color="#990000">), enable_sound <font color="#990000">);  <font color="#000000">g_signal_connect  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( sound_check <font color="#990000">),  <font color="#FF0000">"clicked"  <font color="#990000">,                       <font color="#000000">G_CALLBACK   <font color="#990000">( sound_callback <font color="#990000">), NULL <font color="#990000">);  <font color="#000000">gtk_box_pack_end  <font color="#990000">(   <font color="#000000">GTK_BOX   <font color="#990000">( sound_hbox <font color="#990000">), sound_check <font color="#990000">, FALSE <font color="#990000">, FALSE <font color="#990000">,  <font color="#993399">0  <font color="#990000">); sound_label <font color="#990000"> =  <font color="#000000">gtk_label_new   <font color="#990000">(  <font color="#FF0000">"Sound"  <font color="#990000">);  <font color="#000000">g_assert  <font color="#990000">( sound_label <font color="#990000">);  <font color="#000000">gtk_box_pack_end  <font color="#990000">(   <font color="#000000">GTK_BOX   <font color="#990000">( sound_hbox <font color="#990000">), sound_label <font color="#990000">, TRUE <font color="#990000">, TRUE <font color="#990000">,  <font color="#993399">0  <font color="#990000">);  <font color="#000000">gtk_box_pack_start  <font color="#990000">(   <font color="#000000">GTK_BOX   <font color="#990000">( game_hbox <font color="#990000">), sound_hbox <font color="#990000">, FALSE <font color="#990000">, FALSE <font color="#990000">,  <font color="#993399">2  <font color="#990000">);  <font color="#000000">printf  <font color="#990000">(  <font color="#FF0000">"%s : %s : %d  <font color="#CC33CC">\n  <font color="#FF0000">"  <font color="#990000">, __FILE__ <font color="#990000">, __FUNCTION__ <font color="#990000">, __LINE__ <font color="#990000">);  <font color="#0000FF">return  game_hbox <font color="#990000"> ; <font color="#FF0000">} </tt>

The following example illustrates the function that is responsible for using Gconf to store the user preferences (as is recommended, since the back-up application stores the GConf database): crazyparking/src/plugin/plugin.c

  <font color="#0000FF">static  <font color="#009900">void   <font color="#000000">write_config   <font color="#990000">(  <font color="#009900">void  <font color="#990000">) <font color="#FF0000">{ <font color="#009900">int value <font color="#990000"> ; value <font color="#990000"> =  <font color="#000000">gtk_spin_button_get_value_as_int   <font color="#990000">(   <font color="#000000">GTK_SPIN_BUTTON   <font color="#990000">( board_box <font color="#990000">));  <font color="#0000FF">if  <font color="#990000">( value <font color="#990000">&lt;  <font color="#993399">1  <font color="#990000">) value <font color="#990000"> =  <font color="#993399">1  <font color="#990000"> ;  <font color="#0000FF">else   <font color="#0000FF">if   <font color="#990000">( value <font color="#990000">&gt;  <font color="#993399">12  <font color="#990000">) value <font color="#990000"> =  <font color="#993399">12  <font color="#990000"> ;  <font color="#000000">gconf_client_set_int  <font color="#990000">( gcc <font color="#990000">, SETTINGS_LEVEL <font color="#990000">, value <font color="#990000">, NULL <font color="#990000">);  <font color="#000000">gconf_client_set_int  <font color="#990000">( gcc <font color="#990000">, SETTINGS_SOUND <font color="#990000">,           <font color="#000000">gtk_toggle_button_get_active   <font color="#990000">(   <font color="#000000">GTK_TOGGLE_BUTTON   <font color="#990000">( sound_check <font color="#990000">)), NULL <font color="#990000">); <font color="#FF0000">} </tt>

The following example illustrates the function that initializes the game-specific plug-in menu, which is between the Game and Close submenus of osso-games-startup: crazyparking/src/plugin/plugin.c

  <font color="#0000FF">static  <font color="#008080">GtkWidget  <font color="#990000"> **   <font color="#000000">load_menu   <font color="#990000">(  <font color="#008080">guint  <font color="#990000"> * nitems <font color="#990000">) <font color="#FF0000">{ <font color="#009900">int enable_sound <font color="#990000"> ;  <font color="#9A1900">//number of entries in maemo-games-startup main menu for this game  <font color="#990000"> * nitems <font color="#990000"> = <font color="#993399">1  <font color="#990000"> ; settings_item <font color="#990000"> =  <font color="#000000">gtk_menu_item_new_with_label   <font color="#990000">(  <font color="#FF0000">"Settings"  <font color="#990000">); settings_menu <font color="#990000"> =  <font color="#000000">gtk_menu_new   <font color="#990000">; menu_items <font color="#990000">[ <font color="#993399">0  <font color="#990000">]  <font color="#990000"> = settings_item <font color="#990000"> ;  <font color="#000000">gtk_menu_item_set_submenu  <font color="#990000">(   <font color="#000000">GTK_MENU_ITEM   <font color="#990000">( settings_item <font color="#990000">), settings_menu <font color="#990000">);  <font color="#9A1900">//difficulty settings  difficulty_menu <font color="#990000"> =  <font color="#000000">gtk_menu_new   <font color="#990000">; difficulty_item <font color="#990000"> =  <font color="#000000">gtk_menu_item_new_with_label   <font color="#990000">(  <font color="#FF0000">"Difficulty"  <font color="#990000">);  <font color="#000000">gtk_menu_item_set_submenu  <font color="#990000">(   <font color="#000000">GTK_MENU_ITEM   <font color="#990000">( difficulty_item <font color="#990000">), difficulty_menu <font color="#990000">);  <font color="#000000">gtk_menu_append  <font color="#990000">(   <font color="#000000">GTK_MENU   <font color="#990000">( settings_menu <font color="#990000">), difficulty_item <font color="#990000">); level_1_item <font color="#990000"> =  <font color="#000000">gtk_radio_menu_item_new_with_label   <font color="#990000">( group <font color="#990000">,  <font color="#FF0000">"Level 1"  <font color="#990000">);  <font color="#000000">gtk_menu_append  <font color="#990000">(   <font color="#000000">GTK_MENU   <font color="#990000">( difficulty_menu <font color="#990000">), level_1_item <font color="#990000">); group <font color="#990000"> =  <font color="#000000">gtk_radio_menu_item_group   <font color="#990000">(   <font color="#000000">GTK_RADIO_MENU_ITEM   <font color="#990000">( level_1_item <font color="#990000">)); level_2_item <font color="#990000"> =  <font color="#000000">gtk_radio_menu_item_new_with_label   <font color="#990000">( group <font color="#990000">,  <font color="#FF0000">"Level 2"  <font color="#990000">);  <font color="#000000">gtk_menu_append  <font color="#990000">(   <font color="#000000">GTK_MENU   <font color="#990000">( difficulty_menu <font color="#990000">), level_2_item <font color="#990000">); group <font color="#990000"> =  <font color="#000000">gtk_radio_menu_item_group   <font color="#990000">(   <font color="#000000">GTK_RADIO_MENU_ITEM   <font color="#990000">( level_2_item <font color="#990000">)); level_3_item <font color="#990000"> =  <font color="#000000">gtk_radio_menu_item_new_with_label   <font color="#990000">( group <font color="#990000">,  <font color="#FF0000">"Level 3"  <font color="#990000">);  <font color="#000000">gtk_menu_append  <font color="#990000">(   <font color="#000000">GTK_MENU   <font color="#990000">( difficulty_menu <font color="#990000">), level_3_item <font color="#990000">); group <font color="#990000"> =  <font color="#000000">gtk_radio_menu_item_group   <font color="#990000">(   <font color="#000000">GTK_RADIO_MENU_ITEM   <font color="#990000">( level_3_item <font color="#990000">)); '' <font color="#9A1900">/* ... Listing cut for brevity ...*/ '' level_12_item <font color="#990000"> =  <font color="#000000">gtk_radio_menu_item_new_with_label   <font color="#990000">( group <font color="#990000">,  <font color="#FF0000">"Level 12"  <font color="#990000">);  <font color="#000000">gtk_menu_append  <font color="#990000">(   <font color="#000000">GTK_MENU   <font color="#990000">( difficulty_menu <font color="#990000">), level_12_item <font color="#990000">); group <font color="#990000"> =  <font color="#000000">gtk_radio_menu_item_group   <font color="#990000">(   <font color="#000000">GTK_RADIO_MENU_ITEM   <font color="#990000">( level_12_item <font color="#990000">));  <font color="#000000">g_signal_connect  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( level_1_item <font color="#990000">),  <font color="#FF0000">"toggled"  <font color="#990000">,                       <font color="#000000">G_CALLBACK   <font color="#990000">( plugin_callback <font color="#990000">),  <font color="#990000">( gpointer <font color="#990000">) LEVEL_1 <font color="#990000">);  <font color="#000000">g_signal_connect  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( level_2_item <font color="#990000">),  <font color="#FF0000">"toggled"  <font color="#990000">,                       <font color="#000000">G_CALLBACK   <font color="#990000">( plugin_callback <font color="#990000">),  <font color="#990000">( gpointer <font color="#990000">) LEVEL_2 <font color="#990000">);  <font color="#000000">g_signal_connect  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( level_3_item <font color="#990000">),  <font color="#FF0000">"toggled"  <font color="#990000">,                       <font color="#000000">G_CALLBACK   <font color="#990000">( plugin_callback <font color="#990000">),  <font color="#990000">( gpointer <font color="#990000">) LEVEL_3 <font color="#990000">); '' <font color="#9A1900">/* ... Listing cut for brevity ...*/ ''  <font color="#000000">g_signal_connect  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( level_12_item <font color="#990000">),  <font color="#FF0000">"toggled"  <font color="#990000">,                       <font color="#000000">G_CALLBACK   <font color="#990000">( plugin_callback <font color="#990000">),  <font color="#990000">( gpointer <font color="#990000">) LEVEL_12 <font color="#990000">);  <font color="#000000">gtk_menu_append  <font color="#990000">(   <font color="#000000">GTK_MENU   <font color="#990000">( settings_menu <font color="#990000">),   <font color="#000000">gtk_menu_item_new   <font color="#990000">);  <font color="#9A1900">//sound settings  sound_item <font color="#990000"> =  <font color="#000000">gtk_check_menu_item_new_with_label   <font color="#990000">(  <font color="#FF0000">"Sound"  <font color="#990000">);  <font color="#000000">gtk_menu_append  <font color="#990000">(   <font color="#000000">GTK_MENU   <font color="#990000">( settings_menu <font color="#990000">), sound_item <font color="#990000">);  <font color="#000000">g_signal_connect  <font color="#990000">(   <font color="#000000">G_OBJECT   <font color="#990000">( sound_item <font color="#990000">),  <font color="#FF0000">"toggled"  <font color="#990000">,                       <font color="#000000">G_CALLBACK   <font color="#990000">( plugin_callback <font color="#990000">),  <font color="#990000">( gpointer <font color="#990000">) MENU_SOUND <font color="#990000">);  <font color="#000000">gtk_check_menu_item_set_state  <font color="#990000">(   <font color="#000000">GTK_CHECK_MENU_ITEM   <font color="#990000">( sound_item <font color="#990000">),     <font color="#000000">gtk_toggle_button_get_active   <font color="#990000">(   <font color="#000000">GTK_TOGGLE_BUTTON   <font color="#990000">( sound_check <font color="#990000">)));  <font color="#0000FF">return  menu_items <font color="#990000"> ; <font color="#FF0000">} </tt>

The following example illustrates the function that is called when any configuration is performed in the menu. This function updates the GTK_SPIN_BUTTON (level change) or the GTK_CHECK_MENU_ITEM (sound change). crazyparking/src/plugin/plugin.c

  <font color="#0000FF">static  <font color="#009900">void   <font color="#000000">plugin_callback   <font color="#990000">(  <font color="#008080">GtkWidget  <font color="#990000"> * menu_item <font color="#990000">,  <font color="#008080">gpointer  data <font color="#990000">) <font color="#FF0000">{  <font color="#0000FF">if  <font color="#990000">( MENU_SOUND <font color="#990000"> ==  <font color="#990000">(  <font color="#009900">int  <font color="#990000">) data <font color="#990000">&amp;&amp;  <font color="#990000"> ! changed <font color="#990000">)  <font color="#FF0000">{ changed <font color="#990000"> = TRUE <font color="#990000"> ;  <font color="#000000">gtk_toggle_button_set_active  <font color="#990000">(   <font color="#000000">GTK_TOGGLE_BUTTON   <font color="#990000">( sound_check <font color="#990000">),                                         <font color="#000000">gtk_check_menu_item_get_active   <font color="#990000">(  <font color="#000000">GTK_CHECK_MENU_ITEM  <font color="#990000">( sound_item <font color="#990000">))); <font color="#FF0000">}  <font color="#0000FF">else    <font color="#0000FF">if   <font color="#990000">(! changed <font color="#990000">)  <font color="#FF0000">{ changed <font color="#990000"> = TRUE <font color="#990000"> ;  <font color="#000000">gtk_spin_button_set_value  <font color="#990000">(   <font color="#000000">GTK_SPIN_BUTTON   <font color="#990000">( board_box <font color="#990000">),  <font color="#990000">(  <font color="#009900">int  <font color="#990000">) data <font color="#990000">); <font color="#FF0000">} changed <font color="#990000"> = FALSE <font color="#990000"> ; <font color="#FF0000">} </tt>

The following example illustrates the function that is called to update the menu level option, when the user chooses the level using the GTK_SPIN_BUTTON: crazyparking/src/plugin/plugin.c

  <font color="#0000FF">static  <font color="#009900">void   <font color="#000000">settings_callback   <font color="#990000">(  <font color="#008080">GtkWidget  <font color="#990000"> * widget <font color="#990000">,  <font color="#008080">gpointer data <font color="#990000">) <font color="#FF0000">{  <font color="#0000FF">if  <font color="#990000">(! changed <font color="#990000">)  <font color="#FF0000">{ changed <font color="#990000"> = TRUE <font color="#990000"> ; <font color="#008080">gint active <font color="#990000"> =  <font color="#000000">gtk_spin_button_get_value_as_int   <font color="#990000">(   <font color="#000000">GTK_SPIN_BUTTON   <font color="#990000">( widget <font color="#990000">));  <font color="#0000FF">if  <font color="#990000">( active <font color="#990000"> == LEVEL_1 <font color="#990000">)  <font color="#FF0000">{  <font color="#000000">gtk_check_menu_item_set_state  <font color="#990000">(   <font color="#000000">GTK_CHECK_MENU_ITEM   <font color="#990000">( level_1_item <font color="#990000">), TRUE <font color="#990000">); <font color="#FF0000">}  <font color="#0000FF">else   <font color="#0000FF">if   <font color="#990000">( active <font color="#990000"> == LEVEL_2 <font color="#990000">)  <font color="#FF0000">{  <font color="#000000">gtk_check_menu_item_set_state  <font color="#990000">(   <font color="#000000">GTK_CHECK_MENU_ITEM   <font color="#990000">( level_2_item <font color="#990000">), TRUE <font color="#990000">); <font color="#FF0000">}  <font color="#0000FF">else   <font color="#0000FF">if   <font color="#990000">( active <font color="#990000"> == LEVEL_3 <font color="#990000">)  <font color="#FF0000">{  <font color="#000000">gtk_check_menu_item_set_state  <font color="#990000">(   <font color="#000000">GTK_CHECK_MENU_ITEM   <font color="#990000">( level_3_item <font color="#990000">), TRUE <font color="#990000">); <font color="#FF0000">} '' <font color="#9A1900">/*... Listing cut for brevity ...*/ ''  <font color="#0000FF">else   <font color="#0000FF">if   <font color="#990000">( active <font color="#990000"> == LEVEL_12 <font color="#990000">)  <font color="#FF0000">{  <font color="#000000">gtk_check_menu_item_set_state  <font color="#990000">(   <font color="#000000">GTK_CHECK_MENU_ITEM   <font color="#990000">( level_12_item <font color="#990000">), TRUE <font color="#990000">); <font color="#FF0000">} <font color="#FF0000">} changed <font color="#990000"> = FALSE <font color="#990000"> ; <font color="#FF0000">} </tt>

The following example illustrates the function that handles changes to the sound setup: crazyparking/src/plugin/plugin.c

  <font color="#0000FF">static  <font color="#009900">void   <font color="#000000">sound_callback   <font color="#990000">(  <font color="#008080">GtkWidget  <font color="#990000"> * widget <font color="#990000">,  <font color="#008080">gpointer data <font color="#990000">) <font color="#FF0000">{  <font color="#0000FF">if  <font color="#990000">(! changed <font color="#990000">)  <font color="#FF0000">{ changed <font color="#990000"> = TRUE <font color="#990000"> ;  <font color="#000000">gtk_check_menu_item_set_state  <font color="#990000">(   <font color="#000000">GTK_CHECK_MENU_ITEM   <font color="#990000">( sound_item <font color="#990000">),                                      <font color="#000000">gtk_toggle_button_get_active   <font color="#990000">(  <font color="#000000">GTK_TOGGLE_BUTTON  <font color="#990000">( widget <font color="#990000">))); <font color="#FF0000">} changed <font color="#990000"> = FALSE <font color="#990000"> ; <font color="#FF0000">} </tt>

The following example illustrates the function that is called by osso-games-startup, if necessary. crazyparking/src/plugin/plugin.c

  <font color="#0000FF">static  <font color="#009900">void   <font color="#000000">update_menu   <font color="#990000">(  <font color="#009900">void  <font color="#990000">) <font color="#FF0000">{  <font color="#000000">settings_callback  <font color="#990000">( board_box <font color="#990000">, NULL <font color="#990000">);  <font color="#000000">sound_callback  <font color="#990000">( sound_check <font color="#990000">, NULL <font color="#990000">); <font color="#FF0000">} </tt>