Back to index

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

Go to the source code of this file.

Defines

#define SOUNDLISTFILE   PACKAGE
#define MAX_LAYERS   3
#define NORMAL   0
#define CLIC   1
#define DOUBLECLIC   2
#define NUMBER_OF_IMAGES   G_N_ELEMENTS(imageList)

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 game_won (void)
static GnomeCanvasItem * erase_create_item (int layer)
static void erase_destroy_all_items (void)
static void erase_next_level (void)
static gint item_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
static void shuffle_image_list (char *list[], int size)
 shuffle_image_list, takes a char* array and it's length.
static void bonus ()
static void finished ()

Variables

static GcomprisBoard * gcomprisBoard = NULL
static gboolean board_paused = TRUE
static int gamewon
static GnomeCanvasGroup * boardRootItem = NULL
static int number_of_item = 0
static int number_of_item_x = 0
static int number_of_item_y = 0
static gint timer_id = 0
static gint DefaultDoubleClicDistance
static gint DoubleClicLevel [6] = { 1000, 750, 600, 500, 400, 250}
static gint board_mode = NORMAL
static gchar * imageList []
static int current_image
static BoardPlugin menu_bp

Define Documentation

#define CLIC   1

Definition at line 58 of file erase.c.

#define DOUBLECLIC   2

Definition at line 59 of file erase.c.

#define MAX_LAYERS   3

Definition at line 25 of file erase.c.

#define NORMAL   0

Definition at line 57 of file erase.c.

#define NUMBER_OF_IMAGES   G_N_ELEMENTS(imageList)

Definition at line 103 of file erase.c.

#define SOUNDLISTFILE   PACKAGE

Definition at line 24 of file erase.c.


Function Documentation

static void bonus ( ) [static]

Definition at line 394 of file erase.c.

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 215 of file erase.c.

{
  if (board_mode == DOUBLECLIC){
    gdk_display_set_double_click_time( gdk_display_get_default(),
                                      DefaultDoubleClicDistance);
    g_warning("Double click value is now %d.",DefaultDoubleClicDistance);
  }
  if(gcomprisBoard!=NULL)
    {
      pause_board(TRUE);
      gc_score_end();
      erase_destroy_all_items();
    }
  gcomprisBoard = NULL;
}

Here is the call graph for this function:

static GnomeCanvasItem * erase_create_item ( int  layer) [static]

Definition at line 323 of file erase.c.

{
  int i,j;
  int ix, jy;
  GnomeCanvasItem *item = NULL;
  GdkPixbuf *pixmap[MAX_LAYERS];

  g_assert(layer<=MAX_LAYERS);

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

  number_of_item = 0;

  for(i=0; i<MAX_LAYERS; i++)
    pixmap[i] = NULL;

  if(layer>0)
    pixmap[0] = gc_pixmap_load("images/transparent_square.png");

  if(layer>1)
    pixmap[1] = gc_pixmap_load("images/water_spot.png");

  if(layer>2)
    pixmap[2] = gc_pixmap_load("images/water_drop.png");

  for(i=0,ix=0; i<BOARDWIDTH; i+=BOARDWIDTH/number_of_item_x, ix++)
    {
      for(j=0, jy=0; j<BOARDHEIGHT; j+=BOARDHEIGHT/number_of_item_y, jy++)
       {
         int current_layer = layer;

         if ((board_mode != NORMAL) && ((ix+jy) %2 == 0))
           continue;

         while(current_layer--)
           {
             double w = (BOARDWIDTH/number_of_item_x) *  (1.0 - (0.3 * current_layer));
             double h = (BOARDHEIGHT/number_of_item_y) * (1.0 - (0.3 * current_layer));
             double x = i + ((BOARDWIDTH/number_of_item_x)  - w) / 2;
             double y = j + ((BOARDHEIGHT/number_of_item_y) - h) / 2;

             item = gnome_canvas_item_new (boardRootItem,
                                       gnome_canvas_pixbuf_get_type (),
                                       "pixbuf", pixmap[current_layer],
                                       "x", x,
                                       "y", y,
                                       "width", w,
                                       "height", h,
                                       "width_set", TRUE,
                                       "height_set", TRUE,
                                       "anchor", GTK_ANCHOR_NW,
                                       NULL);

             gtk_signal_connect(GTK_OBJECT(item), "event", (GtkSignalFunc) item_event, NULL);
             number_of_item++;
           }
       }
    }

  for(i=0; i<MAX_LAYERS; i++)
    if(pixmap[i])
      gdk_pixbuf_unref(pixmap[i]);

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void erase_destroy_all_items ( void  ) [static]

Definition at line 310 of file erase.c.

{
  if (timer_id) {
    gtk_timeout_remove (timer_id);
    timer_id = 0;
  }

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

  boardRootItem = NULL;
}

Here is the caller graph for this function:

static void erase_next_level ( void  ) [static]

Definition at line 267 of file erase.c.

{
  int layers = 1;

  gc_set_background(gnome_canvas_root(gcomprisBoard->canvas),
                       imageList[current_image++]);

  if(current_image>=NUMBER_OF_IMAGES)
    current_image=0;

  gc_bar_set_level(gcomprisBoard);

  erase_destroy_all_items();
  gamewon = FALSE;

  /* Select level difficulty */

  if (board_mode != NORMAL) {
    number_of_item_x = 5;
    number_of_item_y = 5;
  } else {
    number_of_item_x = ((gcomprisBoard->level+1)%2+1)*5;
    number_of_item_y = ((gcomprisBoard->level+1)%2+1)*5;
  }

  /* Select the number of layer depending on the level */

  if (board_mode != DOUBLECLIC){
    if(gcomprisBoard->level>4)
      layers = 3;
    else if(gcomprisBoard->level>2)
      layers = 2;
  }

  /* Try the next level */
  erase_create_item(layers);

  gc_score_set(gcomprisBoard->sublevel);

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void finished ( ) [static]

Definition at line 399 of file erase.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void game_won ( void  ) [static]

Definition at line 405 of file erase.c.

{
  gcomprisBoard->sublevel++;
  gc_score_set(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
      timer_id = gtk_timeout_add (2000, (GtkFunction) finished, NULL);
      return;
    }
    if (board_mode == DOUBLECLIC){
      gdk_display_set_double_click_time( gdk_display_get_default(),
                                    DoubleClicLevel[gcomprisBoard->level-1]);
      g_warning("Double click value is now %d.", DoubleClicLevel[gcomprisBoard->level-1]);
    }

    gc_sound_play_ogg ("sounds/bonus.ogg", NULL);
  }
  erase_next_level();
}

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 249 of file erase.c.

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

{

  if(board_paused)
    return FALSE;

  if (event->type == GDK_MOTION_NOTIFY)
    return FALSE;

  if (board_mode == NORMAL)
    if (event->type != GDK_ENTER_NOTIFY)
      return FALSE;

  if (board_mode == CLIC)
    if (event->type != GDK_BUTTON_PRESS)
      return FALSE;

  if (board_mode == DOUBLECLIC)
    if ((event->type != GDK_BUTTON_PRESS) &
       (event->type != GDK_2BUTTON_PRESS) &
       (event->type != GDK_BUTTON_RELEASE))
      return FALSE;


  if (board_mode == DOUBLECLIC){
    if (event->type == GDK_BUTTON_PRESS){
      return FALSE;
    }
    if (event->type == GDK_BUTTON_RELEASE){
      return FALSE;
    }
  }

  gtk_object_destroy(GTK_OBJECT(item));

  if(--number_of_item == 0)
    {
      gamewon = TRUE;
      erase_destroy_all_items();
      timer_id = gtk_timeout_add (4000, (GtkFunction) bonus, NULL);
    }

  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 145 of file erase.c.

{
  if(gcomprisBoard==NULL)
    return;

  if (timer_id) {
    gtk_timeout_remove (timer_id);
    timer_id = 0;
  }

  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 set_level ( guint  level) [static]

Definition at line 232 of file erase.c.

{

  if(gcomprisBoard!=NULL)
    {
      gcomprisBoard->level=level;
      gcomprisBoard->sublevel=1;
      erase_next_level();
    }
  if (board_mode == DOUBLECLIC){
    gdk_display_set_double_click_time( gdk_display_get_default(),
                                   DoubleClicLevel[gcomprisBoard->level-1]);
    g_warning("Double click value is now %d.",DoubleClicLevel[gcomprisBoard->level-1]);
  }

}

Here is the call graph for this function:

void shuffle_image_list ( char *  list[],
int  size 
) [static]

shuffle_image_list, takes a char* array and it's length.

    it swaps a random number of items in it in order to provide
    the same list but in a random order.
Parameters:
list,:the array to shuffle
size,:the size of the array

Definition at line 484 of file erase.c.

{
  int i;

  for(i=0; i<size; i++)
    {
      int random1 = RAND(0, size-1);
      int random2 = RAND(0, size-1);
      char *olditem;

      olditem = list[random2];
      list[random2] = list[random1];
      list[random1] = olditem;
    }
}

Here is the caller graph for this function:

static void start_board ( GcomprisBoard *  agcomprisBoard) [static]

Definition at line 165 of file erase.c.

{

  if(agcomprisBoard!=NULL)
    {
      gcomprisBoard=agcomprisBoard;
      gcomprisBoard->level=1;
      gcomprisBoard->maxlevel=6;
      gcomprisBoard->sublevel=1;
      gcomprisBoard->number_of_sublevel=10; /* Go to next level after this number of 'play' */
      gc_score_start(SCORESTYLE_NOTE,
                        gcomprisBoard->width - 220,
                        gcomprisBoard->height - 50,
                        gcomprisBoard->number_of_sublevel);
      gc_bar_set(GC_BAR_LEVEL);

      if (strcmp(gcomprisBoard->mode,"double_clic")==0)
       board_mode = DOUBLECLIC;
      else if (strcmp(gcomprisBoard->mode,"clic")==0)
       board_mode = CLIC;
      else
       board_mode = NORMAL;

      if (board_mode == DOUBLECLIC){
       GtkSettings *DefaultsGtkSettings = gtk_settings_get_default ();

       if (DefaultsGtkSettings == NULL) {
         g_warning("Couldn't get GTK settings");
       } else {
         g_object_get(G_OBJECT(DefaultsGtkSettings),
                     "gtk-double-click-time", &DefaultDoubleClicDistance, NULL);

         g_warning("Double-click default value %d.",DefaultDoubleClicDistance);
       }

       gdk_display_set_double_click_time( gdk_display_get_default(),
                                      DoubleClicLevel[gcomprisBoard->level-1]);
       g_warning("Double-click value is now %d.",DoubleClicLevel[gcomprisBoard->level-1]);
      }

      current_image = 0;
      shuffle_image_list(imageList, NUMBER_OF_IMAGES);

      erase_next_level();

      gamewon = FALSE;
      pause_board(FALSE);
    }
}

Here is the call graph for this function:


Variable Documentation

gint board_mode = NORMAL [static]

Definition at line 61 of file erase.c.

gboolean board_paused = TRUE [static]

Definition at line 28 of file erase.c.

GnomeCanvasGroup* boardRootItem = NULL [static]

Definition at line 38 of file erase.c.

int current_image [static]

Definition at line 106 of file erase.c.

Definition at line 53 of file erase.c.

gint DoubleClicLevel[6] = { 1000, 750, 600, 500, 400, 250} [static]

Definition at line 55 of file erase.c.

int gamewon [static]

Definition at line 35 of file erase.c.

GcomprisBoard* gcomprisBoard = NULL [static]

Definition at line 27 of file erase.c.

gchar* imageList[] [static]

Definition at line 64 of file erase.c.

BoardPlugin menu_bp [static]
Initial value:
  {
    NULL,
    NULL,
    N_("Move the mouse"),
    N_("Move the mouse to erase the area and discover the background"),
    "Bruno Coudoin <bruno.coudoin@free.fr>",
    NULL,
    NULL,
    NULL,
    NULL,
    start_board,
    pause_board,
    end_board,
    is_our_board,
    NULL,
    NULL,
    set_level,
    NULL,
    NULL,
    NULL,
    NULL
  }

Definition at line 109 of file erase.c.

int number_of_item = 0 [static]

Definition at line 46 of file erase.c.

int number_of_item_x = 0 [static]

Definition at line 47 of file erase.c.

int number_of_item_y = 0 [static]

Definition at line 48 of file erase.c.

gint timer_id = 0 [static]

Definition at line 50 of file erase.c.