3
* Time-stamp: <2004/09/29 00:16:53 bcoudoin>
5
* Copyright (C) 2000 Bruno Coudoin
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
* The menu display icons of each boards and let the user select one
25
* Seen from gcompris, the menu is a board like another.
29
#include <libxml/tree.h>
30
#include <libxml/parser.h>
32
#include "gcompris/gcompris.h"
33
#include "gcompris/gcompris_config.h"
35
#define SOUNDLISTFILE PACKAGE
36
#define MENU_PER_LINE 5
39
/* Information items */
40
GnomeCanvasItem *boardname_item;
41
GnomeCanvasItem *description_item;
42
GnomeCanvasItem *author_item;
45
static GcomprisBoard *gcomprisBoard = NULL;
46
static gboolean board_paused = TRUE;
48
static void menu_start (GcomprisBoard *agcomprisBoard);
49
static void menu_pause (gboolean pause);
50
static void menu_end (void);
51
static gboolean menu_is_our_board (GcomprisBoard *gcomprisBoard);
52
static void menu_config(void);
54
static void menu_create_item(GnomeCanvasGroup *parent, MenuItems *menuitems, GcomprisBoard *board);
55
static gboolean next_spot();
56
static void create_info_area(GnomeCanvasGroup *parent, MenuItems *menuitems);
57
static gint item_event(GnomeCanvasItem *item, GdkEvent *event, MenuItems *menuitems);
58
static void display_board_icon(GcomprisBoard *board, MenuItems *menuitems);
59
static gboolean read_xml_file(char *fname);
60
static void free_stuff (GtkObject *obj, gpointer data);
62
static double current_x = 0.0;
63
static double current_y = 0.0;
65
static GnomeCanvasGroup *boardRootItem = NULL;
67
/* Description of this plugin */
68
static BoardPlugin menu_bp =
74
"Bruno Coudoin <bruno.coudoin@free.fr>",
91
* Main entry point mandatory for each Gcompris's board
92
* ---------------------------------------------------
98
*get_bplugin_info(void)
104
* in : boolean TRUE = PAUSE : FALSE = CONTINUE
107
static void menu_pause (gboolean pause)
110
if(gcomprisBoard==NULL)
113
board_paused = pause;
118
static void menu_start (GcomprisBoard *agcomprisBoard)
124
if(agcomprisBoard!=NULL)
126
MenuItems *menuitems;
127
GList *boardlist; /* List of Board */
129
gcomprisBoard=agcomprisBoard;
130
menuitems = g_new(MenuItems, 1);
132
gcompris_set_background(gnome_canvas_root(gcomprisBoard->canvas),
133
gcompris_image_to_skin("gcompris-init.jpg"));
136
boardRootItem = GNOME_CANVAS_GROUP(
137
gnome_canvas_item_new (gnome_canvas_root(gcomprisBoard->canvas),
138
gnome_canvas_group_get_type (),
143
g_object_set_data (G_OBJECT (boardRootItem), "menuitems", menuitems);
144
g_signal_connect (boardRootItem, "destroy",
145
G_CALLBACK (free_stuff),
148
boardlist = gcompris_get_menulist(gcomprisBoard->section);
150
create_info_area(boardRootItem, menuitems);
152
g_list_foreach (boardlist, (GFunc) display_board_icon, menuitems);
154
g_list_free(boardlist);
156
/* set initial values for this level */
157
gcomprisBoard->level = 1;
158
gcomprisBoard->maxlevel=1;
159
gcompris_bar_set(GCOMPRIS_BAR_CONFIG|GCOMPRIS_BAR_ABOUT);
161
/* FIXME : Workaround for bugged canvas */
162
gnome_canvas_update_now(gcomprisBoard->canvas);
173
if(boardRootItem!=NULL)
174
gtk_object_destroy (GTK_OBJECT(boardRootItem));
180
menu_is_our_board (GcomprisBoard *gcomprisBoard)
184
if(g_strcasecmp(gcomprisBoard->type, "menu")==0)
186
/* Set the plugin entry */
187
gcomprisBoard->plugin=&menu_bp;
198
if(gcomprisBoard!=NULL)
201
gcompris_config_start();
207
/*-------------------------------------------------------------------------------*/
208
/*-------------------------------------------------------------------------------*/
209
/*-------------------------------------------------------------------------------*/
210
/*-------------------------------------------------------------------------------*/
212
static void display_board_icon(GcomprisBoard *board, MenuItems *menuitems)
215
GcomprisProperties *properties = gcompris_get_properties();
217
difficulty = atoi(board->difficulty);
220
&& gcompris_properties_get_board_status(board->name)
221
&& board_check_file(board))
223
/* Always display menu items or we risk to have unaccessible boards */
224
if(g_strcasecmp(board->type, "menu")==0) {
225
menu_create_item(boardRootItem, menuitems, board);
227
/* Implements the level filtering system */
228
switch (properties->filter_style) {
229
case GCOMPRIS_FILTER_NONE:
230
if(difficulty>0) /* Skip in development boards */
231
menu_create_item(boardRootItem, menuitems, board);
233
case GCOMPRIS_FILTER_EQUAL:
234
if(properties->difficulty_filter==difficulty)
235
menu_create_item(boardRootItem, menuitems, board);
237
case GCOMPRIS_FILTER_UNDER:
238
if(difficulty<=properties->difficulty_filter && difficulty>0)
239
menu_create_item(boardRootItem, menuitems, board);
241
case GCOMPRIS_FILTER_ABOVE:
242
if(difficulty>=properties->difficulty_filter)
243
menu_create_item(boardRootItem, menuitems, board);
246
/* Hum, should not happen, let's display the board anyway */
254
* Calculate the next stop where to place an item
255
* return false if there is no more space left
257
static gboolean next_spot()
261
/* Initialisation case */
262
current_x = gcomprisBoard->width/MENU_PER_LINE;
263
current_y = gcomprisBoard->height/MENU_PER_LINE - 40;
267
current_x += gcomprisBoard->width/MENU_PER_LINE;
268
if(current_x>=gcomprisBoard->width-100)
270
current_x = gcomprisBoard->width/MENU_PER_LINE;
277
static void menu_create_item(GnomeCanvasGroup *parent, MenuItems *menuitems, GcomprisBoard *board)
279
GdkPixbuf *menu_pixmap = NULL;
280
GdkPixbuf *pixmap = NULL;
281
GnomeCanvasItem *item, *menu_button;
284
menu_pixmap = gcompris_load_pixmap(board->icon_name);
287
menu_button = gnome_canvas_item_new (parent,
288
gnome_canvas_pixbuf_get_type (),
289
"pixbuf", menu_pixmap,
290
"x", (double)current_x - gdk_pixbuf_get_width(menu_pixmap)/2,
291
"y", (double)current_y - gdk_pixbuf_get_height(menu_pixmap)/2,
294
// display difficulty stars
295
if (board->difficulty != NULL) {
296
difficulty = atoi(board->difficulty);
297
gcompris_display_difficulty_stars(parent,
298
(double)current_x - gdk_pixbuf_get_width(menu_pixmap)/2 - 25,
299
(double)current_y - gdk_pixbuf_get_height(menu_pixmap)/2,
304
// display board availability due to sound voice not present
305
if(board->mandatory_sound_file)
307
gchar *soundfile = NULL;
309
if(board->mandatory_sound_dataset) {
310
/* We have to search for an assetml sound */
311
soundfile = gcompris_get_asset_file(board->mandatory_sound_dataset, NULL, NULL,
312
board->mandatory_sound_file);
314
/* We search a fixed path sound file */
315
soundfile = g_strdup_printf("%s/%s", PACKAGE_DATA_DIR "/sounds",
316
board->mandatory_sound_file);
317
g_warning("Checking mandatory_sound_file %s\n", soundfile);
320
if (!g_file_test (soundfile, G_FILE_TEST_EXISTS) || !gcompris_get_properties()->audio_works)
322
pixmap = gcompris_load_skin_pixmap("voice_bad.png");
326
pixmap = gcompris_load_skin_pixmap("voice.png");
329
gnome_canvas_item_new (parent,
330
gnome_canvas_pixbuf_get_type (),
332
"x", (double)current_x - gdk_pixbuf_get_width(menu_pixmap)/2 - 25,
333
"y", (double)current_y - gdk_pixbuf_get_height(menu_pixmap)/2 + 28,
335
gdk_pixbuf_unref(pixmap);
339
// display menu icon ========================== BEGIN
340
if(g_strcasecmp(board->type, "menu")==0)
342
pixmap = gcompris_load_skin_pixmap("menuicon.png");
343
item = gnome_canvas_item_new (parent,
344
gnome_canvas_pixbuf_get_type (),
346
"x", (double)current_x - gdk_pixbuf_get_width(menu_pixmap)/2 - 25,
347
"y", (double)current_y - gdk_pixbuf_get_height(menu_pixmap)/2,
349
gdk_pixbuf_unref(pixmap);
352
gdk_pixbuf_unref(menu_pixmap);
354
// display menu icon ========================== END
357
* Now everything ready, map the events
358
* -------------------------------------
360
g_object_set_data (G_OBJECT (menu_button), "board", board);
361
gtk_signal_connect(GTK_OBJECT(menu_button), "event",
362
(GtkSignalFunc) item_event,
365
gtk_signal_connect(GTK_OBJECT(menu_button), "event",
366
(GtkSignalFunc) gcompris_item_event_focus,
373
item_event(GnomeCanvasItem *item, GdkEvent *event, MenuItems *menuitems)
375
GtkTextIter iter_start, iter_end;
376
GtkTextBuffer *buffer;
378
GcomprisBoard *board;
383
if(boardRootItem == NULL)
386
board = g_object_get_data (G_OBJECT (item), "board");
390
case GDK_ENTER_NOTIFY:
391
if(board->title && G_IS_OBJECT(menuitems->boardname_item))
392
gnome_canvas_item_set (menuitems->boardname_item,
393
"text", board->title,
396
if(board->description && G_IS_OBJECT(menuitems->description_item))
397
gnome_canvas_item_set (menuitems->description_item,
398
"text", board->description,
401
if(board->author && G_IS_OBJECT(menuitems->author_item))
402
gnome_canvas_item_set (menuitems->author_item,
403
"text", board->author,
407
case GDK_LEAVE_NOTIFY:
408
gnome_canvas_item_set (menuitems->boardname_item,
412
gnome_canvas_item_set (menuitems->description_item,
416
gnome_canvas_item_set (menuitems->author_item,
421
case GDK_BUTTON_PRESS:
423
/* Back Reference the current board in the next one */
424
board->previous_board = gcomprisBoard;
426
gcompris_play_ogg ("gobble", NULL);
431
/* Start the user's one */
443
static void create_info_area(GnomeCanvasGroup *parent, MenuItems *menuitems)
445
gint x = (double)gcomprisBoard->width/2;
451
menuitems->boardname_item = \
452
gnome_canvas_item_new (parent,
453
gnome_canvas_text_get_type (),
455
"font", gcompris_skin_font_board_big,
458
"anchor", GTK_ANCHOR_NORTH,
459
"fill_color", "white",
462
menuitems->description_item = \
463
gnome_canvas_item_new (parent,
464
gnome_canvas_text_get_type (),
466
"font", gcompris_skin_font_board_medium,
468
"y", (double) y + 28,
469
"anchor", GTK_ANCHOR_NORTH,
470
"fill_color", "white",
473
menuitems->author_item = \
474
gnome_canvas_item_new (parent,
475
gnome_canvas_text_get_type (),
477
"font", gcompris_skin_font_board_tiny,
479
"y", (double) y + 90,
480
"anchor", GTK_ANCHOR_NORTH,
481
"fill_color", "white",
482
"justification", GTK_JUSTIFY_CENTER,
488
free_stuff (GtkObject *obj, gpointer data)
495
/* Local Variables: */
497
/* eval:(load-library "time-stamp") */
498
/* eval:(make-local-variable 'write-file-hooks) */
499
/* eval:(add-hook 'write-file-hooks 'time-stamp) */
500
/* eval:(setq time-stamp-format '(time-stamp-yyyy/mm/dd time-stamp-hh:mm:ss user-login-name)) */