Back to index

gcompris  8.2.2
menu2.c
Go to the documentation of this file.
00001 /* gcompris - menu2.c
00002  *
00003  * Time-stamp: <2006/08/21 23:34:21 bruno>
00004  *
00005  * Copyright (C) 2000 Bruno Coudoin
00006  *
00007  *   This program is free software; you can redistribute it and/or modify
00008  *   it under the terms of the GNU General Public License as published by
00009  *   the Free Software Foundation; either version 2 of the License, or
00010  *   (at your option) any later version.
00011  *
00012  *   This program is distributed in the hope that it will be useful,
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *   GNU General Public License for more details.
00016  *
00017  *   You should have received a copy of the GNU General Public License
00018  *   along with this program; if not, write to the Free Software
00019  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  */
00021 
00027 #include <string.h>
00028 
00029 #include "gcompris/gcompris.h"
00030 #include "gcompris/gcompris_config.h"
00031 
00032 #define SOUNDLISTFILE PACKAGE
00033 #define MENU_PER_LINE 5
00034 
00035 typedef struct {
00036   /* Information items (_s are shadow) */
00037   GnomeCanvasItem *boardname_item;
00038   GnomeCanvasRichText *description_item;
00039   GnomeCanvasItem *author_item;
00040   GnomeCanvasItem *boardname_item_s;
00041   GnomeCanvasRichText *description_item_s;
00042   GnomeCanvasItem *author_item_s;
00043 } MenuItems;
00044 
00045 static MenuItems *menuitems;
00046 
00047 static GcomprisBoard *gcomprisBoard = NULL;
00048 static gboolean board_paused = TRUE;
00049 
00050 /* We don't wan't the callback on boards to be accepted until the menu is fully displayed */
00051 static gboolean menu_displayed = FALSE;
00052 
00053 static void           menu_start (GcomprisBoard *agcomprisBoard);
00054 static void           menu_pause (gboolean pause);
00055 static void           menu_end (void);
00056 static gboolean              menu_is_our_board (GcomprisBoard *gcomprisBoard);
00057 static void           menu_config(void);
00058 
00059 static void              menu_config_start(GcomprisBoard *agcomprisBoard,
00060                                       GcomprisProfile *aProfile);
00061 
00062 static void              menu_config_stop(void);
00063 
00064 static void           menu_create_item(GnomeCanvasGroup *parent, MenuItems *menuitems, GcomprisBoard *board);
00065 static gboolean              next_spot();
00066 static void           create_info_area(GnomeCanvasGroup *parent, MenuItems *menuitems);
00067 static gint           item_event(GnomeCanvasItem *item, GdkEvent *event, MenuItems *menuitems);
00068 static void           display_board_icon(GcomprisBoard *board, MenuItems *menuitems);
00069 static void           free_stuff (GtkObject *obj, gpointer data);
00070 static void           set_content(GnomeCanvasRichText *item_content,
00071                                  GnomeCanvasRichText *item_content_s,
00072                                  gchar *text);
00073 
00074 static void              display_section (gchar *path);
00075 static void              display_welcome (void);
00076 static void           create_panel(GnomeCanvasGroup *parent);
00077 static void           create_top(GnomeCanvasGroup *parent, gchar *path);
00078 
00079 static double current_x = 0.0;
00080 static double current_y = 0.0;
00081 
00082 static double current_top_x = 0.0;
00083 static double current_top_y = 0.0;
00084 
00085 static double panel_x, panel_y, panel_w, panel_h;
00086 static double top_x, top_y, top_w, top_h, top_int_x;
00087 static double display_x, display_y, display_w, display_h, display_int_x, display_int_y;
00088 static double info_x, info_y, info_w, info_h;
00089 
00090 static double icon_size, icon_size_panel, icon_size_top, top_arrow_size;
00091 
00092 static gdouble get_ratio(GdkPixbuf *pixmap, gdouble size);
00093 
00094 #define P_X 0
00095 #define P_Y 10
00096 #define P_W 80
00097 #define P_H 480
00098 
00099 #define T_X 175
00100 #define T_Y 10
00101 #define T_W 550
00102 #define T_H 55
00103 #define T_INT_X 5
00104 #define T_ARROW_SIZE 20
00105 
00106 #define D_X 175
00107 #define D_Y 70
00108 #define D_W 550
00109 #define D_H 320
00110 #define D_INT_X 50
00111 #define D_INT_Y 5
00112 
00113 #define I_X 140
00114 #define I_Y 400
00115 #define I_W 600
00116 #define I_H 125
00117 
00118 #define ICON_SIZE 100
00119 #define ICON_SIZE_PANEL 50
00120 #define ICON_SIZE_TOP 50
00121 
00122 static GnomeCanvasGroup *boardRootItem = NULL;
00123 static GnomeCanvasGroup *actualSectionItem = NULL;
00124 static GList *panelBoards = NULL;
00125 
00126 /* Description of this plugin */
00127 static BoardPlugin menu_bp =
00128   {
00129     NULL,
00130     NULL,
00131     N_("Main Menu Second Version"),
00132     N_("Select a Board"),
00133     "Bruno Coudoin <bruno.coudoin@free.fr>",
00134     NULL,
00135     NULL,
00136     NULL,
00137     NULL,
00138     menu_start,
00139     menu_pause,
00140     menu_end,
00141     menu_is_our_board,
00142     NULL,
00143     NULL,
00144     NULL,
00145     menu_config,
00146     NULL,
00147     menu_config_start,
00148     menu_config_stop
00149   };
00150 
00151 /*
00152  * Main entry point mandatory for each Gcompris's board
00153  * ---------------------------------------------------
00154  *
00155  */
00156 
00157 
00158 GET_BPLUGIN_INFO(menu)
00159 
00160 /*
00161  * in : boolean TRUE = PAUSE : FALSE = CONTINUE
00162  *
00163  */
00164 static void menu_pause (gboolean pause)
00165 {
00166 
00167   if(gcomprisBoard==NULL)
00168     return;
00169 
00170   board_paused = pause;
00171 }
00172 
00173 /*
00174  */
00175 static void menu_start (GcomprisBoard *agcomprisBoard)
00176 {
00177 
00178   GcomprisProperties *properties = gc_prop_get();
00179 
00180   current_x = 0.0;
00181   current_y = 0.0;
00182 
00183   /* initialisations */
00184   /* in case we will make this parametrable */
00185 
00186   panel_x = P_X;
00187   panel_y = P_Y;
00188   panel_w = P_W;
00189   panel_h = P_H;
00190 
00191   top_x = T_X;
00192   top_y = T_Y;
00193   top_w = T_W;
00194   top_h = T_H;
00195   top_int_x = T_INT_X;
00196   top_arrow_size = T_ARROW_SIZE;
00197 
00198   display_x = D_X;
00199   display_y = D_Y;
00200   display_w = D_W;
00201   display_h = D_H;
00202   display_int_x = D_INT_X;
00203   display_int_y = D_INT_Y;
00204 
00205   info_x = I_X;
00206   info_y = I_Y;
00207   info_w = I_W;
00208   info_h = I_H;
00209 
00210   icon_size = ICON_SIZE;
00211   icon_size_panel = ICON_SIZE_PANEL;
00212   icon_size_top = ICON_SIZE_TOP;
00213 
00214   g_warning ("menu2 : start  board");
00215 
00216   if(agcomprisBoard!=NULL)
00217     {
00218       gchar *img;
00219 
00220       gcomprisBoard=agcomprisBoard;
00221 
00222       menuitems = g_new(MenuItems, 1);
00223 
00224       img = gc_skin_image_get("gcompris-menu2bg.png");
00225       gc_set_background(gnome_canvas_root(gcomprisBoard->canvas),
00226                            img);
00227       g_free(img);
00228 
00229       boardRootItem = GNOME_CANVAS_GROUP(
00230                                     gnome_canvas_item_new (gnome_canvas_root(gcomprisBoard->canvas),
00231                                                         gnome_canvas_group_get_type (),
00232                                                         "x", (double) 0,
00233                                                         "y", (double) 0,
00234                                                         NULL));
00235 
00236       g_object_set_data (G_OBJECT (boardRootItem), "menuitems", menuitems);
00237       g_signal_connect (boardRootItem, "destroy",
00238                      G_CALLBACK (free_stuff),
00239                      menuitems);
00240 
00241       create_info_area(boardRootItem, menuitems);
00242 
00243       create_panel(boardRootItem);
00244 
00245       if (properties->menu_position){
00246        display_section(properties->menu_position);
00247       }
00248       else
00249        display_welcome();
00250 
00251       /* set initial values for this level */
00252       gcomprisBoard->level = 1;
00253       gcomprisBoard->maxlevel=1;
00254       gc_bar_set(GC_BAR_CONFIG|GC_BAR_ABOUT);
00255 
00256       /* FIXME : Workaround for bugged canvas */
00257       //gnome_canvas_update_now(gcomprisBoard->canvas);
00258 
00259       menu_pause(FALSE);
00260 
00261     }
00262 
00263 }
00264 
00265 
00266 static void create_panel(GnomeCanvasGroup *parent)
00267 {
00268   int n_sections;
00269   GList *list = NULL;
00270   GcomprisBoard *board;
00271   GdkPixbuf *pixmap = NULL;
00272   GnomeCanvasItem *item;
00273   gdouble ratio;
00274 
00275   gdouble x, y;
00276   gint int_y;
00277   GcomprisProperties *properties = gc_prop_get();
00278 
00279   /* In normal mode, we show all the sections in panel */
00280   /* in direct submenu access, we show the icon of the submenu */
00281   if (strcmp(properties->root_menu,"/")==0)
00282     panelBoards = gc_menu_getlist(properties->root_menu);
00283   else
00284     panelBoards = g_list_append(list, gcomprisBoard);
00285 
00286   n_sections = g_list_length(panelBoards);
00287 
00288   if (n_sections == 0)
00289     return;
00290 
00291   if ( (panel_h/n_sections) <= icon_size_panel){
00292     icon_size_panel = panel_h/n_sections;
00293     int_y = 0;
00294   }
00295   else {
00296     int_y = (panel_h - n_sections*icon_size_panel)/n_sections;
00297   }
00298 
00299   x = panel_x + panel_w/2.0;
00300   y = panel_y + int_y/2.0;
00301 
00302   for (list = panelBoards; list != NULL; list = list->next){
00303     board = (GcomprisBoard *) list->data;
00304 
00305     pixmap = gc_pixmap_load(board->icon_name);
00306 
00307     ratio = get_ratio( pixmap, icon_size_panel);
00308 
00309     item = gnome_canvas_item_new (parent,
00310                               gnome_canvas_pixbuf_get_type (),
00311                               "pixbuf", pixmap,
00312                               "x", x,
00313                               "y", y,
00314                               "width", (gdouble)  gdk_pixbuf_get_width(pixmap)*ratio,
00315                               "height", (gdouble) gdk_pixbuf_get_height(pixmap)*ratio,
00316                               "width-set", TRUE,
00317                               "height-set", TRUE,
00318                               "anchor", GTK_ANCHOR_NW,
00319                               NULL);
00320 
00321     gdk_pixbuf_unref(pixmap);
00322 
00323     y += int_y + icon_size_panel;
00324 
00325     g_object_set_data (G_OBJECT (item), "board", board);
00326 
00327     gtk_signal_connect(GTK_OBJECT(item), "event",
00328                      (GtkSignalFunc) item_event,
00329                      menuitems);
00330 
00331     gtk_signal_connect(GTK_OBJECT(item), "event",
00332                      (GtkSignalFunc) gc_item_focus_event,
00333                      NULL);
00334 
00335   }
00336 
00337 
00338 
00339 }
00340 
00341 static void display_section (gchar *path)
00342 {
00343       GList          *boardlist;   /* List of Board */
00344 
00345       menu_displayed = FALSE;
00346 
00347       boardlist = gc_menu_getlist(path);
00348 
00349       if (actualSectionItem)
00350        gtk_object_destroy (GTK_OBJECT(actualSectionItem));
00351 
00352       current_x = 0.0;
00353       current_y = 0.0;
00354       current_top_x = 0.0;
00355       current_top_y = 0.0;
00356 
00357       actualSectionItem = GNOME_CANVAS_GROUP(
00358                                     gnome_canvas_item_new ( boardRootItem,
00359                                                          gnome_canvas_group_get_type (),
00360                                                         "x", (double) 0,
00361                                                         "y", (double) 0,
00362                                                         NULL));
00363 
00364 
00365       create_top (actualSectionItem, path);
00366 
00367       g_list_foreach (boardlist, (GFunc) display_board_icon, menuitems);
00368 
00369       if (strcmp(path,"home")!=0)
00370        g_list_free(boardlist);
00371 
00372       menu_displayed = TRUE;
00373 }
00374 
00375 static void
00376 menu_end ()
00377 {
00378   if(boardRootItem!=NULL)
00379     {
00380       /* WORKAROUND: There is a bug in the richtex item and we need to remove it first */
00381       while (g_idle_remove_by_data (menuitems->description_item));
00382       gtk_object_destroy (GTK_OBJECT(menuitems->description_item));
00383 
00384       while (g_idle_remove_by_data (menuitems->description_item_s));
00385       gtk_object_destroy (GTK_OBJECT(menuitems->description_item_s));
00386 
00387       gtk_object_destroy (GTK_OBJECT(boardRootItem));
00388     }
00389 
00390   boardRootItem     = NULL;
00391   actualSectionItem = NULL;
00392 
00393   g_list_free(panelBoards);
00394 
00395 }
00396 
00397 static gboolean
00398 menu_is_our_board (GcomprisBoard *gcomprisBoard)
00399 {
00400   if (gcomprisBoard)
00401     {
00402       if(g_strcasecmp(gcomprisBoard->type, "menu")==0)
00403        {
00404          /* Set the plugin entry */
00405          gcomprisBoard->plugin=&menu_bp;
00406 
00407          return TRUE;
00408        }
00409     }
00410   return FALSE;
00411 }
00412 
00413 static void
00414 menu_config ()
00415 {
00416   if(gcomprisBoard!=NULL)
00417     {
00418       menu_pause(TRUE);
00419       gc_config_start();
00420     }
00421 }
00422 
00423 
00424 
00425 /*-------------------------------------------------------------------------------*/
00426 /*-------------------------------------------------------------------------------*/
00427 /*-------------------------------------------------------------------------------*/
00428 /*-------------------------------------------------------------------------------*/
00429 
00430 static void display_board_icon(GcomprisBoard *board, MenuItems *menuitems)
00431 {
00432   /* FIXME: Check board is available for the current profile */
00433   if (board!=NULL
00434       && gc_board_check_file(board))
00435     {
00436       menu_create_item(actualSectionItem, menuitems, board);
00437     }
00438 }
00439 
00440 /*
00441  * Calculate the next stop where to place an item
00442  * return false if there is no more space left
00443  */
00444 static gboolean next_spot()
00445 {
00446   if(current_x==0.0)
00447     {
00448       /* Initialisation case */
00449       current_x = display_x + icon_size/2.0;
00450        current_y = display_y + icon_size/2.0;
00451       return(TRUE);
00452     }
00453 
00454   current_x += icon_size + display_int_x;
00455 
00456   if(current_x > display_x + display_w - icon_size/2.0)
00457     {
00458       current_x =  display_x + icon_size/2.0;
00459       current_y += icon_size + display_int_y;
00460     }
00461 
00462   if ( current_y > display_y + display_h - icon_size/2.0 )
00463     return FALSE;
00464   else
00465     return TRUE;
00466 
00467 }
00468 
00469 static void menu_create_item(GnomeCanvasGroup *parent, MenuItems *menuitems, GcomprisBoard *board)
00470 {
00471   GdkPixbuf *menu_pixmap = NULL;
00472   GdkPixbuf *pixmap = NULL;
00473   GnomeCanvasItem *item, *menu_button;
00474   int difficulty;
00475   gchar *tmp_board_dir;
00476   gdouble ratio, pixmap_w, pixmap_h;
00477 
00478   /*
00479    * Take care to load the board->icon_name from the dir specified
00480    * in the board->board_dir
00481    * To make it simple and reuse the gc_pixmap_load, we overwrite temporarily
00482    * the gcomprisBoard->board_dir and board->board_dir
00483    */
00484   tmp_board_dir = gcomprisBoard->board_dir;
00485   gcomprisBoard->board_dir = board->board_dir;
00486   menu_pixmap = gc_pixmap_load(board->icon_name);
00487   gcomprisBoard->board_dir = tmp_board_dir;
00488 
00489   ratio = get_ratio (menu_pixmap, icon_size);
00490 
00491   if (ratio < 1.0)
00492     g_warning("Resize %s", board->icon_name);
00493 
00494   pixmap_w = gdk_pixbuf_get_width(menu_pixmap)*ratio;
00495   pixmap_h = gdk_pixbuf_get_height(menu_pixmap)*ratio;
00496 
00497   next_spot();
00498 
00499   menu_button = gnome_canvas_item_new (parent,
00500                                    gnome_canvas_pixbuf_get_type (),
00501                                    "pixbuf", menu_pixmap,
00502                                    "x", (double)current_x - pixmap_w/2,
00503                                    "y", (double)current_y - pixmap_h/2,
00504                                    "width", (gdouble) pixmap_w,
00505                                    "height", (gdouble) pixmap_h,
00506                                    "width-set", TRUE,
00507                                    "height-set", TRUE,
00508                                    NULL);
00509 
00510   // display difficulty stars
00511   if (board->difficulty != NULL) {
00512     difficulty = atoi(board->difficulty);
00513     gc_difficulty_display(parent,
00514                                   (double)current_x - pixmap_w/2 - 25,
00515                                   (double)current_y - pixmap_h/2,
00516                                   (double) 0.6,
00517                                   difficulty);
00518   }
00519 
00520   // display board availability due to sound voice not present
00521   if(board->mandatory_sound_file)
00522     {
00523       gchar *soundfile = NULL;
00524 
00525       /* We search a fixed path sound file */
00526       soundfile = gc_file_find_absolute(board->mandatory_sound_file);
00527       g_warning("Checking mandatory_sound_file %s\n", soundfile);
00528 
00529       if (!soundfile || !gc_prop_get()->fx)
00530        {
00531          pixmap = gc_skin_pixmap_load("voice_bad.png");
00532        }
00533       else
00534        {
00535          pixmap = gc_skin_pixmap_load("voice.png");
00536        }
00537 
00538       gnome_canvas_item_new (parent,
00539                           gnome_canvas_pixbuf_get_type (),
00540                           "pixbuf", pixmap,
00541                           "x", (double)current_x - pixmap_w/2 - 25,
00542                           "y", (double)current_y - pixmap_h/2 + 28,
00543                           NULL);
00544       gdk_pixbuf_unref(pixmap);
00545       g_free(soundfile);
00546     }
00547 
00548   // display menu icon ========================== BEGIN
00549   if(g_strcasecmp(board->type, "menu")==0)
00550     {
00551       pixmap = gc_skin_pixmap_load("menuicon.png");
00552       item =  gnome_canvas_item_new (parent,
00553                                  gnome_canvas_pixbuf_get_type (),
00554                                  "pixbuf", pixmap,
00555                                  "x", (double)current_x - pixmap_w/2 - 25,
00556                                  "y", (double)current_y - pixmap_h/2,
00557                                  NULL);
00558       gdk_pixbuf_unref(pixmap);
00559     }
00560 
00561   gdk_pixbuf_unref(menu_pixmap);
00562 
00563   // display menu icon ========================== END
00564 
00565   /*
00566    * Now everything ready, map the events
00567    * -------------------------------------
00568    */
00569   g_object_set_data (G_OBJECT (menu_button), "board", board);
00570 
00571   gtk_signal_connect(GTK_OBJECT(menu_button), "event",
00572                    (GtkSignalFunc) item_event,
00573                    menuitems);
00574 
00575   gtk_signal_connect(GTK_OBJECT(menu_button), "event",
00576                    (GtkSignalFunc) gc_item_focus_event,
00577                    NULL);
00578 
00579 }
00580 
00581 static gint
00582 item_event(GnomeCanvasItem *item, GdkEvent *event,  MenuItems *menuitems)
00583 {
00584   GcomprisBoard *board;
00585 
00586   if(board_paused)
00587     return FALSE;
00588 
00589   if(boardRootItem    == NULL)
00590     return FALSE;
00591 
00592   board = g_object_get_data (G_OBJECT (item), "board");
00593 
00594   switch (event->type)
00595     {
00596     case GDK_ENTER_NOTIFY:
00597       if(board->title && G_IS_OBJECT(menuitems->boardname_item))
00598        gnome_canvas_item_set (menuitems->boardname_item,
00599                             "text", board->title,
00600                             NULL);
00601 
00602       if(board->description
00603         && G_IS_OBJECT(menuitems->description_item)
00604         && G_IS_OBJECT(menuitems->description_item_s))
00605        set_content(menuitems->description_item,
00606                   menuitems->description_item_s,
00607                   board->description);
00608 
00609       if(board->author && G_IS_OBJECT(menuitems->author_item))
00610        gnome_canvas_item_set (menuitems->author_item,
00611                             "text",  board->author,
00612                             NULL);
00613 
00614       if(board->title && G_IS_OBJECT(menuitems->boardname_item_s))
00615        gnome_canvas_item_set (menuitems->boardname_item_s,
00616                             "text", board->title,
00617                             NULL);
00618 
00619       if(board->author && G_IS_OBJECT(menuitems->author_item_s))
00620        gnome_canvas_item_set (menuitems->author_item_s,
00621                             "text",  board->author,
00622                             NULL);
00623 
00624       break;
00625     case GDK_LEAVE_NOTIFY:
00626       gnome_canvas_item_set (menuitems->boardname_item,
00627                           "text", " ",
00628                           NULL);
00629 
00630       gnome_canvas_item_set (GNOME_CANVAS_ITEM(menuitems->description_item),
00631                           "text",  " ",
00632                           NULL);
00633 
00634       gnome_canvas_item_set (menuitems->author_item,
00635                           "text",  " ",
00636                           NULL);
00637 
00638       gnome_canvas_item_set (menuitems->boardname_item_s,
00639                           "text", " ",
00640                           NULL);
00641 
00642       gnome_canvas_item_set (GNOME_CANVAS_ITEM(menuitems->description_item_s),
00643                           "text",  " ",
00644                           NULL);
00645 
00646       gnome_canvas_item_set (menuitems->author_item_s,
00647                           "text",  " ",
00648                           NULL);
00649 
00650       break;
00651     case GDK_BUTTON_PRESS:
00652       if(!menu_displayed)
00653        return TRUE;
00654 
00655       gc_sound_play_ogg ("sounds/gobble.ogg", NULL);
00656 
00657       if (strcmp(board->type,"menu")==0){
00658        gchar *path = g_strdup_printf("%s/%s",board->section, board->name);
00659        GcomprisProperties   *properties = gc_prop_get();
00660 
00661        display_section(path);
00662 
00663        if (properties->menu_position)
00664          g_free(properties->menu_position);
00665 
00666        properties->menu_position = path;
00667 
00668       }
00669       else
00670        gc_board_run_next (board);
00671 
00672       break;
00673 
00674     default:
00675       break;
00676     }
00677 
00678   return FALSE;
00679 }
00680 
00681 /* Apply the style to the given RichText item  */
00682 static void
00683 set_content(GnomeCanvasRichText *item_content,
00684            GnomeCanvasRichText *item_content_s,
00685            gchar *text) {
00686 
00687   GtkTextIter    iter_start, iter_end;
00688   GtkTextBuffer *buffer;
00689   GtkTextTag    *txt_tag;
00690   gboolean success;
00691   gchar *color_string;
00692   GdkColor *color_s = (GdkColor *)malloc(sizeof(GdkColor));
00693   GdkColor *color   = (GdkColor *)malloc(sizeof(GdkColor));
00694 
00695   /*
00696    * Set the new text in the 2 items
00697    */
00698   gnome_canvas_item_set(GNOME_CANVAS_ITEM(item_content),
00699                      "text", text,
00700                      NULL);
00701 
00702   gnome_canvas_item_set(GNOME_CANVAS_ITEM(item_content_s),
00703                      "text", text,
00704                      NULL);
00705 
00706   /*
00707    * Set the shadow
00708    */
00709 
00710   color_string = g_strdup_printf("#%x", gc_skin_color_shadow >> 8);
00711   gdk_color_parse(color_string, color_s);
00712   g_free(color_string);
00713   success = gdk_colormap_alloc_color(gdk_colormap_get_system(),
00714                                  color_s,
00715                                  FALSE, TRUE);
00716 
00717   buffer  = gnome_canvas_rich_text_get_buffer(GNOME_CANVAS_RICH_TEXT(item_content_s));
00718   txt_tag = gtk_text_buffer_create_tag(buffer, NULL,
00719                                    "foreground-gdk", color_s,
00720                                    "font",       gc_skin_font_board_medium,
00721                                    NULL);
00722   gtk_text_buffer_get_end_iter(buffer, &iter_end);
00723   gtk_text_buffer_get_start_iter(buffer, &iter_start);
00724   gtk_text_buffer_apply_tag(buffer, txt_tag, &iter_start, &iter_end);
00725 
00726   /*
00727    * Set the text
00728    */
00729   color_string = g_strdup_printf("#%x", gc_skin_get_color("menu/text") >> 8);
00730   gdk_color_parse(color_string, color);
00731   g_free(color_string);
00732   success = gdk_colormap_alloc_color(gdk_colormap_get_system(),
00733                                  color,
00734                                  FALSE, TRUE);
00735 
00736   buffer  = gnome_canvas_rich_text_get_buffer(GNOME_CANVAS_RICH_TEXT(item_content));
00737   txt_tag = gtk_text_buffer_create_tag(buffer, NULL,
00738                                    "foreground-gdk", color,
00739                                    "font",        gc_skin_font_board_medium,
00740                                    NULL);
00741   gtk_text_buffer_get_end_iter(buffer, &iter_end);
00742   gtk_text_buffer_get_start_iter(buffer, &iter_start);
00743   gtk_text_buffer_apply_tag(buffer, txt_tag, &iter_start, &iter_end);
00744   g_free(color);
00745   g_free(color_s);
00746 }
00747 
00751 static void create_info_area(GnomeCanvasGroup *parent, MenuItems *menuitems)
00752 {
00753   gint x = (double) info_x + info_w/2.0;
00754   gint y = info_y;
00755 
00756   if(parent    == NULL)
00757     return;
00758 
00759   menuitems->boardname_item_s = \
00760     gnome_canvas_item_new (parent,
00761                         gnome_canvas_text_get_type (),
00762                         "text", " ",
00763                         "font", gc_skin_font_board_big,
00764                         "x", (double) x + 1.0,
00765                         "y", (double) y + 1.0,
00766                         "anchor", GTK_ANCHOR_NORTH,
00767                         "fill_color_rgba",  gc_skin_color_shadow,
00768                         NULL);
00769 
00770   menuitems->boardname_item = \
00771     gnome_canvas_item_new (parent,
00772                         gnome_canvas_text_get_type (),
00773                         "text", " ",
00774                         "font", gc_skin_font_board_big,
00775                         "x", (double) x,
00776                         "y", (double) y,
00777                         "anchor", GTK_ANCHOR_NORTH,
00778                         "fill_color_rgba",  gc_skin_get_color("menu/text"),
00779                         NULL);
00780 
00781   menuitems->description_item_s = \
00782     GNOME_CANVAS_RICH_TEXT(gnome_canvas_item_new (parent,
00783                                             gnome_canvas_rich_text_get_type (),
00784                                             "x", (double) x + 1.0,
00785                                             "y", (double) y + 28 + 1.0,
00786                                             "width",  info_w,
00787                                             "height", info_h - 28,
00788                                             "anchor", GTK_ANCHOR_NORTH,
00789                                             "justification", GTK_JUSTIFY_CENTER,
00790                                             "grow_height", FALSE,
00791                                             "cursor_visible", FALSE,
00792                                             "cursor_blink", FALSE,
00793                                             "editable", FALSE,
00794                                             NULL));
00795   menuitems->description_item = \
00796     GNOME_CANVAS_RICH_TEXT(gnome_canvas_item_new (parent,
00797                                             gnome_canvas_rich_text_get_type (),
00798                                             "x", (double) x,
00799                                             "y", (double) y + 28,
00800                                             "width",  info_w,
00801                                             "height", info_h - 28,
00802                                             "anchor", GTK_ANCHOR_NORTH,
00803                                             "justification", GTK_JUSTIFY_CENTER,
00804                                             "grow_height", FALSE,
00805                                             "cursor_visible", FALSE,
00806                                             "cursor_blink", FALSE,
00807                                             "editable", FALSE,
00808                                             NULL));
00809 
00810   menuitems->author_item_s = \
00811     gnome_canvas_item_new (parent,
00812                         gnome_canvas_text_get_type (),
00813                         "text", " ",
00814                         "font", gc_skin_font_board_tiny,
00815                         "x", (double) x + 1.0,
00816                         "y", (double) y + 90 + 1.0,
00817                         "anchor", GTK_ANCHOR_NORTH,
00818                         "fill_color_rgba", gc_skin_color_shadow,
00819                         "justification", GTK_JUSTIFY_CENTER,
00820                         NULL);
00821 
00822   menuitems->author_item = \
00823     gnome_canvas_item_new (parent,
00824                         gnome_canvas_text_get_type (),
00825                         "text", " ",
00826                         "font", gc_skin_font_board_tiny,
00827                         "x", (double) x,
00828                         "y", (double) y + 90,
00829                         "anchor", GTK_ANCHOR_NORTH,
00830                         "fill_color_rgba", gc_skin_get_color("menu/text"),
00831                         "justification", GTK_JUSTIFY_CENTER,
00832                         NULL);
00833 
00834 }
00835 
00836 static void
00837 free_stuff (GtkObject *obj, gpointer data)
00838 {
00839   g_free (data);
00840 }
00841 
00842 
00843 static gdouble get_ratio(GdkPixbuf *pixmap, gdouble size)
00844 {
00845 
00846   gdouble ratio = 1.0;
00847   gint pixmap_h, pixmap_w;
00848 
00849   pixmap_w = gdk_pixbuf_get_width(pixmap);
00850   pixmap_h = gdk_pixbuf_get_height(pixmap);
00851 
00852   if (pixmap_h <= pixmap_w){
00853     if (pixmap_w > size)
00854        ratio = size / pixmap_w;
00855     }
00856     else {
00857       if (pixmap_h > size)
00858        ratio = size / pixmap_h;
00859     }
00860 
00861   return ratio;
00862 
00863 }
00864 
00865 static void create_top(GnomeCanvasGroup *parent, gchar *path)
00866 {
00867   gchar **splitted_section;
00868   gint i = 1;
00869   GdkPixbuf *pixmap = NULL;
00870   gdouble ratio;
00871   GcomprisBoard *board;
00872   gchar *path1, *path2;
00873 
00874   GnomeCanvasItem *item;
00875 
00876   GcomprisProperties *properties = gc_prop_get();
00877 
00878   if (!path)
00879     return;
00880 
00881   splitted_section = g_strsplit (path, "/", 0);
00882 
00883   path1 = g_strdup("");
00884 
00885   /* splitted_section[0] is always "" */
00886   i = 1;
00887 
00888   while (splitted_section[i] != NULL)
00889     {
00890 
00891       path2 = g_strdup_printf("%s/%s", path1, splitted_section[i]);
00892 
00893       g_free(path1);
00894       path1 = path2;
00895 
00896       if (strcmp(path1, properties->root_menu)<0){
00897        i++;
00898        continue;
00899       }
00900 
00901       if (current_top_x == 0.0){
00902        current_top_x = top_x;
00903        current_top_y = top_y + top_h/2.0;
00904       } else {
00905        pixmap = gc_skin_pixmap_load("button_forward.png");
00906        ratio = get_ratio(pixmap, top_arrow_size);
00907 
00908        gnome_canvas_item_new (parent,
00909                             gnome_canvas_pixbuf_get_type (),
00910                             "pixbuf", pixmap,
00911                             "x", current_top_x,
00912                             "y", current_top_y,
00913                             "width", (gdouble)  gdk_pixbuf_get_width(pixmap)*ratio,
00914                             "height", (gdouble) gdk_pixbuf_get_height(pixmap)*ratio,
00915                             "width-set", TRUE,
00916                             "height-set", TRUE,
00917                             "anchor", GTK_ANCHOR_WEST,
00918                             NULL);
00919 
00920        gdk_pixbuf_unref(pixmap);
00921 
00922        current_top_x += top_arrow_size + top_int_x;
00923 
00924       }
00925 
00926       board = gc_menu_section_get(path1);
00927 
00928       pixmap = gc_pixmap_load(board->icon_name);
00929 
00930       ratio = get_ratio( pixmap, icon_size_top);
00931 
00932       item = gnome_canvas_item_new (parent,
00933                                 gnome_canvas_pixbuf_get_type (),
00934                                 "pixbuf", pixmap,
00935                                 "x", current_top_x,
00936                                 "y", current_top_y,
00937                                 "width", (gdouble)  gdk_pixbuf_get_width(pixmap)*ratio,
00938                                 "height", (gdouble) gdk_pixbuf_get_height(pixmap)*ratio,
00939                                 "width-set", TRUE,
00940                                 "height-set", TRUE,
00941                                 "anchor", GTK_ANCHOR_WEST,
00942                                 NULL);
00943 
00944       gdk_pixbuf_unref(pixmap);
00945 
00946       current_top_x += top_int_x + icon_size_top;
00947 
00948       g_object_set_data (G_OBJECT (item), "board", board);
00949 
00950       gtk_signal_connect(GTK_OBJECT(item), "event",
00951                       (GtkSignalFunc) item_event,
00952                       menuitems);
00953 
00954       gtk_signal_connect(GTK_OBJECT(item), "event",
00955                       (GtkSignalFunc) gc_item_focus_event,
00956                       NULL);
00957 
00958 
00959 
00960       i++;
00961     }
00962 
00963   g_strfreev(splitted_section);
00964   g_free(path1);
00965 
00966 }
00967 
00968 static void
00969 display_welcome (void)
00970 {
00971   GnomeCanvasItem *logo;
00972   GdkPixbuf *pixmap;
00973 
00974   if (actualSectionItem)
00975     {
00976       g_error("actualSectionItem exists in display_section !");
00977     }
00978 
00979 
00980   actualSectionItem = GNOME_CANVAS_GROUP(
00981                                     gnome_canvas_item_new ( boardRootItem,
00982                                                          gnome_canvas_group_get_type (),
00983                                                          "x", (double) 0,
00984                                                          "y", (double) 0,
00985                                                          NULL));
00986 
00987   pixmap = gc_skin_pixmap_load("gcompris-about.png");
00988 
00989 
00990   logo = gnome_canvas_item_new (actualSectionItem,
00991                             gnome_canvas_pixbuf_get_type (),
00992                             "pixbuf", pixmap,
00993                             "x", (gdouble) display_x + display_w/2.0,
00994                             "y", (gdouble) display_y + display_h/2.0,
00995                             "anchor", GTK_ANCHOR_CENTER,
00996                             NULL);
00997 
00998   gdk_pixbuf_unref(pixmap);
00999 
01000   if(G_IS_OBJECT(menuitems->boardname_item))
01001     gnome_canvas_item_set (menuitems->boardname_item,
01002                         "text", "GCompris V" VERSION,
01003                         NULL);
01004 
01005   if(G_IS_OBJECT(menuitems->description_item)
01006      && G_IS_OBJECT(menuitems->description_item_s))
01007     set_content(menuitems->description_item,
01008               menuitems->description_item_s,
01009               _("GCompris is a collection of educational games that provides different activities for children aged 2 and up."));
01010 
01011   if(G_IS_OBJECT(menuitems->author_item))
01012     gnome_canvas_item_set (menuitems->author_item,
01013                         "text", "",
01014                         NULL);
01015   if(G_IS_OBJECT(menuitems->boardname_item_s))
01016     gnome_canvas_item_set (menuitems->boardname_item_s,
01017                             "text", "GCompris V" VERSION,
01018                         NULL);
01019 
01020   if(G_IS_OBJECT(menuitems->author_item_s))
01021     gnome_canvas_item_set (menuitems->author_item_s,
01022                         "text", "",
01023                         NULL);
01024 
01025   menu_displayed = TRUE;
01026 }
01027 
01028 static void
01029 menu_config_start(GcomprisBoard *agcomprisBoard,
01030             GcomprisProfile *aProfile){
01031   if(gcomprisBoard!=NULL)
01032     {
01033       menu_pause(TRUE);
01034       gc_config_start();
01035     }
01036 }
01037 
01038 /* ======================= */
01039 /* = config_stop        = */
01040 /* ======================= */
01041 static void
01042 menu_config_stop()
01043 {
01044 }