Back to index

gcompris  8.2.2
Defines | Functions | Variables
click_on_letter.c File Reference
#include <glib.h>
#include <string.h>
#include "gcompris/gcompris.h"

Go to the source code of this file.

Defines

#define SOUNDLISTFILE   PACKAGE
#define VERTICAL_SEPARATION   408
#define HORIZONTAL_SEPARATION   0
#define NUMBER_OF_SUBLEVELS   3
#define NUMBER_OF_LEVELS   5
#define MAX_NUMBER_OF_LETTERS   4
#define NOT_OK   0
#define OK   1
#define OK_NO_INIT   2
#define TEXT_COLOR   "white"

Functions

static void start_board (GcomprisBoard *agcomprisBoard)
static void pause_board (gboolean pause)
static void end_board (void)
static gboolean is_our_board (GcomprisBoard *gcomprisBoard)
static void set_level (guint level)
static void process_ok (void)
static void highlight_selected (GnomeCanvasItem *)
static void game_won (void)
static void repeat (void)
static void config_start (GcomprisBoard *agcomprisBoard, GcomprisProfile *aProfile)
static void config_stop (void)
static GnomeCanvasItem * click_on_letter_create_item (GnomeCanvasGroup *parent)
static void click_on_letter_destroy_all_items (void)
static void click_on_letter_next_level (void)
static gint item_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
static gboolean sounds_are_fine ()
static void sound_played (gchar *file)
static gboolean process_ok_timeout ()
static GHFunc save_table (gpointer key, gpointer value, gpointer user_data)
static void conf_ok (GHashTable *table)

Variables

static GcomprisBoard * gcomprisBoard = NULL
static gboolean board_paused
static int gamewon
static GnomeCanvasGroup * boardRootItem = NULL
static GnomeCanvasItem * l_items [MAX_NUMBER_OF_LETTERS]
static GnomeCanvasItem * buttons [MAX_NUMBER_OF_LETTERS]
static GnomeCanvasItem * selected_button = NULL
static int right_position
static int number_of_letters = MAX_NUMBER_OF_LETTERS
static gchar * right_letter
static gchar * alphabet
static gboolean uppercase_only
static BoardPlugin menu_bp
static GcomprisProfileprofile_conf
static GcomprisBoard * board_conf

Define Documentation

#define HORIZONTAL_SEPARATION   0

Definition at line 50 of file click_on_letter.c.

#define MAX_NUMBER_OF_LETTERS   4

Definition at line 54 of file click_on_letter.c.

#define NOT_OK   0

Definition at line 56 of file click_on_letter.c.

#define NUMBER_OF_LEVELS   5

Definition at line 53 of file click_on_letter.c.

#define NUMBER_OF_SUBLEVELS   3

Definition at line 52 of file click_on_letter.c.

#define OK   1

Definition at line 57 of file click_on_letter.c.

#define OK_NO_INIT   2

Definition at line 58 of file click_on_letter.c.

#define SOUNDLISTFILE   PACKAGE

Definition at line 27 of file click_on_letter.c.

#define TEXT_COLOR   "white"

Definition at line 60 of file click_on_letter.c.

#define VERTICAL_SEPARATION   408

Definition at line 49 of file click_on_letter.c.


Function Documentation

static GnomeCanvasItem * click_on_letter_create_item ( GnomeCanvasGroup *  parent) [static]

Definition at line 339 of file click_on_letter.c.

{

  int xOffset,yOffset,i,j;
  GdkPixbuf *button_pixmap = NULL;

  int length_of_aphabet=g_utf8_strlen (alphabet,-1);

  number_of_letters=gcomprisBoard->level+1;
  if (number_of_letters>MAX_NUMBER_OF_LETTERS) number_of_letters=MAX_NUMBER_OF_LETTERS;

  int numbers[number_of_letters];

  gchar *letters[number_of_letters];
  g_assert(number_of_letters<=length_of_aphabet); // because we must set unique letter on every "vagon"

  for (i=0;i<number_of_letters;i++){
    numbers[i]=((int)(((float)length_of_aphabet)*rand()/(RAND_MAX+1.0)));

    // check that the letter has not been taken yet
    for(j=0;j<i;j++){
      if (numbers[i]==numbers[j]) {
       i--;
       continue;
      }
    }

  }

  for (i=0;i<number_of_letters;i++){
    gchar *copy_from=g_utf8_offset_to_pointer(alphabet, numbers[i]);
    gchar *copy_to=g_utf8_offset_to_pointer(alphabet, numbers[i]+1);
    letters[i]=g_strndup(copy_from,copy_to-copy_from);

    if (uppercase_only)
      letters[i]=g_utf8_strup(copy_from,copy_to-copy_from);
    else {
      switch (gcomprisBoard->level) {
      case 1  :
      case 2  : letters[i]=g_strndup(copy_from,copy_to-copy_from); break;
      case 3  : letters[i]=g_utf8_strup(copy_from,copy_to-copy_from); break;
      default :
       if ( rand() > (RAND_MAX/2) )
         letters[i]=g_strndup(copy_from,copy_to-copy_from);
       else
         letters[i]=g_utf8_strup(copy_from,copy_to-copy_from);
      }
    }
  }

  /*  */
  right_position = ((int)(((float)number_of_letters)*rand()/(RAND_MAX+1.0)));
  g_assert(right_position >= 0  && right_position < number_of_letters);
  right_letter = g_utf8_strdown(letters[right_position],-1);

  repeat();


  boardRootItem = GNOME_CANVAS_GROUP(
                                 gnome_canvas_item_new (gnome_canvas_root(gcomprisBoard->canvas),
                                                     gnome_canvas_group_get_type (),
                                                     "x", (double) 0,
                                                     "y", (double) 0,
                                                     NULL));


  button_pixmap = gc_pixmap_load("images/wagon-yellow.png");

  yOffset = VERTICAL_SEPARATION;
  xOffset = 5;


  for (i=0; i< number_of_letters; i++) {
    buttons[i] = gnome_canvas_item_new (boardRootItem,
                                   gnome_canvas_pixbuf_get_type (),
                                   "pixbuf",  button_pixmap,
                                   "x",  (double) xOffset,
                                   "y",  (double) yOffset,
                                   NULL);


    l_items[i] = gnome_canvas_item_new (boardRootItem,
                                   gnome_canvas_text_get_type (),
                                   "text", letters[i],
                                   "font", gc_skin_font_board_huge_bold,
                                   "anchor", GTK_ANCHOR_CENTER,
                                   "fill_color_rgba", 0x0000ffff,
                                   "x",  (double) xOffset + gdk_pixbuf_get_width(button_pixmap)/2,
                                   "y",  (double) yOffset + gdk_pixbuf_get_height(button_pixmap)/2 - 5,
                                   NULL);

    g_free(letters[i]);
    xOffset +=HORIZONTAL_SEPARATION +gdk_pixbuf_get_width(button_pixmap);

    gtk_signal_connect(GTK_OBJECT(l_items[i]), "event", (GtkSignalFunc) item_event, GINT_TO_POINTER(i));
    gtk_signal_connect(GTK_OBJECT(buttons[i]), "event",  (GtkSignalFunc) item_event, GINT_TO_POINTER(i));
    //  gtk_signal_connect(GTK_OBJECT(buttons[i]), "event", (GtkSignalFunc) gc_item_focus_event, NULL);
  }


  gdk_pixbuf_unref(button_pixmap);

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void click_on_letter_destroy_all_items ( void  ) [static]

Definition at line 331 of file click_on_letter.c.

{
  if(boardRootItem!=NULL)
    gtk_object_destroy (GTK_OBJECT(boardRootItem));

  boardRootItem = NULL;
}

Here is the caller graph for this function:

static void click_on_letter_next_level ( void  ) [static]

Definition at line 313 of file click_on_letter.c.

{
  /* It must be set it for the warning dialogs */
  gc_bar_set(GC_BAR_CONFIG|GC_BAR_LEVEL|GC_BAR_REPEAT);

  gc_bar_set_level(gcomprisBoard);

  click_on_letter_destroy_all_items();
  gamewon = FALSE;
  selected_button = NULL;
  gc_score_set(gcomprisBoard->sublevel);
  g_free (right_letter);
  /* Try the next level */
  gc_sound_play_ogg("sounds/$LOCALE/misc/click_on_letter.ogg", NULL);
  click_on_letter_create_item(gnome_canvas_root(gcomprisBoard->canvas));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void conf_ok ( GHashTable *  table) [static]

Definition at line 563 of file click_on_letter.c.

{
  if (!table){
    if (gcomprisBoard)
      pause_board(FALSE);

    return;
  }


  g_hash_table_foreach(table, (GHFunc) save_table, NULL);

  board_conf = NULL;
  profile_conf = NULL;

  if (gcomprisBoard){
    GHashTable *config;
    if (profile_conf)
      config = gc_db_get_board_conf();
    else
      config = table;

    gc_locale_reset();
    gc_locale_set(g_hash_table_lookup(config, "locale_sound"));

    gchar *up_init_str = g_hash_table_lookup( config, "uppercase_only");
    if (up_init_str)
      {
       if(strcmp(up_init_str, "True")==0)
         uppercase_only = TRUE;
       else
         uppercase_only = FALSE;
      }

    if (profile_conf)
      g_hash_table_destroy(config);

    sounds_are_fine();

    click_on_letter_next_level();

    gamewon = FALSE;
    pause_board(FALSE);

  }

  board_conf = NULL;
  profile_conf = NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void config_start ( GcomprisBoard *  agcomprisBoard,
GcomprisProfile aProfile 
) [static]

Definition at line 614 of file click_on_letter.c.

{
  board_conf = agcomprisBoard;
  profile_conf = aProfile;

  if (gcomprisBoard)
    pause_board(TRUE);

  gchar *label = g_strdup_printf("<b>%s</b> configuration\n for profile <b>%s</b>",
                             agcomprisBoard->name,
                             aProfile ? aProfile->name : "");

  gc_board_config_window_display(label, conf_ok);

  g_free(label);

  /* init the combo to previously saved value */
  GHashTable *config = gc_db_get_conf( profile_conf, board_conf);

  gchar *saved_locale_sound = g_hash_table_lookup( config, "locale_sound");

  gc_board_config_combo_locales_asset( "Select sound locale", saved_locale_sound,
                            "sounds/$LOCALE/colors/purple.ogg");

  gboolean up_init = FALSE;

  gchar *up_init_str = g_hash_table_lookup( config, "uppercase_only");

  if (up_init_str && (strcmp(up_init_str, "True")==0))
    up_init = TRUE;

  gc_board_config_boolean_box(_("Uppercase only text"),
                     "uppercase_only",
                     up_init);

  g_hash_table_destroy(config);
}

Here is the call graph for this function:

static void config_stop ( void  ) [static]

Definition at line 658 of file click_on_letter.c.

{
}
static void end_board ( void  ) [static]

Definition at line 190 of file click_on_letter.c.

Here is the call graph for this function:

static void game_won ( void  ) [static]

Definition at line 444 of file click_on_letter.c.

{
  gcomprisBoard->sublevel++;

  if(gcomprisBoard->sublevel>gcomprisBoard->number_of_sublevel) {
    /* Try the next level */
    gcomprisBoard->sublevel=1;
    gcomprisBoard->level++;
    if(gcomprisBoard->level>gcomprisBoard->maxlevel) { // the current board is finished : bail out
      gc_bonus_end_display(BOARD_FINISHED_TUXPLANE);
      return;
    }
  }
  click_on_letter_next_level();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void highlight_selected ( GnomeCanvasItem *  item) [static]

Definition at line 504 of file click_on_letter.c.

                                                       {
  GdkPixbuf *button_pixmap_selected = NULL, *button_pixmap = NULL;
  GnomeCanvasItem *button;
  int i;


  /* Replace text item by button item */
  button = item;
  for (i=0; i<number_of_letters;i++) {
    if ( l_items[i] == item ) {
      button = buttons[i];
    }
  }

  if (selected_button != NULL && selected_button != button) {
    button_pixmap = gc_pixmap_load("images/wagon-yellow.png");
    /* Warning changing the image needs to update pixbuf_ref for the focus usage */
    gc_item_focus_free(selected_button, NULL);
    gnome_canvas_item_set(selected_button, "pixbuf", button_pixmap, NULL);
    gdk_pixbuf_unref(button_pixmap);
  }

  if (selected_button != button) {
    button_pixmap_selected = gc_pixmap_load("images/wagon-green.png");
    /* Warning changing the image needs to update pixbuf_ref for the focus usage */
      gc_item_focus_free(button, NULL);
    gnome_canvas_item_set(button, "pixbuf", button_pixmap_selected, NULL);
    selected_button = button;
    gdk_pixbuf_unref(button_pixmap_selected);
  }

}

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean is_our_board ( GcomprisBoard *  gcomprisBoard) [static]

Definition at line 215 of file click_on_letter.c.

{
  if (gcomprisBoard)
    {
      if(g_strcasecmp(gcomprisBoard->type, "click_on_letter")==0)
       {
         /* Set the plugin entry */
         gcomprisBoard->plugin=&menu_bp;

         return TRUE;
       }
    }
  return FALSE;
}
static gint item_event ( GnomeCanvasItem *  item,
GdkEvent *  event,
gpointer  data 
) [static]

Definition at line 472 of file click_on_letter.c.

{
  int pos = GPOINTER_TO_INT(data);
  double item_x, item_y;
  item_x = event->button.x;
  item_y = event->button.y;
  gnome_canvas_item_w2i(item->parent, &item_x, &item_y);

  if(board_paused)
    return FALSE;

  switch (event->type)
    {
    case GDK_BUTTON_PRESS:
      /* We really don't want the user to change his/her mind */
      board_paused = TRUE;

      if ( pos == right_position ) {
       gamewon = TRUE;
      } else {
       gamewon = FALSE;
      }
      highlight_selected(item);
      process_ok();
      break;

    default:
      break;
    }
  return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void pause_board ( gboolean  pause) [static]

Definition at line 122 of file click_on_letter.c.

{
  if(gcomprisBoard==NULL)
    return;

  if(gamewon == TRUE && pause == FALSE) /* the game is won */
    {
      game_won();
    }

  board_paused = pause;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void process_ok ( void  ) [static]

Definition at line 466 of file click_on_letter.c.

                         {
  // leave time to display the right answer
  g_timeout_add(TIME_CLICK_TO_BONUS, process_ok_timeout, NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean process_ok_timeout ( ) [static]

Definition at line 461 of file click_on_letter.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void repeat ( void  ) [static]

Definition at line 231 of file click_on_letter.c.

{
  if(gcomprisBoard!=NULL)
    {
      gchar *str1 = NULL;
      gchar *right_letter_ogg = NULL;

      str1 = gc_sound_alphabet(right_letter);

      right_letter_ogg = g_strdup_printf("sounds/$LOCALE/alphabet/%s", str1);
      g_free(str1);

      if(right_letter_ogg) {
       gc_sound_play_ogg_cb(right_letter_ogg, sound_played);
      }

      g_free(right_letter_ogg);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static GHFunc save_table ( gpointer  key,
gpointer  value,
gpointer  user_data 
) [static]

Definition at line 550 of file click_on_letter.c.

{
  gc_db_set_board_conf ( profile_conf,
                         board_conf,
                         (gchar *) key,
                         (gchar *) value);

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_level ( guint  level) [static]

Definition at line 204 of file click_on_letter.c.

{

  if(gcomprisBoard!=NULL)
    {
      gcomprisBoard->level=level;
      gcomprisBoard->sublevel=1;
      click_on_letter_next_level();
    }
}

Here is the call graph for this function:

static void sound_played ( gchar *  file) [static]

Definition at line 663 of file click_on_letter.c.

{
  g_warning ("Sound_played %s\n", file);
}

Here is the caller graph for this function:

static gboolean sounds_are_fine ( ) [static]

Definition at line 251 of file click_on_letter.c.

{
  char *letter_str;
  char *str2;
  GcomprisProperties *properties = gc_prop_get();

  if(!properties->fx)
    {
      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);
      return(NOT_OK);
    }

  /* TRANSLATORS: Put here the alphabet in your language */
  alphabet=_("abcdefghijklmnopqrstuvwxyz");
  g_assert(g_utf8_validate(alphabet, -1, NULL)); // require by all utf8-functions

  gchar *letter = g_new0(gchar, 8);
  g_unichar_to_utf8(g_utf8_get_char(alphabet), letter);
  letter_str = gc_sound_alphabet(letter);
  g_free(letter);

  str2 = gc_file_find_absolute("sounds/$LOCALE/alphabet/%s", letter_str);

  if (!str2)
    {
      gchar *locale = NULL;

      locale = g_strndup(gc_locale_get(), 2);
      gc_locale_reset();
      gc_locale_set("en_US");

      str2 = gc_file_find_absolute("sounds/en/alphabet/%s", letter_str);

      if (!str2)
       {
         gchar *msg = g_strdup_printf( _("Error: this activity requires that you first install\nthe packages with gcompris voices for the locale '%s' or '%s'"),
                                   locale, "en");
         gc_dialog(msg, gc_board_stop);
         g_free(msg);
         return (NOT_OK);
       }
      else
       {
         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);
         gc_dialog(msg, click_on_letter_next_level);
         g_free(msg);
         g_free(str2);
         return(OK_NO_INIT);
       }
    }
  else
    {
      g_free(str2);
    }

  return(OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void start_board ( GcomprisBoard *  agcomprisBoard) [static]

Definition at line 137 of file click_on_letter.c.

{
  GHashTable *config = gc_db_get_board_conf();
  int ready;

  board_paused = TRUE;

  gc_locale_set(g_hash_table_lookup( config, "locale_sound"));

  gchar *up_init_str = g_hash_table_lookup( config, "uppercase_only");

  if (up_init_str && (strcmp(up_init_str, "True")==0))
    uppercase_only = TRUE;
  else
    uppercase_only = FALSE;

  g_hash_table_destroy(config);

  ready = sounds_are_fine();

  gc_sound_pause();

  if (agcomprisBoard!=NULL)
    {
      gcomprisBoard=agcomprisBoard;
      gc_set_background(gnome_canvas_root(gcomprisBoard->canvas),
                           "images/scenery4_background.png");
      gcomprisBoard->level=1;
      gcomprisBoard->maxlevel=NUMBER_OF_LEVELS;
      gcomprisBoard->sublevel=1;

      /* Go to next level after this number of 'play' */
      gcomprisBoard->number_of_sublevel=NUMBER_OF_SUBLEVELS;

      if(ready)
       {
         /* Warning, bar buttons are set in click_on_letter_next_level()
            to avoid them to appear in the case a dialog is displayed */
         gc_score_start(SCORESTYLE_NOTE,
                            50,
                            50,
                            gcomprisBoard->number_of_sublevel);

         if(ready == OK)
           click_on_letter_next_level();

         gamewon = FALSE;
         pause_board(FALSE);
       }
    }

}

Here is the call graph for this function:


Variable Documentation

gchar* alphabet [static]

Definition at line 79 of file click_on_letter.c.

GcomprisBoard* board_conf [static]

Definition at line 548 of file click_on_letter.c.

gboolean board_paused [static]

Definition at line 30 of file click_on_letter.c.

GnomeCanvasGroup* boardRootItem = NULL [static]

Definition at line 62 of file click_on_letter.c.

GnomeCanvasItem* buttons[MAX_NUMBER_OF_LETTERS] [static]

Definition at line 65 of file click_on_letter.c.

int gamewon [static]

Definition at line 38 of file click_on_letter.c.

GcomprisBoard* gcomprisBoard = NULL [static]

Definition at line 29 of file click_on_letter.c.

GnomeCanvasItem* l_items[MAX_NUMBER_OF_LETTERS] [static]

Definition at line 64 of file click_on_letter.c.

BoardPlugin menu_bp [static]
Initial value:
  {
    NULL,
    NULL,
    "Read a letter",
    "Learn to recognize letters",
    "Pascal Georges pascal.georges1@free.fr>",
    NULL,
    NULL,
    NULL,
    NULL,
    start_board,
    pause_board,
    end_board,
    is_our_board,
    NULL,
    NULL,
    set_level,
    NULL,
    repeat,
    config_start,
    config_stop
  }

Definition at line 86 of file click_on_letter.c.

Definition at line 76 of file click_on_letter.c.

Definition at line 547 of file click_on_letter.c.

gchar* right_letter [static]

Definition at line 77 of file click_on_letter.c.

int right_position [static]

Definition at line 75 of file click_on_letter.c.

GnomeCanvasItem* selected_button = NULL [static]

Definition at line 66 of file click_on_letter.c.

gboolean uppercase_only [static]

Definition at line 83 of file click_on_letter.c.