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

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.

Warning: This page is 58 kilobytes long; some browsers may have problems editing pages approaching or longer than 32kb. Please consider breaking the page into smaller sections.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
-
The <code>osso-games-startup</code> application is a generic game start-up interface, providing a common [[hildon|hildonized]] user interface view for game start-up control and configuration.
+
= 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 ==
==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.
-
To execute the game, the <code>osso-games-startup</code> application needs to be called. The game configuration file must be passed as an argument. Once loaded, <code>osso-games-startup</code> creates a common interface for all games and, if needed, loads 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 [[#Integrating-non-gtk+ Games]]).
-
When the Play button is pressed, the D-Bus service defined in the configuration file is 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 [[#Integrating non-GTK+ Games]]).
+
The service is called every time any communication between osso-games-startup and the game is needed.
-
The service is called every time any communication between <code>osso-games-startup</code> and the game is needed.
+
The following diagram illustrates the operational execution flow of the osso-games-startup application.
-
 
+
-
The following diagram illustrates the operational execution flow of the <code>osso-games-startup</code> application.
+
[[Image:diagram_chinook.png]]
[[Image:diagram_chinook.png]]
 +
==Integration ==
==Integration ==
Line 19: Line 21:
* Games based on GTK+
* Games based on GTK+
* Games based on other toolkits, such as SDL
* Games based on other toolkits, such as SDL
 +
===Integrating GTK+ Games ===
===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:
-
To integrate games based on GTK+, a configuration file must be created, defining the information necessary for the <code>osso-games-startup</code> application. The following example illustrates the contents of the configuration file:
+
<div class="graybox">
-
<pre>
+
<nowiki>
-
[Startup Entry]
+
[Startup Entry]
-
# the name of the application
+
# the name of the application
-
Name=example
+
Name=example
-
# the current version of the application
+
# the current version of the application
-
Version=0.2.0
+
Version=0.2.0
-
# the title that is used, if not specified by the GettextPackage
+
# the title that will be used, if not specified by the GettextPackage
-
Title=Example
+
Title=Example
-
# the GettextPackage to be used to locate the title string
+
# the GettextPackage to be used to locate the title string
-
GettextPackage=example
+
GettextPackage=example
-
# if the TitleId is defined, it searches for it inside the gettext package
+
# if the TitleId is defined, it will search for it inside the gettext package
-
TitleId=example_title
+
TitleId=example_title
-
# if the game has a plug-in
+
# if the game has a plug-in
-
PluginPath=/usr/share/example/example_plugin.so
+
PluginPath=/usr/share/example/example_plugin.so
-
# the games-startup screen image
+
# the games-startup screen image
-
Image=/usr/share/example/pixmaps/example.png
+
Image=/usr/share/example/pixmaps/example.png
-
# the D-Bus service, path and interface names
+
# the D-BUS service, path and interface names
-
ServiceName=com.domain.example
+
ServiceName=com.domain.example
-
PathName=/com/domain/example
+
PathName=/com/domain/example
-
InterfaceName=com.domain.example
+
InterfaceName=com.domain.example
-
</pre>
+
</nowiki>
-
The game must 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 <code>osso-games-startup</code> application, the game must register the service as defined in the configuration file.
+
</div>
-
When sending messages to <code>osso-games-startup</code>, the game must use the service, path and interface name defined in the configuration file, but with a "_startup" suffix.
 
-
Next, a D-Bus service (a .service file) must 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:
+
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.
-
<pre>
+
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.
-
[D-BUS Service]
+
-
Name=com.domain.example
+
-
Exec=/usr/games/wrapper/games/wrapper.l
+
-
</pre>
+
-
Finally, the game must create a shell script that calls the <code>osso-games-startup</code> application executable and passes the game configuration file as an argument. The following example illustrates the contents of the script:
+
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:
-
<source lang="c">
+
<div class="graybox">
 +
[D-BUS Service]
 +
Name=com.domain.example
 +
Exec=/usr/games/wrapper/games/wrapper.l
 +
</div>
 +
 
 +
 
 +
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:
 +
 
 +
<div class="graybox">
  /usr/bin/osso_games_startup /usr/share/example/example.conf
  /usr/bin/osso_games_startup /usr/share/example/example.conf
-
</source>
+
</div>
 +
 
 +
 
===Integrating non-GTK+ Games ===
===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.
-
In order to integrate non-GTK+ applications to <code>osso-games-startup</code>, differences in the actual game implementation must be dealt with. The same steps must be followed to create osso desktop files and registering D-Bus services as for the GTK+ based games; the only difference is that Nokia is providing a hildon-games-wrapper library to deal with D-Bus 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
-
To initialize game application to receive events from osso-games-startup, the snippets/games_integrating_non-gtk+-hgw__init approach can be used.
+
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.
-
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 which state the game was started in. This is done by calling <code>hgw_context_get_start_command()</code>. The return values indicate the state the game must 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 <code>HgwStartCommand</code> 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_
-
In the game's event loop, the user has to check if events are available by calling <code>hgw_msg_check_incoming()</code>. It returns <code>HGW_ERR_COMMUNICATION</code> if there are messages available and other values if messages are not available or if there was error. (see hgw/hgw.h for more details about <code>HgwError</code> 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.
-
Pointer <code>*msg</code> then holds information about the received dbus message and the game application is able to process and act accordingly. Actual information about the received events is stored in <code>msg->e_val</code> which is an enumeration mapped against <code>HgwCallback</code>.
+
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.
-
When the game ends or the game is requested to pause or quit, a call to <code>hgw_context_destroy()</code> is made with initialized <code>hgw</code> 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.
-
 
+
-
Also, <code>hildon-games-wrapper</code> library provides an interface to gconf. GConf is used to store persistent data such as the level of difficulty and sounds on/off. This method is preferred because the data stored in GConf is automatically backed up and restored when the user chooses to do so (from desktop, back-up manager). However, this interface is read-only, because writing happens in the game-specific plug-in in the <code>osso-games-startup</code> screen.
+
== Creating Game-Specific Plug-in ==
== 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.
-
Each game can create a plug-in for specific settings, such as sound control or difficulty level. Basically, each plug-in must implement some pre-defined functions that are executed by the <code>osso-games-startup</code> application.
+
The functions that can be implemented by each plug-in are:
The functions that can be implemented by each plug-in are:
-
* <code>static GtkWidget *load_plugin (void)</code>: This function creates the game-specific plug-in.
+
* static GtkWidget *load_plugin (void) This function creates the game-specific plug-in.
-
* <code>static void unload_plugin (void)</code>: This function destroys global variables, if necessary.
+
* static void unload_plugin (void) This function destroys global variables, if necessary.
-
* <code>static void write_config (void)</code>: This function saves the game configuration chosen by the player using the plug-in options.
+
* 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 <code>osso-games-startup</code> screen main menu (see figure [localhost#fig:basic_osso-games-startup_app_screen 8.1]), the following functions must be used:
+
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:
-
* <code>static GtkWidget **load_menu (guint *)</code>: This function creates the game-specific submenu that is added to the osso-games-startup main menu.
+
* static GtkWidget **load_menu (guint *) This function creates the game-specific submenu that is added to the osso-games-startup main menu.
-
* <code>static void update_menu (void)</code>: This function updates the game-specific menu.
+
* static void update_menu (void) This function updates the game-specific menu.
-
The struct below must be filled and sent to the <code>osso-games-startup</code> application. It specifies which plug-in functions the start-up must call.  snippets/games_integrating_non-gtk+-StartupPluginInfo
+
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.
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 <code>osso-games-startup</code> info. The reference is given when <code>STARTUP_INIT_PLUGIN</code> is called. The following example illustrates a reference to osso-games-startup:  snippets/games_integrating_non-gtk+-GameStartupInfo
+
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 <code>STARTUP_INIT_PLUGIN</code> that initializes the plug-in. The parameters, in the order they are shown, are:
+
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)
* Pointer for plug-in information (see the struct shown above)
-
* <code>GameStartupInfo</code>
+
* GameStartupInfo
-
* Definition on whether the <code>osso-games-startup</code> should send a D-Bus message on closing
+
* Definition on whether the osso-games-startup should send a D-BUS message on closing
-
* Definition on whether the <code>osso-games-startup</code> menu has open/save game options
+
* Definition on whether the osso-games-startup menu has open/save game options
snippets/games_integrating_non-gtk+-STARTUP_INIT_PLUGIN
snippets/games_integrating_non-gtk+-STARTUP_INIT_PLUGIN
-
In order to inform <code>osso-games-startup</code> that the game has a plug-in, the .conf configuration file of the game must include the <code>PluginPath</code> entry, such as
+
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.
-
PluginPath=datadir/game01/game01_plugin.so
+
-
===Building Example Plug-in for CrazyParking ===
 
 +
===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.  
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.  
Line 121: Line 128:
[[Image: crazyparking.png|400px]]
[[Image: crazyparking.png|400px]]
-
Source code is available [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/crazyparking/ here].
+
Source code is available [https://garage.maemo.org/svn/maemoexamples/branches/fremantle-sdk-testing/crazyparking/ here].
-
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 desired: as a basic skeleton for the game, or simply to gain a better understanding of the game start-up.
+
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.
-
Because the plug-in and osso-games-startup are written with GTK+-2.0, they must include <code>startup_plugin.h</code> from <code>osso-games-startup</code>. In addition, GConf is used to save the user settings. [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/crazyparking/src/plugin/plugin.c crazyparking/src/plugin/plugin.c]
+
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
-
<source lang="c">
+
<tt><span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000">&lt;stdio.h&gt;</font></span>
-
#include <stdio.h>
+
<span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000">&lt;gtk/gtk.h&gt;</font></span>
-
#include <gtk/gtk.h>
+
<span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000">&lt;startup_plugin.h&gt;</font></span>
-
#include <startup_plugin.h>
+
<span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000">&lt;gconf/gconf.h&gt;</font></span>
-
#include <gconf/gconf.h>
+
<span>'''<span><font color="#000080"><nowiki>#include</nowiki></font></span>'''</span> <span><font color="#FF0000">&lt;gconf/gconf-client.h&gt;</font></span>
-
#include <gconf/gconf-client.h>
+
<span>'''<span><font color="#000080"><nowiki>#define</nowiki></font></span>'''</span> MENU_SOUND <span><font color="#993399">15</font></span>
-
#define MENU_SOUND 15
+
</tt>
-
</source>
+
-
The following example illustrates the labels for retrieving information at GConf: [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/crazyparking/src/plugin/plugin.c crazyparking/src/plugin/plugin.c]
+
The following example illustrates the labels for retrieving information at GConf: crazyparking/src/plugin/plugin.c
-
<source lang="c">
+
<tt><span>'''<span><font color="#000080"><nowiki>#define</nowiki></font></span>'''</span> SETTINGS_LEVEL <span><font color="#FF0000">"/apps/osso/crazyparking/level"</font></span>
-
#define SETTINGS_LEVEL "/apps/osso/crazyparking/level"
+
<span>'''<span><font color="#000080"><nowiki>#define</nowiki></font></span>'''</span> SETTINGS_SOUND <span><font color="#FF0000">"/apps/osso/crazyparking/sound"</font></span></tt>
-
#define SETTINGS_SOUND "/apps/osso/crazyparking/sound"
+
-
</source>
+
The following example illustrates the functions that are implemented:
The following example illustrates the functions that are implemented:
-
<source lang="c">
+
<tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span><span>'''<span><font color="#000000">load_plugin</font></span>'''</span>         <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">);</font></span>
-
static GtkWidget  *load_plugin          (void);
+
<span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">unload_plugin</font></span>'''</span>       <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">);</font></span>
-
static void        unload_plugin        (void);
+
<span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">write_config</font></span>'''</span>         <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">);</font></span>
-
static void        write_config        (void);
+
<span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>**</nowiki></font></span><span>'''<span><font color="#000000">load_menu</font></span>'''</span>           <span><font color="#990000">(</font></span>guint <span><font color="#990000"><nowiki>*);</nowiki></font></span>
-
static GtkWidget **load_menu            (guint *);
+
<span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span>        <span>'''<span><font color="#000000">update_menu</font></span>'''</span>          <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">);</font></span>
-
static void        update_menu          (void);
+
<span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span>       <span>'''<span><font color="#000000">plugin_callback</font></span>'''</span>     <span><font color="#990000">(</font></span><span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>menu_item<span><font color="#990000">,</font></span> <span><font color="#008080">gpointer</font></span> data<span><font color="#990000">);</font></span>
-
static void        plugin_callback      (GtkWidget *menu_item, gpointer data);
+
<span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span>        <span>'''<span><font color="#000000">settings_callback</font></span>'''</span>    <span><font color="#990000">(</font></span><span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>widget<span><font color="#990000">,</font></span> <span><font color="#008080">gpointer</font></span> data<span><font color="#990000">);</font></span>
-
static void        settings_callback    (GtkWidget *widget, gpointer data);
+
<span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span>        <span>'''<span><font color="#000000">sound_callback</font></span>'''</span>      <span><font color="#990000">(</font></span><span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>widget<span><font color="#990000">,</font></span> <span><font color="#008080">gpointer</font></span> data<span><font color="#990000">);</font></span></tt>
-
static void        sound_callback      (GtkWidget *widget, gpointer data);
+
-
</source>
+
-
 
+
-
The following example illustrates some global variables: [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/crazyparking/src/plugin/plugin.c crazyparking/src/plugin/plugin.c]
+
-
 
+
-
<source lang="c">
+
-
GConfClient *gcc = NULL;
+
-
GtkWidget *board_box;
+
-
GtkWidget *level_1_item;
+
-
GtkWidget *level_2_item;
+
-
GtkWidget *level_3_item;
+
-
GtkWidget *level_4_item;
+
-
GtkWidget *level_5_item;
+
-
GtkWidget *level_6_item;
+
-
GtkWidget *level_7_item;
+
-
GtkWidget *level_8_item;
+
-
GtkWidget *level_9_item;
+
-
GtkWidget *level_10_item;
+
-
GtkWidget *level_11_item;
+
-
GtkWidget *level_12_item;
+
-
GtkWidget *settings_item;
+
-
GtkWidget *settings_menu;
+
-
GtkWidget *difficulty_item;
+
-
GtkWidget *difficulty_menu;
+
-
static GameStartupInfo gs;
+
-
GtkWidget *menu_items[2];
+
-
static int changed = FALSE;
+
-
GSList * group = NULL;
+
-
GtkWidget *sound_check = NULL;
+
-
GtkWidget *sound_item;
+
-
</source>
+
-
 
+
-
The implemented functions of the plug-in must be sent to osso-games-startup: in this case, a <code>GTK_SPIN_BUTTON</code> and a <code>GTK_CHECK_ITEM</code>. If the plug-in has no specific menu, <code>load_menu</code> and <code>update_menu</code> must be <code>NULL</code> [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/crazyparking/src/plugin/plugin.c crazyparking/src/plugin/plugin.c]
+
-
 
+
-
<source lang="c">
+
-
static StartupPluginInfo plugin_info = {
+
-
  load_plugin,
+
-
  unload_plugin,
+
-
  write_config,
+
-
  load_menu,
+
-
  update_menu,
+
-
  NULL
+
-
};
+
-
</source>
+
-
 
+
-
The following example illustrates the initializing plug-in that informs the application that there is a plug-in: [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/crazyparking/src/plugin/plugin.c crazyparking/src/plugin/plugin.c]
+
-
 
+
-
<source lang="c">
+
-
STARTUP_INIT_PLUGIN(plugin_info, gs, FALSE, FALSE);
+
-
</source>
+
-
 
+
-
The following example illustrates the function that initializes the widgets that localize the osso-games-startup standard buttons: [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/crazyparking/plugin/plugin.c crazyparking/src/plugin/plugin.c]
+
-
 
+
-
<source lang="c">
+
-
static GtkWidget *load_plugin (void)
+
-
{
+
-
  int board, enable_sound;
+
-
  GtkWidget *game_hbox;
+
-
  GtkWidget *board_hbox, *board_label;
+
-
  GtkWidget *sound_hbox, *sound_label;
+
-
 
+
-
  g_type_init();
+
-
  gcc = gconf_client_get_default();
+
-
  board = gconf_client_get_int(gcc, SETTINGS_LEVEL, NULL);
+
-
  enable_sound = gconf_client_get_int(gcc, SETTINGS_SOUND, NULL);
+
-
 
+
-
  game_hbox = gtk_hbox_new (TRUE, 0);
+
-
  g_assert (game_hbox);
+
-
 
+
-
  board_hbox = gtk_hbox_new (FALSE, 4);
+
-
 
+
-
  board_box = gtk_spin_button_new_with_range (1, 12, 1);
+
-
  g_assert (board_box);
+
-
 
+
-
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (board_box), board);
+
-
  g_signal_connect(G_OBJECT(board_box), "value-changed", G_CALLBACK(settings_callback), NULL);
+
-
  gtk_box_pack_end (GTK_BOX (board_hbox), board_box, FALSE, FALSE, 0);
+
-
 
+
-
  board_label = gtk_label_new ("Starting level");
+
-
  g_assert(board_label);
+
-
 
+
-
  gtk_box_pack_end (GTK_BOX (board_hbox), board_label, FALSE, FALSE, 0);
+
-
 
+
-
  gtk_box_pack_start (GTK_BOX (game_hbox), board_hbox, FALSE, FALSE, 2);
+
-
 
+
-
  sound_hbox = gtk_hbox_new (FALSE, 4);
+
-
  sound_check = gtk_check_button_new();
+
The following example illustrates some global variables: crazyparking/src/plugin/plugin.c
-
  g_assert (sound_check);
+
-
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(sound_check), enable_sound);
+
<tt><span><font color="#008080">GConfClient</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>gcc <span><font color="#990000"><nowiki>=</nowiki></font></span> NULL<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  g_signal_connect (G_OBJECT(sound_check), "clicked",
+
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>board_box<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
                    G_CALLBACK(sound_callback), NULL);
+
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>level_1_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>level_2_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>level_3_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>level_4_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>level_5_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>level_6_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>level_7_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>level_8_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>level_9_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>level_10_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>level_11_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>level_12_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>settings_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>settings_menu<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>difficulty_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>difficulty_menu<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#008080">GameStartupInfo</font></span> gs<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>menu_items<span><font color="#990000">[</font></span><span><font color="#993399">2</font></span><span><font color="#990000">];</font></span>
 +
<span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">int</font></span> changed <span><font color="#990000"><nowiki>=</nowiki></font></span> FALSE<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
GSList <span><font color="#990000"><nowiki>*</nowiki></font></span> group <span><font color="#990000"><nowiki>=</nowiki></font></span> NULL<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>sound_check <span><font color="#990000"><nowiki>=</nowiki></font></span> NULL<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>sound_item<span><font color="#990000"><nowiki>;</nowiki></font></span> </tt>
-
  gtk_box_pack_end (GTK_BOX (sound_hbox), sound_check, FALSE, FALSE, 0);
+
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
-
  sound_label = gtk_label_new ("Sound");
+
<tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#008080">StartupPluginInfo</font></span> plugin_info <span><font color="#990000"><nowiki>=</nowiki></font></span> <span><font color="#FF0000">{</font></span>
-
  g_assert (sound_label);
+
  load_plugin<span><font color="#990000">,</font></span>
 +
  unload_plugin<span><font color="#990000">,</font></span>
 +
  write_config<span><font color="#990000">,</font></span>
 +
  load_menu<span><font color="#990000">,</font></span>
 +
  update_menu<span><font color="#990000">,</font></span>
 +
  NULL
 +
<span><font color="#FF0000">}</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span> </tt>
-
  gtk_box_pack_end (GTK_BOX (sound_hbox), sound_label, TRUE, TRUE, 0);
+
The following example illustrates the initializing plug-in that informs the application that there is a plug-in: crazyparking/src/plugin/plugin.c
-
  gtk_box_pack_start (GTK_BOX (game_hbox), sound_hbox, FALSE, FALSE, 2);
+
<tt><span>'''<span><font color="#000000">STARTUP_INIT_PLUGIN</font></span>'''</span><span><font color="#990000">(</font></span>plugin_info<span><font color="#990000">,</font></span> gs<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">);</font></span></tt>
-
  printf ("%s : %s : %d\n", __FILE__, __FUNCTION__, __LINE__);
+
The following example illustrates the function that initializes the widgets that localize the osso-games-startup standard buttons: crazyparking/src/plugin/plugin.c
-
  return game_hbox;
+
<tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span><span>'''<span><font color="#000000">load_plugin</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">)</font></span>
-
}
+
<span><font color="#FF0000">{</font></span>
-
</source>
+
  <span><font color="#009900">int</font></span> board<span><font color="#990000">,</font></span> enable_sound<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
  <span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>game_hbox<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
  <span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>board_hbox<span><font color="#990000">,</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>board_label<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
  <span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>sound_hbox<span><font color="#990000">,</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>sound_label<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
 +
  <span>'''<span><font color="#000000">g_type_init</font></span>'''</span><span><font color="#990000">();</font></span>
 +
  gcc <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gconf_client_get_default</font></span>'''</span><span><font color="#990000">();</font></span>
 +
  board <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gconf_client_get_int</font></span>'''</span><span><font color="#990000">(</font></span>gcc<span><font color="#990000">,</font></span> SETTINGS_LEVEL<span><font color="#990000">,</font></span> NULL<span><font color="#990000">);</font></span>
 +
  enable_sound <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gconf_client_get_int</font></span>'''</span><span><font color="#990000">(</font></span>gcc<span><font color="#990000">,</font></span> SETTINGS_SOUND<span><font color="#990000">,</font></span> NULL<span><font color="#990000">);</font></span>
 +
 +
  game_hbox <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_hbox_new</font></span>'''</span> <span><font color="#990000">(</font></span>TRUE<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">);</font></span>
 +
  <span>'''<span><font color="#000000">g_assert</font></span>'''</span> <span><font color="#990000">(</font></span>game_hbox<span><font color="#990000">);</font></span>
 +
 +
  board_hbox <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_hbox_new</font></span>'''</span> <span><font color="#990000">(</font></span>FALSE<span><font color="#990000">,</font></span> <span><font color="#993399">4</font></span><span><font color="#990000">);</font></span>
 +
 +
  board_box <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_spin_button_new_with_range</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#993399">1</font></span><span><font color="#990000">,</font></span> <span><font color="#993399">12</font></span><span><font color="#990000">,</font></span> <span><font color="#993399">1</font></span><span><font color="#990000">);</font></span>
 +
  <span>'''<span><font color="#000000">g_assert</font></span>'''</span> <span><font color="#990000">(</font></span>board_box<span><font color="#990000">);</font></span>
 +
 +
  <span>'''<span><font color="#000000">gtk_spin_button_set_value</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_SPIN_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>board_box<span><font color="#990000">),</font></span> board<span><font color="#990000">);</font></span>
 +
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span><span><font color="#990000">(</font></span>board_box<span><font color="#990000">),</font></span> <span><font color="#FF0000">"value-changed"</font></span><span><font color="#990000">,</font></span> <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span><span><font color="#990000">(</font></span>settings_callback<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span>
 +
  <span>'''<span><font color="#000000">gtk_box_pack_end</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_BOX</font></span>'''</span> <span><font color="#990000">(</font></span>board_hbox<span><font color="#990000">),</font></span> board_box<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">);</font></span>
 +
 +
  board_label <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_label_new</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Starting level"</font></span><span><font color="#990000">);</font></span>
 +
  <span>'''<span><font color="#000000">g_assert</font></span>'''</span><span><font color="#990000">(</font></span>board_label<span><font color="#990000">);</font></span>
 +
 +
  <span>'''<span><font color="#000000">gtk_box_pack_end</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_BOX</font></span>'''</span> <span><font color="#990000">(</font></span>board_hbox<span><font color="#990000">),</font></span> board_label<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">);</font></span>
 +
 +
  <span>'''<span><font color="#000000">gtk_box_pack_start</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_BOX</font></span>'''</span> <span><font color="#990000">(</font></span>game_hbox<span><font color="#990000">),</font></span> board_hbox<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">,</font></span> <span><font color="#993399">2</font></span><span><font color="#990000">);</font></span>
 +
 +
  sound_hbox <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_hbox_new</font></span>'''</span> <span><font color="#990000">(</font></span>FALSE<span><font color="#990000">,</font></span> <span><font color="#993399">4</font></span><span><font color="#990000">);</font></span>
 +
 +
  sound_check <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_check_button_new</font></span>'''</span><span><font color="#990000">();</font></span>
 +
  <span>'''<span><font color="#000000">g_assert</font></span>'''</span> <span><font color="#990000">(</font></span>sound_check<span><font color="#990000">);</font></span>
 +
 +
  <span>'''<span><font color="#000000">gtk_toggle_button_set_active</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TOGGLE_BUTTON</font></span>'''</span><span><font color="#990000">(</font></span>sound_check<span><font color="#990000">),</font></span> enable_sound<span><font color="#990000">);</font></span>
 +
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span><span><font color="#990000">(</font></span>sound_check<span><font color="#990000">),</font></span> <span><font color="#FF0000">"clicked"</font></span><span><font color="#990000">,</font></span>
 +
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span><span><font color="#990000">(</font></span>sound_callback<span><font color="#990000">),</font></span> NULL<span><font color="#990000">);</font></span>
 +
 +
  <span>'''<span><font color="#000000">gtk_box_pack_end</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_BOX</font></span>'''</span> <span><font color="#990000">(</font></span>sound_hbox<span><font color="#990000">),</font></span> sound_check<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">);</font></span>
 +
 +
  sound_label <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_label_new</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Sound"</font></span><span><font color="#990000">);</font></span>
 +
  <span>'''<span><font color="#000000">g_assert</font></span>'''</span> <span><font color="#990000">(</font></span>sound_label<span><font color="#990000">);</font></span>
 +
 +
  <span>'''<span><font color="#000000">gtk_box_pack_end</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_BOX</font></span>'''</span> <span><font color="#990000">(</font></span>sound_hbox<span><font color="#990000">),</font></span> sound_label<span><font color="#990000">,</font></span> TRUE<span><font color="#990000">,</font></span> TRUE<span><font color="#990000">,</font></span> <span><font color="#993399">0</font></span><span><font color="#990000">);</font></span>
 +
 +
  <span>'''<span><font color="#000000">gtk_box_pack_start</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_BOX</font></span>'''</span> <span><font color="#990000">(</font></span>game_hbox<span><font color="#990000">),</font></span> sound_hbox<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">,</font></span> FALSE<span><font color="#990000">,</font></span> <span><font color="#993399">2</font></span><span><font color="#990000">);</font></span>
 +
 +
  <span>'''<span><font color="#000000">printf</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"%s : %s : %d</font></span><span><font color="#CC33CC">\n</font></span><span><font color="#FF0000">"</font></span><span><font color="#990000">,</font></span> __FILE__<span><font color="#990000">,</font></span> __FUNCTION__<span><font color="#990000">,</font></span> __LINE__<span><font color="#990000">);</font></span>
 +
 +
  <span>'''<span><font color="#0000FF">return</font></span>'''</span> game_hbox<span><font color="#990000"><nowiki>;</nowiki></font></span>
 +
<span><font color="#FF0000">}</font></span></tt>
-
The following example illustrates the function that is responsible for using GConf to store the user preferences (as is recommended, because the back-up application stores the GConf database): [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/crazyparking/src/plugin/plugin.c crazyparking/src/plugin/plugin.c]
+
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
-
<source lang="c">
+
<tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">write_config</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">)</font></span>
-
static void write_config (void)
+
<span><font color="#FF0000">{</font></span>
-
{
+
  <span><font color="#009900">int</font></span> value<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  int value;
+
  value <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_spin_button_get_value_as_int</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_SPIN_BUTTON</font></span>'''</span><span><font color="#990000">(</font></span>board_box<span><font color="#990000">));</font></span>
-
  value = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(board_box));
+
  <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>value <span><font color="#990000">&lt;</font></span> <span><font color="#993399">1</font></span><span><font color="#990000">)</font></span> value <span><font color="#990000"><nowiki>=</nowiki></font></span> <span><font color="#993399">1</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  if (value < 1) value = 1;
+
  <span>'''<span><font color="#0000FF">else</font></span>'''</span> <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>value <span><font color="#990000">&gt;</font></span> <span><font color="#993399">12</font></span><span><font color="#990000">)</font></span> value <span><font color="#990000"><nowiki>=</nowiki></font></span> <span><font color="#993399">12</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  else if (value > 12) value = 12;
+
  <span>'''<span><font color="#000000">gconf_client_set_int</font></span>'''</span><span><font color="#990000">(</font></span>gcc<span><font color="#990000">,</font></span> SETTINGS_LEVEL<span><font color="#990000">,</font></span> value<span><font color="#990000">,</font></span> NULL<span><font color="#990000">);</font></span>
-
  gconf_client_set_int(gcc, SETTINGS_LEVEL, value, NULL);
+
  <span>'''<span><font color="#000000">gconf_client_set_int</font></span>'''</span><span><font color="#990000">(</font></span>gcc<span><font color="#990000">,</font></span> SETTINGS_SOUND<span><font color="#990000">,</font></span>
-
  gconf_client_set_int(gcc, SETTINGS_SOUND,
+
        <span>'''<span><font color="#000000">gtk_toggle_button_get_active</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TOGGLE_BUTTON</font></span>'''</span><span><font color="#990000">(</font></span>sound_check<span><font color="#990000">)),</font></span> NULL<span><font color="#990000">);</font></span>
-
        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sound_check)), NULL);
+
<span><font color="#FF0000">}</font></span></tt>
-
}
+
-
</source>
+
-
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: [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/crazyparking/src/plugin/plugin.c crazyparking/src/plugin/plugin.c]
+
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
-
<source lang="c">
+
<tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>**</nowiki></font></span><span>'''<span><font color="#000000">load_menu</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#008080">guint</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>nitems<span><font color="#990000">)</font></span>
-
static GtkWidget **load_menu (guint *nitems)
+
<span><font color="#FF0000">{</font></span>
-
{
+
  <span><font color="#009900">int</font></span> enable_sound<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  int enable_sound;
+
  <span>''<span><font color="#9A1900">//number of entries in maemo-games-startup main menu for this game </font></span>''</span>
-
  //number of entries in maemo-games-startup main menu for this game  
+
  <span><font color="#990000"><nowiki>*</nowiki></font></span>nitems <span><font color="#990000"><nowiki>=</nowiki></font></span> <span><font color="#993399">1</font></span><span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  *nitems = 1;
+
  settings_item <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_menu_item_new_with_label</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Settings"</font></span><span><font color="#990000">);</font></span>
-
  settings_item = gtk_menu_item_new_with_label ("Settings");
+
  settings_menu <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_menu_new</font></span>'''</span> <span><font color="#990000">();</font></span>
-
  settings_menu = gtk_menu_new ();
+
  menu_items<span><font color="#990000">[</font></span><span><font color="#993399">0</font></span><span><font color="#990000">]</font></span> <span><font color="#990000"><nowiki>=</nowiki></font></span> settings_item<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  menu_items[0] = settings_item;
+
  <span>'''<span><font color="#000000">gtk_menu_item_set_submenu</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_MENU_ITEM</font></span>'''</span> <span><font color="#990000">(</font></span>settings_item<span><font color="#990000">),</font></span> settings_menu<span><font color="#990000">);</font></span>
-
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (settings_item), settings_menu);
+
  <span>''<span><font color="#9A1900">//difficulty settings </font></span>''</span>
-
  //difficulty settings  
+
  difficulty_menu <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_menu_new</font></span>'''</span> <span><font color="#990000">();</font></span>
-
  difficulty_menu = gtk_menu_new ();
+
  difficulty_item <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_menu_item_new_with_label</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#FF0000">"Difficulty"</font></span><span><font color="#990000">);</font></span>
-
  difficulty_item = gtk_menu_item_new_with_label ("Difficulty");
+
  <span>'''<span><font color="#000000">gtk_menu_item_set_submenu</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_MENU_ITEM</font></span>'''</span> <span><font color="#990000">(</font></span>difficulty_item<span><font color="#990000">),</font></span> difficulty_menu<span><font color="#990000">);</font></span>
-
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (difficulty_item), difficulty_menu);
+
  <span>'''<span><font color="#000000">gtk_menu_append</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_MENU</font></span>'''</span> <span><font color="#990000">(</font></span>settings_menu<span><font color="#990000">),</font></span> difficulty_item<span><font color="#990000">);</font></span>
-
  gtk_menu_append (GTK_MENU (settings_menu), difficulty_item);
+
  level_1_item <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_radio_menu_item_new_with_label</font></span>'''</span> <span><font color="#990000">(</font></span>group<span><font color="#990000">,</font></span> <span><font color="#FF0000">"Level 1"</font></span><span><font color="#990000">);</font></span>
-
  level_1_item = gtk_radio_menu_item_new_with_label (group, "Level 1");
+
  <span>'''<span><font color="#000000">gtk_menu_append</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_MENU</font></span>'''</span> <span><font color="#990000">(</font></span>difficulty_menu<span><font color="#990000">),</font></span> level_1_item<span><font color="#990000">);</font></span>
-
  gtk_menu_append (GTK_MENU (difficulty_menu), level_1_item);
+
  group <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_radio_menu_item_group</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_RADIO_MENU_ITEM</font></span>'''</span><span><font color="#990000">(</font></span>level_1_item<span><font color="#990000">));</font></span>
-
  group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(level_1_item));
+
  level_2_item <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_radio_menu_item_new_with_label</font></span>'''</span> <span><font color="#990000">(</font></span>group<span><font color="#990000">,</font></span> <span><font color="#FF0000">"Level 2"</font></span><span><font color="#990000">);</font></span>
-
  level_2_item = gtk_radio_menu_item_new_with_label (group, "Level 2");
+
  <span>'''<span><font color="#000000">gtk_menu_append</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_MENU</font></span>'''</span> <span><font color="#990000">(</font></span>difficulty_menu<span><font color="#990000">),</font></span> level_2_item<span><font color="#990000">);</font></span>
-
  gtk_menu_append (GTK_MENU (difficulty_menu), level_2_item);
+
  group <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_radio_menu_item_group</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_RADIO_MENU_ITEM</font></span>'''</span><span><font color="#990000">(</font></span>level_2_item<span><font color="#990000">));</font></span>
-
  group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(level_2_item));
+
  level_3_item <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_radio_menu_item_new_with_label</font></span>'''</span> <span><font color="#990000">(</font></span>group<span><font color="#990000">,</font></span> <span><font color="#FF0000">"Level 3"</font></span><span><font color="#990000">);</font></span>
-
  level_3_item = gtk_radio_menu_item_new_with_label (group, "Level 3");
+
  <span>'''<span><font color="#000000">gtk_menu_append</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_MENU</font></span>'''</span> <span><font color="#990000">(</font></span>difficulty_menu<span><font color="#990000">),</font></span> level_3_item<span><font color="#990000">);</font></span>
-
  gtk_menu_append (GTK_MENU (difficulty_menu), level_3_item);
+
  group <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_radio_menu_item_group</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_RADIO_MENU_ITEM</font></span>'''</span><span><font color="#990000">(</font></span>level_3_item<span><font color="#990000">));</font></span>
-
  group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(level_3_item));
+
  <span>''<span><font color="#9A1900">/* ... Listing cut for brevity ...*/</font></span>''</span>
-
  /* ... Listing cut for brevity ...*/
+
  level_12_item <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_radio_menu_item_new_with_label</font></span>'''</span> <span><font color="#990000">(</font></span>group<span><font color="#990000">,</font></span> <span><font color="#FF0000">"Level 12"</font></span><span><font color="#990000">);</font></span>
-
  level_12_item = gtk_radio_menu_item_new_with_label (group, "Level 12");
+
  <span>'''<span><font color="#000000">gtk_menu_append</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_MENU</font></span>'''</span> <span><font color="#990000">(</font></span>difficulty_menu<span><font color="#990000">),</font></span> level_12_item<span><font color="#990000">);</font></span>
-
  gtk_menu_append (GTK_MENU (difficulty_menu), level_12_item);
+
  group <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_radio_menu_item_group</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_RADIO_MENU_ITEM</font></span>'''</span><span><font color="#990000">(</font></span>level_12_item<span><font color="#990000">));</font></span>
-
  group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(level_12_item));
+
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>level_1_item<span><font color="#990000">),</font></span> <span><font color="#FF0000">"toggled"</font></span><span><font color="#990000">,</font></span>
-
  g_signal_connect (G_OBJECT (level_1_item), "toggled",
+
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>plugin_callback<span><font color="#990000">),</font></span> <span><font color="#990000">(</font></span>gpointer<span><font color="#990000">)</font></span> LEVEL_1<span><font color="#990000">);</font></span>
-
                    G_CALLBACK (plugin_callback), (gpointer) LEVEL_1);
+
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>level_2_item<span><font color="#990000">),</font></span> <span><font color="#FF0000">"toggled"</font></span><span><font color="#990000">,</font></span>
-
  g_signal_connect (G_OBJECT (level_2_item), "toggled",
+
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>plugin_callback<span><font color="#990000">),</font></span> <span><font color="#990000">(</font></span>gpointer<span><font color="#990000">)</font></span> LEVEL_2<span><font color="#990000">);</font></span>
-
                    G_CALLBACK (plugin_callback), (gpointer) LEVEL_2);
+
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>level_3_item<span><font color="#990000">),</font></span> <span><font color="#FF0000">"toggled"</font></span><span><font color="#990000">,</font></span>
-
  g_signal_connect (G_OBJECT (level_3_item), "toggled",
+
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>plugin_callback<span><font color="#990000">),</font></span> <span><font color="#990000">(</font></span>gpointer<span><font color="#990000">)</font></span> LEVEL_3<span><font color="#990000">);</font></span>
-
                    G_CALLBACK (plugin_callback), (gpointer) LEVEL_3);
+
  <span>''<span><font color="#9A1900">/* ... Listing cut for brevity ...*/</font></span>''</span>
-
  /* ... Listing cut for brevity ...*/
+
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>level_12_item<span><font color="#990000">),</font></span> <span><font color="#FF0000">"toggled"</font></span><span><font color="#990000">,</font></span>
-
  g_signal_connect (G_OBJECT (level_12_item), "toggled",
+
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>plugin_callback<span><font color="#990000">),</font></span> <span><font color="#990000">(</font></span>gpointer<span><font color="#990000">)</font></span> LEVEL_12<span><font color="#990000">);</font></span>
-
                    G_CALLBACK (plugin_callback), (gpointer) LEVEL_12);
+
  <span>'''<span><font color="#000000">gtk_menu_append</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_MENU</font></span>'''</span> <span><font color="#990000">(</font></span>settings_menu<span><font color="#990000">),</font></span> <span>'''<span><font color="#000000">gtk_menu_item_new</font></span>'''</span><span><font color="#990000">());</font></span>
-
  gtk_menu_append (GTK_MENU (settings_menu), gtk_menu_item_new());
+
  <span>''<span><font color="#9A1900">//sound settings </font></span>''</span>
-
  //sound settings  
+
  sound_item <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_check_menu_item_new_with_label</font></span>'''</span><span><font color="#990000">(</font></span><span><font color="#FF0000">"Sound"</font></span><span><font color="#990000">);</font></span>
-
  sound_item = gtk_check_menu_item_new_with_label("Sound");
+
  <span>'''<span><font color="#000000">gtk_menu_append</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_MENU</font></span>'''</span> <span><font color="#990000">(</font></span>settings_menu<span><font color="#990000">),</font></span> sound_item<span><font color="#990000">);</font></span>
-
  gtk_menu_append (GTK_MENU (settings_menu), sound_item);
+
  <span>'''<span><font color="#000000">g_signal_connect</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">G_OBJECT</font></span>'''</span> <span><font color="#990000">(</font></span>sound_item<span><font color="#990000">),</font></span> <span><font color="#FF0000">"toggled"</font></span><span><font color="#990000">,</font></span>
-
  g_signal_connect (G_OBJECT (sound_item), "toggled",
+
                    <span>'''<span><font color="#000000">G_CALLBACK</font></span>'''</span> <span><font color="#990000">(</font></span>plugin_callback<span><font color="#990000">),</font></span> <span><font color="#990000">(</font></span>gpointer<span><font color="#990000">)</font></span> MENU_SOUND<span><font color="#990000">);</font></span>
-
                    G_CALLBACK (plugin_callback), (gpointer) MENU_SOUND);
+
  <span>'''<span><font color="#000000">gtk_check_menu_item_set_state</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CHECK_MENU_ITEM</font></span>'''</span><span><font color="#990000">(</font></span>sound_item<span><font color="#990000">),</font></span>
-
  gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM(sound_item),
+
  <span>'''<span><font color="#000000">gtk_toggle_button_get_active</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TOGGLE_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>sound_check<span><font color="#990000">)));</font></span>
-
  gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (sound_check)));
+
  <span>'''<span><font color="#0000FF">return</font></span>'''</span> menu_items<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  return menu_items;
+
<span><font color="#FF0000">}</font></span>
-
}
+
</tt>
-
</source>
+
-
The following example illustrates the function that is called when any configuration is performed in the menu. This function updates the <code>GTK_SPIN_BUTTON</code> (level change) or the <code>GTK_CHECK_MENU_ITEM</code> (sound change). [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/crazyparking/src/plugin/plugin.c crazyparking/src/plugin/plugin.c]
+
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
-
<source lang="c">
+
<tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">plugin_callback</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>menu_item<span><font color="#990000">,</font></span> <span><font color="#008080">gpointer</font></span> data<span><font color="#990000">)</font></span>
-
static void plugin_callback (GtkWidget *menu_item, gpointer  data)
+
<span><font color="#FF0000">{</font></span>
-
{
+
    <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>MENU_SOUND <span><font color="#990000"><nowiki>==</nowiki></font></span> <span><font color="#990000">(</font></span><span><font color="#009900">int</font></span><span><font color="#990000">)</font></span> data <span><font color="#990000">&amp;&amp;</font></span> <span><font color="#990000"><nowiki>!</nowiki></font></span>changed<span><font color="#990000">)</font></span><span><font color="#FF0000">{</font></span>
-
    if (MENU_SOUND == (int) data && !changed){
+
        changed <span><font color="#990000"><nowiki>=</nowiki></font></span> TRUE<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
        changed = TRUE;
+
        <span>'''<span><font color="#000000">gtk_toggle_button_set_active</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_TOGGLE_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>sound_check<span><font color="#990000">),</font></span>
-
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sound_check),
+
                                      <span>'''<span><font color="#000000">gtk_check_menu_item_get_active</font></span>'''</span> <span><font color="#990000">(</font></span>
-
                                      gtk_check_menu_item_get_active (
+
                                      <span>'''<span><font color="#000000">GTK_CHECK_MENU_ITEM</font></span>'''</span><span><font color="#990000">(</font></span>sound_item<span><font color="#990000">)));</font></span>
-
                                      GTK_CHECK_MENU_ITEM(sound_item)));
+
    <span><font color="#FF0000">}</font></span> <span>'''<span><font color="#0000FF">else</font></span>'''</span> <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(!</font></span>changed<span><font color="#990000">)</font></span> <span><font color="#FF0000">{</font></span>
-
    } else if (!changed) {
+
        changed <span><font color="#990000"><nowiki>=</nowiki></font></span> TRUE<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
        changed = TRUE;
+
        <span>'''<span><font color="#000000">gtk_spin_button_set_value</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_SPIN_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>board_box<span><font color="#990000">),</font></span> <span><font color="#990000">(</font></span><span><font color="#009900">int</font></span><span><font color="#990000">)</font></span> data<span><font color="#990000">);</font></span>
-
        gtk_spin_button_set_value (GTK_SPIN_BUTTON (board_box), (int) data);
+
    <span><font color="#FF0000">}</font></span>
-
    }
+
    changed <span><font color="#990000"><nowiki>=</nowiki></font></span> FALSE<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
    changed = FALSE;
+
<span><font color="#FF0000">}</font></span>
-
}
+
</tt>
-
</source>
+
-
The following example illustrates the function that is called to update the menu level option, when the user chooses the level using the <code>GTK_SPIN_BUTTON</code>: [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/crazyparking/src/plugin/plugin.c crazyparking/src/plugin/plugin.c]
+
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
-
<source lang="c">
+
<tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">settings_callback</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>widget<span><font color="#990000">,</font></span> <span><font color="#008080">gpointer</font></span> data<span><font color="#990000">)</font></span>
-
static void settings_callback (GtkWidget *widget, gpointer data)
+
<span><font color="#FF0000">{</font></span>
-
{
+
  <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(!</font></span>changed<span><font color="#990000">)</font></span> <span><font color="#FF0000">{</font></span>
-
  if (!changed) {
+
    changed <span><font color="#990000"><nowiki>=</nowiki></font></span> TRUE<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
    changed = TRUE;
+
    <span><font color="#008080">gint</font></span> active <span><font color="#990000"><nowiki>=</nowiki></font></span> <span>'''<span><font color="#000000">gtk_spin_button_get_value_as_int</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_SPIN_BUTTON</font></span>'''</span><span><font color="#990000">(</font></span>widget<span><font color="#990000">));</font></span>
-
    gint active = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
+
    <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>active <span><font color="#990000"><nowiki>==</nowiki></font></span> LEVEL_1<span><font color="#990000">)</font></span> <span><font color="#FF0000">{</font></span>
-
    if (active == LEVEL_1) {
+
      <span>'''<span><font color="#000000">gtk_check_menu_item_set_state</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CHECK_MENU_ITEM</font></span>'''</span><span><font color="#990000">(</font></span>level_1_item<span><font color="#990000">),</font></span> TRUE<span><font color="#990000">);</font></span>
-
      gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(level_1_item), TRUE);
+
    <span><font color="#FF0000">}</font></span>
-
    }
+
    <span>'''<span><font color="#0000FF">else</font></span>'''</span> <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>active <span><font color="#990000"><nowiki>==</nowiki></font></span> LEVEL_2<span><font color="#990000">)</font></span> <span><font color="#FF0000">{</font></span>
-
    else if (active == LEVEL_2) {
+
      <span>'''<span><font color="#000000">gtk_check_menu_item_set_state</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CHECK_MENU_ITEM</font></span>'''</span><span><font color="#990000">(</font></span>level_2_item<span><font color="#990000">),</font></span> TRUE<span><font color="#990000">);</font></span>
-
      gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(level_2_item), TRUE);
+
    <span><font color="#FF0000">}</font></span>
-
    }
+
    <span>'''<span><font color="#0000FF">else</font></span>'''</span> <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>active <span><font color="#990000"><nowiki>==</nowiki></font></span> LEVEL_3<span><font color="#990000">)</font></span> <span><font color="#FF0000">{</font></span>
-
    else if (active == LEVEL_3) {
+
      <span>'''<span><font color="#000000">gtk_check_menu_item_set_state</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CHECK_MENU_ITEM</font></span>'''</span><span><font color="#990000">(</font></span>level_3_item<span><font color="#990000">),</font></span> TRUE<span><font color="#990000">);</font></span>
-
      gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(level_3_item), TRUE);
+
    <span><font color="#FF0000">}</font></span>
-
    }
+
    <span>''<span><font color="#9A1900">/*... Listing cut for brevity ...*/</font></span>''</span>
-
    /*... Listing cut for brevity ...*/
+
    <span>'''<span><font color="#0000FF">else</font></span>'''</span> <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(</font></span>active <span><font color="#990000"><nowiki>==</nowiki></font></span> LEVEL_12<span><font color="#990000">)</font></span> <span><font color="#FF0000">{</font></span>
-
    else if (active == LEVEL_12) {
+
      <span>'''<span><font color="#000000">gtk_check_menu_item_set_state</font></span>'''</span><span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CHECK_MENU_ITEM</font></span>'''</span><span><font color="#990000">(</font></span>level_12_item<span><font color="#990000">),</font></span> TRUE<span><font color="#990000">);</font></span>
-
      gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(level_12_item), TRUE);
+
    <span><font color="#FF0000">}</font></span>
-
    }
+
  <span><font color="#FF0000">}</font></span>
-
  }
+
  changed <span><font color="#990000"><nowiki>=</nowiki></font></span> FALSE<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  changed = FALSE;
+
<span><font color="#FF0000">}</font></span>
-
}
+
</tt>
-
</source>
+
-
The following example illustrates the function that handles changes to the sound setup: [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/crazyparking/src/plugin/plugin.c crazyparking/src/plugin/plugin.c]
+
The following example illustrates the function that handles changes to the sound setup: crazyparking/src/plugin/plugin.c
-
<source lang="c">
+
<tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">sound_callback</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#008080">GtkWidget</font></span> <span><font color="#990000"><nowiki>*</nowiki></font></span>widget<span><font color="#990000">,</font></span> <span><font color="#008080">gpointer</font></span> data<span><font color="#990000">)</font></span>
-
static void sound_callback (GtkWidget *widget, gpointer data)
+
<span><font color="#FF0000">{</font></span>
-
{
+
  <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">(!</font></span>changed<span><font color="#990000">)</font></span> <span><font color="#FF0000">{</font></span>
-
  if (!changed) {
+
    changed <span><font color="#990000"><nowiki>=</nowiki></font></span> TRUE<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
    changed = TRUE;
+
    <span>'''<span><font color="#000000">gtk_check_menu_item_set_state</font></span>'''</span> <span><font color="#990000">(</font></span><span>'''<span><font color="#000000">GTK_CHECK_MENU_ITEM</font></span>'''</span><span><font color="#990000">(</font></span>sound_item<span><font color="#990000">),</font></span>
-
    gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM(sound_item),
+
                                    <span>'''<span><font color="#000000">gtk_toggle_button_get_active</font></span>'''</span><span><font color="#990000">(</font></span>
-
                                  gtk_toggle_button_get_active(
+
                                    <span>'''<span><font color="#000000">GTK_TOGGLE_BUTTON</font></span>'''</span> <span><font color="#990000">(</font></span>widget<span><font color="#990000">)));</font></span>
-
                                  GTK_TOGGLE_BUTTON (widget)));
+
  <span><font color="#FF0000">}</font></span>
-
  }
+
  changed <span><font color="#990000"><nowiki>=</nowiki></font></span> FALSE<span><font color="#990000"><nowiki>;</nowiki></font></span>
-
  changed = FALSE;
+
<span><font color="#FF0000">}</font></span></tt>
-
}
+
-
</source>
+
-
The following example illustrates the function that is called by <code>osso-games-startup</code>, if necessary. [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/crazyparking/src/plugin/plugin.c crazyparking/src/plugin/plugin.c]
+
The following example illustrates the function that is called by osso-games-startup, if necessary. crazyparking/src/plugin/plugin.c
-
<source lang="c">
+
<tt><span>'''<span><font color="#0000FF">static</font></span>'''</span> <span><font color="#009900">void</font></span> <span>'''<span><font color="#000000">update_menu</font></span>'''</span> <span><font color="#990000">(</font></span><span><font color="#009900">void</font></span><span><font color="#990000">)</font></span>
-
static void update_menu (void)
+
<span><font color="#FF0000">{</font></span>
-
{
+
  <span>'''<span><font color="#000000">settings_callback</font></span>'''</span><span><font color="#990000">(</font></span>board_box<span><font color="#990000">,</font></span> NULL<span><font color="#990000">);</font></span>
-
  settings_callback(board_box, NULL);
+
  <span>'''<span><font color="#000000">sound_callback</font></span>'''</span><span><font color="#990000">(</font></span>sound_check<span><font color="#990000">,</font></span> NULL<span><font color="#990000">);</font></span>
-
  sound_callback(sound_check, NULL);
+
<span><font color="#FF0000">}</font></span> </tt>
-
}
+
-
</source>
+
-
[[Category:Development]]
+
<br />
-
[[Category:Documentation]]
+
-
[[Category:Fremantle]]
+

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)