Back to index

gcompris  8.2.2
Defines | Functions | Variables
colors.c File Reference
#include "gcompris/gcompris.h"

Go to the source code of this file.

Defines

#define SOUNDLISTFILE   PACKAGE
#define LAST_COLOR   10

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 process_ok (void)
static void highlight_selected (int)
static void game_won (void)
static void repeat (void)
static void colors_config_start (GcomprisBoard *agcomprisBoard, GcomprisProfile *aProfile)
static void colors_config_stop (void)
static GnomeCanvasItem * colors_create_item (GnomeCanvasGroup *parent)
static void colors_destroy_all_items (void)
static void colors_next_level (void)
static gint item_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
static void save_table (gpointer key, gpointer value, gpointer user_data)
static void conf_ok (GHashTable *table)
static gboolean process_ok_timeout ()

Variables

static GcomprisBoard * gcomprisBoard = NULL
static gboolean board_paused = TRUE
static int gamewon
static GnomeCanvasGroup * boardRootItem = NULL
static GnomeCanvasItem * highlight_image_item = NULL
static int highlight_width
static int highlight_height
static GList * listColors = NULL
static gchar * colors [LAST_COLOR *2]
static int X [] = {75,212,242,368,414,533,578,709}
static int Y [] = {25,170,180,335,337,500}
static BoardPlugin menu_bp
static GcomprisProfileprofile_conf
static GcomprisBoard * board_conf

Define Documentation

#define LAST_COLOR   10

Definition at line 52 of file colors.c.

#define SOUNDLISTFILE   PACKAGE

Definition at line 22 of file colors.c.


Function Documentation

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

Definition at line 152 of file colors.c.

{
  board_conf = agcomprisBoard;
  profile_conf = aProfile;

  gchar *label;

  if (gcomprisBoard)
    pause_board(TRUE);

  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");

  g_hash_table_destroy(config);

}

Here is the call graph for this function:

static void colors_config_stop ( void  ) [static]

Definition at line 187 of file colors.c.

{
}
static GnomeCanvasItem * colors_create_item ( GnomeCanvasGroup *  parent) [static]

Definition at line 357 of file colors.c.

                                                                     {
  GdkPixbuf *highlight_pixmap = NULL;
  char *str = NULL;

  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));

  str = g_strdup_printf("%s/%s", gcomprisBoard->boarddir, "colors_highlight.png");
  highlight_pixmap = gc_pixmap_load(str);

  highlight_image_item = gnome_canvas_item_new (boardRootItem,
                                          gnome_canvas_pixbuf_get_type (),
                                          "pixbuf", highlight_pixmap,
                                          "x", (double) 0,
                                          "y", (double) 0,
                                          "width", (double) gdk_pixbuf_get_width(highlight_pixmap),
                                          "height", (double) gdk_pixbuf_get_height(highlight_pixmap),
                                          "width_set", TRUE,
                                          "height_set", TRUE,
                                          NULL);

  highlight_width = gdk_pixbuf_get_width(highlight_pixmap);
  highlight_height = gdk_pixbuf_get_height(highlight_pixmap);

  g_free(str);

  gnome_canvas_item_hide(highlight_image_item);

  gdk_pixbuf_unref(highlight_pixmap);

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void colors_destroy_all_items ( void  ) [static]

Definition at line 347 of file colors.c.

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

  boardRootItem = NULL;
}

Here is the caller graph for this function:

static void colors_next_level ( void  ) [static]

Definition at line 292 of file colors.c.

                                {
  colors_destroy_all_items();
  gamewon = FALSE;

  /* Try the next level */
  colors_create_item(gnome_canvas_root(gcomprisBoard->canvas));
  repeat();
}

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 118 of file colors.c.

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

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

  if (gcomprisBoard){
    GHashTable *config = gc_db_get_board_conf();

    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"));

    if (profile_conf)
      g_hash_table_destroy(config);

    colors_next_level();

    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 end_board ( void  ) [static]

Definition at line 259 of file colors.c.

                         {

  if(gcomprisBoard!=NULL){
    pause_board(TRUE);
    gc_score_end();
    colors_destroy_all_items();
    // free list
    while (g_list_length(listColors) > 0)
      listColors = g_list_remove(listColors, g_list_nth_data(listColors,0));
    g_list_free(listColors);
    listColors=NULL;
  }
  gc_locale_reset();
  gcomprisBoard = NULL;
  gc_sound_resume();
}

Here is the call graph for this function:

static void game_won ( void  ) [static]

Definition at line 396 of file colors.c.

                       {
  gcomprisBoard->sublevel++;

  listColors = g_list_remove(listColors, g_list_nth_data(listColors,0));

  if( g_list_length(listColors) <= 0 ) { // the current board is finished : bail out
    gc_bonus_end_display(BOARD_FINISHED_TUXLOCO);
    return;
  }

  colors_next_level();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void highlight_selected ( int  c) [static]

Definition at line 468 of file colors.c.

                                      {
  int x, y;

  g_assert(c>=0 && c<=9);

  if (c<8) {
    x = (X[(c%4)*2] + X[(c%4)*2+1]) /2;
    y = (Y[(int)(c/4)*2] + Y[(int)(c/4)*2+1]) /2;
  } else {
    y = (Y[4]+Y[5]) /2;
    if (c==8)
      x = (X[2] + X[3]) /2;
    else
      x = (X[4] + X[5]) /2;
  }
  x -= highlight_width/2;
  y -= highlight_height/2;
  gnome_canvas_item_show(highlight_image_item);
  gc_item_absolute_move(highlight_image_item, x, y);
}

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 279 of file colors.c.

                                                            {
  if (gcomprisBoard) {
    if(g_strcasecmp(gcomprisBoard->type, "colors")==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 424 of file colors.c.

                                                                              {
  double x, y;
  int i, j, clicked;

  x = event->button.x;
  y = event->button.y;

  if (!gcomprisBoard || board_paused)
    return FALSE;

  switch (event->type)
    {
    case GDK_BUTTON_PRESS:
      gnome_canvas_c2w(gcomprisBoard->canvas, x, y, &x, &y);
      clicked = -1;
      for (i=0; i<4; i++) {
       for (j=0; j<2; j++) {
         if (x>X[i*2] && x<X[i*2+1] && y>Y[j*2] && y<Y[j*2+1]) {
           clicked = j*4 + i;
         }
       }
      }
      if (x>X[2] && x<X[3] && y>Y[4] && y<Y[5])
       clicked = 8;
      if (x>X[4] && x<X[5] && y>Y[4] && y<Y[5])
       clicked = 9;

      if (clicked >= 0) {
       board_paused = TRUE;
       highlight_selected(clicked);
       gamewon = (clicked == GPOINTER_TO_INT(g_list_nth_data(listColors,0)));
        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 195 of file colors.c.

{
  if(gcomprisBoard==NULL)
    return;

  gc_bar_hide(FALSE);
  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 416 of file colors.c.

                         {
  gc_bar_hide(TRUE);
  // 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 411 of file colors.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 301 of file colors.c.

                     {

  if(gcomprisBoard!=NULL)
    {
      char *str  = NULL;
      GcomprisProperties *properties = gc_prop_get();

      str = g_strdup_printf("sounds/$LOCALE/colors/%s.ogg",
                         colors[GPOINTER_TO_INT(g_list_nth_data(listColors, 0))*2]);

      /* If we don't find a sound in our locale or the sounds are disabled */
      if(str && properties->fx)
       {
         gc_sound_play_ogg(str, NULL);
       }
      else
       {
         str = g_strdup_printf(gettext(colors[GPOINTER_TO_INT(g_list_nth_data(listColors, 0))*2+1]));

         gnome_canvas_item_new (boardRootItem,
                             gnome_canvas_text_get_type (),
                             "text", str,
                             "font", gc_skin_font_board_huge_bold,
                             "x", (double) BOARDWIDTH/2+2,
                             "y", (double) BOARDHEIGHT-25+2,
                             "anchor", GTK_ANCHOR_CENTER,
                             "fill_color", "black",
                             NULL);

         gnome_canvas_item_new (boardRootItem,
                             gnome_canvas_text_get_type (),
                             "text", str,
                             "font", gc_skin_font_board_huge_bold,
                             "x", (double) BOARDWIDTH/2,
                             "y", (double) BOARDHEIGHT-25,
                             "anchor", GTK_ANCHOR_CENTER,
                             "fill_color", "blue",
                             NULL);
       }

      g_free(str);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 107 of file colors.c.

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

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 210 of file colors.c.

                                                        {
  GcomprisProperties *properties = gc_prop_get();
  GList * list = NULL;
  int * item;
  int i;

  GHashTable *config = gc_db_get_board_conf();

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

  g_hash_table_destroy(config);

  gc_sound_pause();

  if(agcomprisBoard!=NULL) {
    gcomprisBoard=agcomprisBoard;
    gc_set_background(gnome_canvas_root(gcomprisBoard->canvas), "colors/colors_bg.png");
    gcomprisBoard->level=1;
    gcomprisBoard->maxlevel=1;

    if(properties->fx) {
      gc_bar_set(GC_BAR_CONFIG|GC_BAR_REPEAT);
    } else {
      gc_bar_set(GC_BAR_CONFIG);
    }

    gamewon = FALSE;

    // we generate a list of color indexes in a random order
    for (i=0; i<LAST_COLOR; i++)
      list = g_list_append(list, GINT_TO_POINTER(i));

    while ((g_list_length(list) > 0)) {
      i = RAND(0,g_list_length(list)-1);
      item = g_list_nth_data(list, i);
      listColors = g_list_append(listColors, item);
      list = g_list_remove(list, item);
    }
    g_list_free(list);

    gtk_signal_connect(GTK_OBJECT(gcomprisBoard->canvas), "event",  (GtkSignalFunc) item_event, NULL);
    colors_next_level();
    pause_board(FALSE);
  }
}

Here is the call graph for this function:


Variable Documentation

GcomprisBoard* board_conf [static]

Definition at line 105 of file colors.c.

gboolean board_paused = TRUE [static]

Definition at line 25 of file colors.c.

GnomeCanvasGroup* boardRootItem = NULL [static]

Definition at line 42 of file colors.c.

gchar* colors[LAST_COLOR *2] [static]
Initial value:
 {
  "blue",     N_("Click on the blue duck"),
  "brown",    N_("Click on the brown duck"),
  "green",    N_("Click on the green duck"),
  "grey",     N_("Click on the grey duck"),
  "orange",   N_("Click on the orange duck"),
  "purple",   N_("Click on the purple duck"),
  "red",      N_("Click on the red duck"),
  "yellow",   N_("Click on the yellow duck"),
  "black",    N_("Click on the black duck"),
  "white",    N_("Click on the white duck")
}

Definition at line 53 of file colors.c.

int gamewon [static]

Definition at line 31 of file colors.c.

GcomprisBoard* gcomprisBoard = NULL [static]

Definition at line 24 of file colors.c.

int highlight_height [static]

Definition at line 49 of file colors.c.

GnomeCanvasItem* highlight_image_item = NULL [static]

Definition at line 43 of file colors.c.

int highlight_width [static]

Definition at line 49 of file colors.c.

GList* listColors = NULL [static]

Definition at line 50 of file colors.c.

BoardPlugin menu_bp [static]
Initial value:
  {
    NULL,
    NULL,
    "Colors",
    "Click on the right color",
    "Pascal Georges <pascal.georges1@free.fr>",
    NULL,
    NULL,
    NULL,
    NULL,
    start_board,
    pause_board,
    end_board,
    is_our_board,
    NULL,
    NULL,
    NULL,
    NULL,
    repeat,
    colors_config_start,
    colors_config_stop
  }

Definition at line 70 of file colors.c.

Definition at line 104 of file colors.c.

int X[] = {75,212,242,368,414,533,578,709} [static]

Definition at line 66 of file colors.c.

int Y[] = {25,170,180,335,337,500} [static]

Definition at line 67 of file colors.c.