Back to index

gcompris  8.2.2
Classes | Functions
anim.h File Reference
#include "gcompris.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  GcomprisAnimation
 Defines an animation object. More...
struct  GcomprisAnimCanvasItem

Functions

GcomprisAnimationgc_anim_load (char *filename)
GcomprisAnimCanvasItemgc_anim_activate (GnomeCanvasGroup *parent, GcomprisAnimation *)
void gc_anim_set_state (GcomprisAnimCanvasItem *, int)
void gc_anim_deactivate (GcomprisAnimCanvasItem *)
void gc_anim_free (GcomprisAnimation *)
void gc_anim_swap (GcomprisAnimCanvasItem *item, GcomprisAnimation *new_anim)

Class Documentation

struct GcomprisAnimation

Defines an animation object.

This structure is opaque and should not be accessed directly.

Definition at line 30 of file anim.h.

Class Members
GdkPixbufAnimation ** anim
int numstates
struct GcomprisAnimCanvasItem

Definition at line 35 of file anim.h.

Collaboration diagram for GcomprisAnimCanvasItem:
Class Members
GcomprisAnimation * anim
GnomeCanvasPixbuf * canvas
GdkPixbufAnimationIter * iter
int state

Function Documentation

GcomprisAnimCanvasItem* gc_anim_activate ( GnomeCanvasGroup *  parent,
GcomprisAnimation  
)

Definition at line 91 of file anim.c.

{
  GcomprisAnimCanvasItem *item = g_malloc(sizeof(GcomprisAnimCanvasItem));

  item->state = 0;
  item->anim = anim;
  item->iter = gdk_pixbuf_animation_get_iter(anim->anim[0], NULL);
  item->canvas = (GnomeCanvasPixbuf*) gnome_canvas_item_new(
                            parent,
                            GNOME_TYPE_CANVAS_PIXBUF,
                            "pixbuf",
                            gdk_pixbuf_animation_iter_get_pixbuf(item->iter),
                            NULL);

  if(active == NULL)
      g_timeout_add(TICK_TIME, (GSourceFunc)anim_tick, NULL);

  active = g_slist_append(active, item);
  return item;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 121 of file anim.c.

{
  GSList *node = g_slist_find( active, item );
  if( !node )
  {
    g_critical( "Tried to deactive non-existant animation" );
    return;
  }

  if (GNOME_IS_CANVAS_ITEM(item->canvas)){
    gtk_object_destroy(GTK_OBJECT(item->canvas));
    item->canvas = NULL;
  }

  active = g_slist_delete_link(active, node);
  g_object_unref(item->iter);
  g_free(item);
}

Here is the caller graph for this function:

Definition at line 141 of file anim.c.

{
  int i;
  for(i=0; i<anim->numstates; i++)
    {
      g_object_unref(anim->anim[i]);
    }
  g_free(anim->anim);
  g_free(anim);
}

Here is the caller graph for this function:

GcomprisAnimation* gc_anim_load ( char *  filename)

Definition at line 34 of file anim.c.

{
  FILE *f = NULL;

  gchar *absolute_filename;

  absolute_filename = gc_file_find_absolute(filename);

  if (absolute_filename){
    f = g_fopen(absolute_filename, "r");
    g_free(absolute_filename);
  }

  if(!f)
    {
      g_warning("Couldn't open animation-spec file '%s'\n", filename);
      return NULL;
    }

  char tmp[100];
  GSList *files = NULL;
  GcomprisAnimation *anim = NULL;

  /* read filenames, one per line, from the animation spec-file */
  while(fscanf(f, "%99s", tmp) == 1)
    {
      GcomprisBoard   *gcomprisBoard = gc_board_get_current();
      files = g_slist_append(files, 
                             g_strdup_printf("%s/%s", gcomprisBoard->board_dir, tmp));
    }
  fclose(f);
  anim = g_malloc(sizeof(GcomprisAnimation));
  anim->numstates = g_slist_length(files);
  anim->anim = g_malloc(sizeof(GdkPixbuf*) * anim->numstates);

  /* open the animations and assign them */
  GError *error = NULL;
  GSList *cur;
  char *name;
  int i;
  for(cur=files, i=0; cur; cur = g_slist_next(cur), i++)
    {
      name = (char*) cur->data;
      anim->anim[i] = gdk_pixbuf_animation_new_from_file(name, &error);
      g_warning("Opened animation %s\n", name);
      if(!anim->anim[i])
        {
          g_critical("Couldn't open animation %s: %s\n", name, error->message);
          return NULL;
        }
      g_free(name);
    }
  g_slist_free(files);
  return anim;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_anim_set_state ( GcomprisAnimCanvasItem ,
int   
)

Definition at line 153 of file anim.c.

{
  if(state < item->anim->numstates)
    {
      item->state = state;
    }
  else
    {
      item->state = 0;
    }
  g_object_unref( item->iter );
  item->iter = gdk_pixbuf_animation_get_iter( item->anim->anim[item->state],
                                              NULL );
  gnome_canvas_item_set( (GnomeCanvasItem*)item->canvas, "pixbuf",
                         gdk_pixbuf_animation_iter_get_pixbuf(item->iter),
                         NULL);
}

Here is the caller graph for this function:

void gc_anim_swap ( GcomprisAnimCanvasItem item,
GcomprisAnimation new_anim 
)

Definition at line 114 of file anim.c.

{
  item->anim = new_anim;
  gc_anim_set_state(item, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function: