64
70
static void click_on_letter_destroy_all_items(void);
65
71
static void click_on_letter_next_level(void);
66
72
static gint item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data);
67
static gint phone_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data);
68
static gboolean sounds_are_fine(gchar* letter);
73
static gboolean sounds_are_fine();
70
75
static int right_position;
71
76
static int number_of_letters=MAX_NUMBER_OF_LETTERS;
72
77
static gchar *right_letter;
79
static gchar *alphabet;
81
static void sound_played(gchar *file);
83
static gboolean uppercase_only;
75
85
/* Description of this plugin */
76
86
static BoardPlugin menu_bp =
81
N_("Learn to recognize letters"),
91
"Learn to recognize letters",
82
92
"Pascal Georges pascal.georges1@free.fr>",
129
137
static void start_board (GcomprisBoard *agcomprisBoard)
132
if(!sounds_are_fine("a"))
135
if(agcomprisBoard!=NULL)
139
GHashTable *config = gc_db_get_board_conf();
144
gc_locale_set(g_hash_table_lookup( config, "locale_sound"));
146
gchar *up_init_str = g_hash_table_lookup( config, "uppercase_only");
148
if (up_init_str && (strcmp(up_init_str, "True")==0))
149
uppercase_only = TRUE;
151
uppercase_only = FALSE;
153
g_hash_table_destroy(config);
155
ready = sounds_are_fine();
159
if (agcomprisBoard!=NULL)
137
161
gcomprisBoard=agcomprisBoard;
138
gcompris_set_background(gnome_canvas_root(gcomprisBoard->canvas), "images/scenery4_background.png");
162
gc_set_background(gnome_canvas_root(gcomprisBoard->canvas),
163
"images/scenery4_background.png");
139
164
gcomprisBoard->level=1;
140
165
gcomprisBoard->maxlevel=NUMBER_OF_LEVELS;
141
166
gcomprisBoard->sublevel=1;
142
gcomprisBoard->number_of_sublevel=NUMBER_OF_SUBLEVELS; /* Go to next level after this number of 'play' */
143
gcompris_bar_set(GCOMPRIS_BAR_LEVEL|GCOMPRIS_BAR_REPEAT);
144
gcompris_score_start(SCORESTYLE_NOTE,
147
gcomprisBoard->number_of_sublevel);
149
click_on_letter_next_level();
168
/* Go to next level after this number of 'play' */
169
gcomprisBoard->number_of_sublevel=NUMBER_OF_SUBLEVELS;
173
/* Warning, bar buttons are set in click_on_letter_next_level()
174
to avoid them to appear in the case a dialog is displayed */
175
gc_score_start(SCORESTYLE_NOTE,
178
gcomprisBoard->number_of_sublevel);
181
click_on_letter_next_level();
156
189
/* ======================================= */
157
190
static void end_board ()
195
230
/* ======================================= */
196
231
static void repeat ()
198
if(gcomprisBoard!=NULL)
233
if(gcomprisBoard!=NULL)
201
235
gchar *str1 = NULL;
202
236
gchar *right_letter_ogg = NULL;
204
right_letter_ogg = g_strdup_printf("%s%s",right_letter,".ogg");
205
str1 = gcompris_get_asset_file("gcompris alphabet", NULL, "audio/x-ogg", right_letter_ogg);
208
gcompris_play_ogg(str1, NULL);
238
str1 = gc_sound_alphabet(right_letter);
240
right_letter_ogg = g_strdup_printf("sounds/$LOCALE/alphabet/%s", str1);
243
if(right_letter_ogg) {
244
gc_sound_play_ogg_cb(right_letter_ogg, sound_played);
212
247
g_free(right_letter_ogg);
216
static gboolean sounds_are_fine (gchar* letter)
251
static gboolean sounds_are_fine()
220
GcomprisProperties *properties = gcompris_get_properties();
222
gboolean fine = TRUE;
224
locale= g_strndup(gcompris_get_locale(), 2);
226
str1 = g_strdup_printf("%s%s", letter, ".ogg");
227
str2 = gcompris_get_asset_file("gcompris alphabet", NULL, "audio/x-ogg", str1);
230
gchar *msg = g_strdup_printf("%s%s", _("Error: this activity requires you that you first install \nthe package assetml-voices-alphabet-"),
232
gcompris_dialog(msg, gcompris_end_board);
236
if(!properties->fx) {
237
gcompris_dialog(_("Error: this activity cannot be played with the\nsound effects disabled.\nGo in the configuration dialog to\nenable the sound"), gcompris_end_board);
255
GcomprisProperties *properties = gc_prop_get();
259
gc_dialog(_("Error: this activity cannot be played with the\nsound effects disabled.\nGo to the configuration dialog to\nenable the sound"), gc_board_stop);
263
/* TRANSLATORS: Put here the alphabet in your language */
264
alphabet=_("abcdefghijklmnopqrstuvwxyz");
265
g_assert(g_utf8_validate(alphabet, -1, NULL)); // require by all utf8-functions
267
gchar *letter = g_new0(gchar, 8);
268
g_unichar_to_utf8(g_utf8_get_char(alphabet), letter);
269
letter_str = gc_sound_alphabet(letter);
272
str2 = gc_file_find_absolute("sounds/$LOCALE/alphabet/%s", letter_str);
276
gchar *locale = NULL;
278
locale = g_strndup(gc_locale_get(), 2);
280
gc_locale_set("en_US");
282
str2 = gc_file_find_absolute("sounds/en/alphabet/%s", letter_str);
286
gchar *msg = g_strdup_printf( _("Error: this activity requires that you first install\nthe packages with gcompris voices for the locale '%s' or '%s'"),
288
gc_dialog(msg, gc_board_stop);
294
gchar *msg = g_strdup_printf( _("Error: this activity requires that you first install\nthe packages with GCompris voices for the locale '%s' ! Fallback to english, sorry!"), locale);
295
gc_dialog(msg, click_on_letter_next_level);
250
309
/*-------------------------------------------------------------------------------*/
251
310
/*-------------------------------------------------------------------------------*/
252
311
/* set initial values for the next level */
253
static void click_on_letter_next_level()
313
click_on_letter_next_level()
255
gcompris_bar_set_level(gcomprisBoard);
315
/* It must be set it for the warning dialogs */
316
gc_bar_set(GC_BAR_CONFIG|GC_BAR_LEVEL|GC_BAR_REPEAT);
318
gc_bar_set_level(gcomprisBoard);
257
320
click_on_letter_destroy_all_items();
259
322
selected_button = NULL;
260
gcompris_score_set(gcomprisBoard->sublevel);
323
gc_score_set(gcomprisBoard->sublevel);
261
324
g_free (right_letter);
262
325
/* Try the next level */
326
gc_sound_play_ogg("sounds/$LOCALE/misc/click_on_letter.ogg", NULL);
263
327
click_on_letter_create_item(gnome_canvas_root(gcomprisBoard->canvas));
265
329
/* ==================================== */
278
342
int xOffset,yOffset,i,j;
279
343
GdkPixbuf *button_pixmap = NULL;
281
/* TRANSLATORS: Put here the alphabet in your language */
282
gchar *alphabet=_("abcdefghijklmnopqrstuvwxyz");
283
assert(g_utf8_validate(alphabet,-1,NULL)); // require by all utf8-functions
286
345
int length_of_aphabet=g_utf8_strlen (alphabet,-1);
288
347
number_of_letters=gcomprisBoard->level+1;
289
348
if (number_of_letters>MAX_NUMBER_OF_LETTERS) number_of_letters=MAX_NUMBER_OF_LETTERS;
291
350
int numbers[number_of_letters];
292
352
gchar *letters[number_of_letters];
293
assert(number_of_letters<=length_of_aphabet); // because we must set unique letter on every "vagon"
353
g_assert(number_of_letters<=length_of_aphabet); // because we must set unique letter on every "vagon"
295
355
for (i=0;i<number_of_letters;i++){
296
numbers[i]=((int)(((float)length_of_aphabet)*rand()/(RAND_MAX+1.0)));
356
numbers[i]=((int)(((float)length_of_aphabet)*rand()/(RAND_MAX+1.0)));
298
// check that the letter has not been taken yet
300
if (numbers[i]==numbers[j]) {
358
// check that the letter has not been taken yet
360
if (numbers[i]==numbers[j]) {
311
368
for (i=0;i<number_of_letters;i++){
312
gchar *copy_from=g_utf8_offset_to_pointer(alphabet, numbers[i]);
313
gchar *copy_to=g_utf8_offset_to_pointer(alphabet, numbers[i]+1);
314
letters[i]=g_strndup(copy_from,copy_to-copy_from);
315
switch (gcomprisBoard->level) {
317
case 2 : letters[i]=g_strndup(copy_from,copy_to-copy_from); break;
318
case 3 : letters[i]=g_utf8_strup(copy_from,copy_to-copy_from); break;
320
if ( rand() > (RAND_MAX/2) )
321
letters[i]=g_strndup(copy_from,copy_to-copy_from);
323
letters[i]=g_utf8_strup(copy_from,copy_to-copy_from);
369
gchar *copy_from=g_utf8_offset_to_pointer(alphabet, numbers[i]);
370
gchar *copy_to=g_utf8_offset_to_pointer(alphabet, numbers[i]+1);
371
letters[i]=g_strndup(copy_from,copy_to-copy_from);
374
letters[i]=g_utf8_strup(copy_from,copy_to-copy_from);
376
switch (gcomprisBoard->level) {
378
case 2 : letters[i]=g_strndup(copy_from,copy_to-copy_from); break;
379
case 3 : letters[i]=g_utf8_strup(copy_from,copy_to-copy_from); break;
381
if ( rand() > (RAND_MAX/2) )
382
letters[i]=g_strndup(copy_from,copy_to-copy_from);
384
letters[i]=g_utf8_strup(copy_from,copy_to-copy_from);
329
390
right_position = ((int)(((float)number_of_letters)*rand()/(RAND_MAX+1.0)));
330
assert(right_position >= 0 && right_position < number_of_letters);
391
g_assert(right_position >= 0 && right_position < number_of_letters);
331
392
right_letter = g_utf8_strdown(letters[right_position],-1);
336
397
boardRootItem = GNOME_CANVAS_GROUP(
337
398
gnome_canvas_item_new (gnome_canvas_root(gcomprisBoard->canvas),
344
button_pixmap = gcompris_load_pixmap("images/wagon-yellow.png");
405
button_pixmap = gc_pixmap_load("images/wagon-yellow.png");
346
407
yOffset = VERTICAL_SEPARATION;
350
411
for (i=0; i< number_of_letters; i++) {
352
buttons[i] = gnome_canvas_item_new (boardRootItem,
353
gnome_canvas_pixbuf_get_type (),
354
"pixbuf", button_pixmap,
355
"x", (double) xOffset,
356
"y", (double) yOffset,
360
l_items[i] = gnome_canvas_item_new (boardRootItem,
361
gnome_canvas_text_get_type (),
363
"font", gcompris_skin_font_board_huge_bold,
364
"anchor", GTK_ANCHOR_CENTER,
365
"fill_color_rgba", 0x0000ffff,
366
"x", (double) xOffset + gdk_pixbuf_get_width(button_pixmap)/2,
367
"y", (double) yOffset + gdk_pixbuf_get_height(button_pixmap)/2 - 5,
370
xOffset +=HORIZONTAL_SEPARATION +gdk_pixbuf_get_width(button_pixmap);
372
gtk_signal_connect(GTK_OBJECT(l_items[i]), "event", (GtkSignalFunc) item_event, GINT_TO_POINTER(i));
373
gtk_signal_connect(GTK_OBJECT(buttons[i]), "event", (GtkSignalFunc) item_event, GINT_TO_POINTER(i));
374
gtk_signal_connect(GTK_OBJECT(buttons[i]), "event", (GtkSignalFunc) gcompris_item_event_focus, NULL);
412
buttons[i] = gnome_canvas_item_new (boardRootItem,
413
gnome_canvas_pixbuf_get_type (),
414
"pixbuf", button_pixmap,
415
"x", (double) xOffset,
416
"y", (double) yOffset,
420
l_items[i] = gnome_canvas_item_new (boardRootItem,
421
gnome_canvas_text_get_type (),
423
"font", gc_skin_font_board_huge_bold,
424
"anchor", GTK_ANCHOR_CENTER,
425
"fill_color_rgba", 0x0000ffff,
426
"x", (double) xOffset + gdk_pixbuf_get_width(button_pixmap)/2,
427
"y", (double) yOffset + gdk_pixbuf_get_height(button_pixmap)/2 - 5,
431
xOffset +=HORIZONTAL_SEPARATION +gdk_pixbuf_get_width(button_pixmap);
433
gtk_signal_connect(GTK_OBJECT(l_items[i]), "event", (GtkSignalFunc) item_event, GINT_TO_POINTER(i));
434
gtk_signal_connect(GTK_OBJECT(buttons[i]), "event", (GtkSignalFunc) item_event, GINT_TO_POINTER(i));
435
// gtk_signal_connect(GTK_OBJECT(buttons[i]), "event", (GtkSignalFunc) gc_item_focus_event, NULL);
461
510
/* Replace text item by button item */
463
512
for (i=0; i<number_of_letters;i++) {
464
if ( l_items[i] == item ) {
513
if ( l_items[i] == item ) {
469
518
if (selected_button != NULL && selected_button != button) {
470
button_pixmap = gcompris_load_pixmap("images/wagon-yellow.png");
471
/* Warning changing the image needs to update pixbuf_ref for the focus usage */
472
g_object_set_data (G_OBJECT (selected_button), "pixbuf_ref", button_pixmap);
473
gnome_canvas_item_set(selected_button, "pixbuf", button_pixmap, NULL);
474
gdk_pixbuf_unref(button_pixmap);
519
button_pixmap = gc_pixmap_load("images/wagon-yellow.png");
520
/* Warning changing the image needs to update pixbuf_ref for the focus usage */
521
gc_item_focus_free(selected_button, NULL);
522
gnome_canvas_item_set(selected_button, "pixbuf", button_pixmap, NULL);
523
gdk_pixbuf_unref(button_pixmap);
477
526
if (selected_button != button) {
478
button_pixmap_selected = gcompris_load_pixmap("images/wagon-green.png");
479
/* Warning changing the image needs to update pixbuf_ref for the focus usage */
480
g_object_set_data (G_OBJECT (button), "pixbuf_ref", button_pixmap_selected);
481
gnome_canvas_item_set(button, "pixbuf", button_pixmap_selected, NULL);
482
selected_button = button;
483
gdk_pixbuf_unref(button_pixmap_selected);
527
button_pixmap_selected = gc_pixmap_load("images/wagon-green.png");
528
/* Warning changing the image needs to update pixbuf_ref for the focus usage */
529
gc_item_focus_free(button, NULL);
530
gnome_canvas_item_set(button, "pixbuf", button_pixmap_selected, NULL);
531
selected_button = button;
532
gdk_pixbuf_unref(button_pixmap_selected);
538
/* ************************************* */
539
/* * Configuration * */
540
/* ************************************* */
543
/* ======================= */
544
/* = config_start = */
545
/* ======================= */
547
static GcomprisProfile *profile_conf;
548
static GcomprisBoard *board_conf;
550
static GHFunc save_table (gpointer key,
554
gc_db_set_board_conf ( profile_conf,
563
conf_ok(GHashTable *table)
573
g_hash_table_foreach(table, (GHFunc) save_table, NULL);
581
config = gc_db_get_board_conf();
586
gc_locale_set(g_hash_table_lookup(config, "locale_sound"));
588
gchar *up_init_str = g_hash_table_lookup( config, "uppercase_only");
591
if(strcmp(up_init_str, "True")==0)
592
uppercase_only = TRUE;
594
uppercase_only = FALSE;
598
g_hash_table_destroy(config);
602
click_on_letter_next_level();
614
config_start(GcomprisBoard *agcomprisBoard,
615
GcomprisProfile *aProfile)
617
board_conf = agcomprisBoard;
618
profile_conf = aProfile;
623
gchar *label = g_strdup_printf("<b>%s</b> configuration\n for profile <b>%s</b>",
624
agcomprisBoard->name,
625
aProfile ? aProfile->name : "");
627
gc_board_config_window_display(label, conf_ok);
631
/* init the combo to previously saved value */
632
GHashTable *config = gc_db_get_conf( profile_conf, board_conf);
634
gchar *saved_locale_sound = g_hash_table_lookup( config, "locale_sound");
636
gc_board_config_combo_locales_asset( "Select sound locale", saved_locale_sound,
637
"sounds/$LOCALE/colors/purple.ogg");
639
gboolean up_init = FALSE;
641
gchar *up_init_str = g_hash_table_lookup( config, "uppercase_only");
643
if (up_init_str && (strcmp(up_init_str, "True")==0))
646
gc_board_config_boolean_box(_("Uppercase only text"),
650
g_hash_table_destroy(config);
654
/* ======================= */
655
/* = config_stop = */
656
/* ======================= */
663
sound_played (gchar *file)
665
g_warning ("Sound_played %s\n", file);