~ubuntu-branches/ubuntu/trusty/gcompris/trusty

« back to all changes in this revision

Viewing changes to src/boards/menu.c

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2006-12-15 23:08:17 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061215230817-exr5ks1hd73s3tlk
Tags: 8.2.2-1
* New upstream bugfix release, fixes among other things the support for
  the version of gnucap shipped in etch.
* Add missing dependency on python-gtk2 (Closes: #396523).
* Removed reference to non-existent sound file from memory.c (upstream
  fix - impacts 8.2 as well).  
* Now suggests gnuchess, gnucap, and tuxpaint.
* Updated extended description for the main package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* gcompris - menu.c
2
 
 *
3
 
 * Time-stamp: <2004/09/29 00:16:53 bcoudoin>
4
 
 *
5
 
 * Copyright (C) 2000 Bruno Coudoin
6
 
 *
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.
11
 
 *
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.
16
 
 *
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
20
 
 */
21
 
 
22
 
/**
23
 
 * The menu display icons of each boards and let the user select one
24
 
 *
25
 
 * Seen from gcompris, the menu is a board like another.
26
 
 */
27
 
 
28
 
/* libxml includes */
29
 
#include <libxml/tree.h>
30
 
#include <libxml/parser.h>
31
 
 
32
 
#include "gcompris/gcompris.h"
33
 
#include "gcompris/gcompris_config.h"
34
 
 
35
 
#define SOUNDLISTFILE PACKAGE
36
 
#define MENU_PER_LINE 5
37
 
 
38
 
typedef struct {
39
 
  /* Information items */
40
 
  GnomeCanvasItem *boardname_item;
41
 
  GnomeCanvasItem *description_item;
42
 
  GnomeCanvasItem *author_item;
43
 
} MenuItems;
44
 
 
45
 
static GcomprisBoard *gcomprisBoard = NULL;
46
 
static gboolean board_paused = TRUE;
47
 
 
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);
53
 
 
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);
61
 
 
62
 
static double current_x = 0.0;
63
 
static double current_y = 0.0;
64
 
 
65
 
static GnomeCanvasGroup *boardRootItem = NULL;
66
 
 
67
 
/* Description of this plugin */
68
 
static BoardPlugin menu_bp =
69
 
  {
70
 
    NULL,
71
 
    NULL,
72
 
    N_("Main Menu"),
73
 
    N_("Select a Board"),
74
 
    "Bruno Coudoin <bruno.coudoin@free.fr>",
75
 
    NULL,
76
 
    NULL,
77
 
    NULL,
78
 
    NULL,
79
 
    menu_start,
80
 
    menu_pause,
81
 
    menu_end,
82
 
    menu_is_our_board,
83
 
    NULL,
84
 
    NULL,
85
 
    NULL,
86
 
    menu_config,
87
 
    NULL
88
 
  };
89
 
 
90
 
/*
91
 
 * Main entry point mandatory for each Gcompris's board
92
 
 * ---------------------------------------------------
93
 
 *
94
 
 */
95
 
 
96
 
 
97
 
BoardPlugin
98
 
*get_bplugin_info(void)
99
 
{
100
 
  return &menu_bp;
101
 
}
102
 
 
103
 
/*
104
 
 * in : boolean TRUE = PAUSE : FALSE = CONTINUE
105
 
 *
106
 
 */
107
 
static void menu_pause (gboolean pause)
108
 
{
109
 
 
110
 
  if(gcomprisBoard==NULL)
111
 
    return;
112
 
 
113
 
  board_paused = pause;
114
 
}
115
 
 
116
 
/*
117
 
 */
118
 
static void menu_start (GcomprisBoard *agcomprisBoard)
119
 
{
120
 
 
121
 
  current_x = 0.0;
122
 
  current_y = 0.0;
123
 
 
124
 
  if(agcomprisBoard!=NULL)
125
 
    {
126
 
      MenuItems         *menuitems;
127
 
      GList             *boardlist;     /* List of Board */
128
 
 
129
 
      gcomprisBoard=agcomprisBoard;
130
 
      menuitems = g_new(MenuItems, 1);
131
 
 
132
 
      gcompris_set_background(gnome_canvas_root(gcomprisBoard->canvas), 
133
 
                              gcompris_image_to_skin("gcompris-init.jpg"));
134
 
 
135
 
 
136
 
      boardRootItem = GNOME_CANVAS_GROUP(
137
 
                                         gnome_canvas_item_new (gnome_canvas_root(gcomprisBoard->canvas),
138
 
                                                                gnome_canvas_group_get_type (),
139
 
                                                                "x", (double) 0,
140
 
                                                                "y", (double) 0,
141
 
                                                                NULL));
142
 
 
143
 
      g_object_set_data (G_OBJECT (boardRootItem), "menuitems", menuitems);
144
 
      g_signal_connect (boardRootItem, "destroy",
145
 
                        G_CALLBACK (free_stuff),
146
 
                        menuitems);
147
 
 
148
 
      boardlist = gcompris_get_menulist(gcomprisBoard->section);
149
 
 
150
 
      create_info_area(boardRootItem, menuitems);
151
 
 
152
 
      g_list_foreach (boardlist, (GFunc) display_board_icon, menuitems);
153
 
 
154
 
      g_list_free(boardlist);
155
 
 
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);
160
 
 
161
 
      /* FIXME : Workaround for bugged canvas */
162
 
      gnome_canvas_update_now(gcomprisBoard->canvas);
163
 
 
164
 
      menu_pause(FALSE);
165
 
 
166
 
    }
167
 
 
168
 
}
169
 
 
170
 
static void
171
 
menu_end ()
172
 
{
173
 
  if(boardRootItem!=NULL)
174
 
    gtk_object_destroy (GTK_OBJECT(boardRootItem));
175
 
 
176
 
  boardRootItem=NULL;
177
 
}
178
 
 
179
 
static gboolean
180
 
menu_is_our_board (GcomprisBoard *gcomprisBoard)
181
 
{
182
 
  if (gcomprisBoard)
183
 
    {
184
 
      if(g_strcasecmp(gcomprisBoard->type, "menu")==0)
185
 
        {
186
 
          /* Set the plugin entry */
187
 
          gcomprisBoard->plugin=&menu_bp;
188
 
 
189
 
          return TRUE;
190
 
        }
191
 
    }
192
 
  return FALSE;
193
 
}
194
 
 
195
 
static void
196
 
menu_config ()
197
 
{
198
 
  if(gcomprisBoard!=NULL)
199
 
    {
200
 
      menu_pause(TRUE);
201
 
      gcompris_config_start();
202
 
    }
203
 
}
204
 
 
205
 
 
206
 
 
207
 
/*-------------------------------------------------------------------------------*/
208
 
/*-------------------------------------------------------------------------------*/
209
 
/*-------------------------------------------------------------------------------*/
210
 
/*-------------------------------------------------------------------------------*/
211
 
 
212
 
static void display_board_icon(GcomprisBoard *board, MenuItems *menuitems)
213
 
{
214
 
  gint difficulty = 0;
215
 
  GcomprisProperties    *properties = gcompris_get_properties();
216
 
 
217
 
  difficulty = atoi(board->difficulty);
218
 
 
219
 
  if (board!=NULL 
220
 
      && gcompris_properties_get_board_status(board->name) 
221
 
      && board_check_file(board))
222
 
    {
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);
226
 
      } else {
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);
232
 
          break;
233
 
        case GCOMPRIS_FILTER_EQUAL:
234
 
          if(properties->difficulty_filter==difficulty)
235
 
            menu_create_item(boardRootItem, menuitems, board);
236
 
          break;
237
 
        case GCOMPRIS_FILTER_UNDER:
238
 
          if(difficulty<=properties->difficulty_filter && difficulty>0)
239
 
            menu_create_item(boardRootItem, menuitems, board);
240
 
          break;
241
 
        case GCOMPRIS_FILTER_ABOVE:
242
 
          if(difficulty>=properties->difficulty_filter)
243
 
            menu_create_item(boardRootItem, menuitems, board);
244
 
          break;
245
 
        default:
246
 
          /* Hum, should not happen, let's display the board anyway */
247
 
          break;
248
 
        }
249
 
      }
250
 
    }
251
 
}
252
 
 
253
 
/*
254
 
 * Calculate the next stop where to place an item
255
 
 * return false if there is no more space left
256
 
 */
257
 
static gboolean next_spot() 
258
 
{
259
 
  if(current_x==0.0)
260
 
    {
261
 
      /* Initialisation case */
262
 
      current_x = gcomprisBoard->width/MENU_PER_LINE;
263
 
      current_y = gcomprisBoard->height/MENU_PER_LINE - 40;
264
 
      return(TRUE);
265
 
    }
266
 
 
267
 
  current_x += gcomprisBoard->width/MENU_PER_LINE;
268
 
  if(current_x>=gcomprisBoard->width-100)
269
 
    {
270
 
      current_x = gcomprisBoard->width/MENU_PER_LINE;
271
 
      current_y += 120;
272
 
    }
273
 
 
274
 
  return(TRUE);
275
 
}
276
 
 
277
 
static void menu_create_item(GnomeCanvasGroup *parent, MenuItems *menuitems, GcomprisBoard *board)
278
 
{
279
 
  GdkPixbuf *menu_pixmap = NULL;
280
 
  GdkPixbuf *pixmap = NULL;
281
 
  GnomeCanvasItem *item, *menu_button;
282
 
  int difficulty;
283
 
 
284
 
  menu_pixmap = gcompris_load_pixmap(board->icon_name);
285
 
  next_spot();
286
 
 
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,
292
 
                                       NULL);
293
 
 
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,
300
 
                                      (double) 0.6,
301
 
                                      difficulty);
302
 
  }
303
 
 
304
 
  // display board availability due to sound voice not present
305
 
  if(board->mandatory_sound_file)
306
 
    {
307
 
      gchar *soundfile = NULL;
308
 
      
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);
313
 
      } else {
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);
318
 
      }
319
 
 
320
 
      if (!g_file_test (soundfile, G_FILE_TEST_EXISTS) || !gcompris_get_properties()->audio_works) 
321
 
        {
322
 
          pixmap = gcompris_load_skin_pixmap("voice_bad.png");
323
 
        }
324
 
      else
325
 
        {
326
 
          pixmap = gcompris_load_skin_pixmap("voice.png");
327
 
        }
328
 
 
329
 
      gnome_canvas_item_new (parent,
330
 
                             gnome_canvas_pixbuf_get_type (),
331
 
                             "pixbuf", pixmap,
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,
334
 
                             NULL);
335
 
      gdk_pixbuf_unref(pixmap);
336
 
      g_free(soundfile);
337
 
    }
338
 
 
339
 
  // display menu icon ========================== BEGIN
340
 
  if(g_strcasecmp(board->type, "menu")==0)
341
 
    {
342
 
      pixmap = gcompris_load_skin_pixmap("menuicon.png");
343
 
      item =  gnome_canvas_item_new (parent,
344
 
                                     gnome_canvas_pixbuf_get_type (),
345
 
                                     "pixbuf", pixmap,
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,
348
 
                                     NULL);
349
 
      gdk_pixbuf_unref(pixmap);
350
 
    }
351
 
 
352
 
  gdk_pixbuf_unref(menu_pixmap);
353
 
 
354
 
  // display menu icon ========================== END
355
 
 
356
 
  /*
357
 
   * Now everything ready, map the events
358
 
   * -------------------------------------
359
 
   */
360
 
  g_object_set_data (G_OBJECT (menu_button), "board", board);
361
 
  gtk_signal_connect(GTK_OBJECT(menu_button), "event",
362
 
                     (GtkSignalFunc) item_event,
363
 
                     menuitems);
364
 
 
365
 
  gtk_signal_connect(GTK_OBJECT(menu_button), "event",
366
 
                     (GtkSignalFunc) gcompris_item_event_focus,
367
 
                     NULL);
368
 
 
369
 
 
370
 
}
371
 
 
372
 
static gint
373
 
item_event(GnomeCanvasItem *item, GdkEvent *event,  MenuItems *menuitems)
374
 
{
375
 
  GtkTextIter    iter_start, iter_end;
376
 
  GtkTextBuffer *buffer;
377
 
  GtkTextTag    *txt_tag;
378
 
  GcomprisBoard *board;
379
 
 
380
 
  if(board_paused)
381
 
    return FALSE;
382
 
 
383
 
  if(boardRootItem    == NULL)
384
 
    return;
385
 
 
386
 
  board = g_object_get_data (G_OBJECT (item), "board");
387
 
 
388
 
  switch (event->type)
389
 
    {
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,
394
 
                               NULL);
395
 
 
396
 
      if(board->description && G_IS_OBJECT(menuitems->description_item))
397
 
        gnome_canvas_item_set (menuitems->description_item,
398
 
                               "text",  board->description,
399
 
                               NULL);
400
 
 
401
 
      if(board->author && G_IS_OBJECT(menuitems->author_item))
402
 
        gnome_canvas_item_set (menuitems->author_item,
403
 
                               "text",  board->author,
404
 
                               NULL);
405
 
 
406
 
      break;
407
 
    case GDK_LEAVE_NOTIFY:
408
 
      gnome_canvas_item_set (menuitems->boardname_item,
409
 
                             "text", " ",
410
 
                             NULL);
411
 
 
412
 
      gnome_canvas_item_set (menuitems->description_item,
413
 
                             "text",  " ",
414
 
                             NULL);
415
 
 
416
 
      gnome_canvas_item_set (menuitems->author_item,
417
 
                             "text",  " ",
418
 
                             NULL);
419
 
 
420
 
      break;
421
 
    case GDK_BUTTON_PRESS:
422
 
      {
423
 
        /* Back Reference the current board in the next one */
424
 
        board->previous_board = gcomprisBoard;
425
 
 
426
 
        gcompris_play_ogg ("gobble", NULL);
427
 
 
428
 
        /* End this board */
429
 
        menu_end();
430
 
 
431
 
        /* Start the user's one */
432
 
        board_play (board);
433
 
      };
434
 
      break;
435
 
      
436
 
    default:
437
 
      break;
438
 
    }
439
 
 
440
 
  return FALSE;
441
 
}
442
 
 
443
 
static void create_info_area(GnomeCanvasGroup *parent, MenuItems *menuitems)
444
 
{
445
 
  gint x = (double)gcomprisBoard->width/2;
446
 
  gint y = 383;
447
 
 
448
 
  if(parent    == NULL)
449
 
    return;
450
 
 
451
 
  menuitems->boardname_item = \
452
 
    gnome_canvas_item_new (parent,
453
 
                           gnome_canvas_text_get_type (),
454
 
                           "text", " ",
455
 
                           "font", gcompris_skin_font_board_big,
456
 
                           "x", (double) x,
457
 
                           "y", (double) y,
458
 
                           "anchor", GTK_ANCHOR_NORTH,
459
 
                           "fill_color", "white",
460
 
                           NULL);
461
 
 
462
 
  menuitems->description_item = \
463
 
    gnome_canvas_item_new (parent,
464
 
                           gnome_canvas_text_get_type (),
465
 
                           "text", "",
466
 
                           "font",       gcompris_skin_font_board_medium,
467
 
                           "x", (double) x,
468
 
                           "y", (double) y + 28,
469
 
                           "anchor", GTK_ANCHOR_NORTH,
470
 
                           "fill_color", "white",
471
 
                           NULL);
472
 
 
473
 
  menuitems->author_item = \
474
 
    gnome_canvas_item_new (parent,
475
 
                           gnome_canvas_text_get_type (),
476
 
                           "text", " ",
477
 
                           "font", gcompris_skin_font_board_tiny,
478
 
                           "x", (double) x,
479
 
                           "y", (double) y + 90,
480
 
                           "anchor", GTK_ANCHOR_NORTH,
481
 
                           "fill_color", "white",
482
 
                           "justification", GTK_JUSTIFY_CENTER,
483
 
                           NULL);
484
 
 
485
 
}
486
 
 
487
 
static void
488
 
free_stuff (GtkObject *obj, gpointer data)
489
 
{
490
 
  g_free (data);
491
 
}
492
 
 
493
 
 
494
 
 
495
 
/* Local Variables: */
496
 
/* mode:c */
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)) */
501
 
/* End: */