Commit 38192857 authored by Bruno Coudoin's avatar Bruno Coudoin

removed train goes faster and arrow issue cause its fixed. added much more

* TODO: removed train goes faster and arrow issue cause its fixed.
* boards/dataset/mrpatate.xml: added much more images. Now uses imageset.
* boards/watercycle.xml.in: changed help text
* src/boards/python/watercycle.py: little cleanup
* src/boards/read_colors.c: (start_board), (end_board): memory leak: added g_list_free
  where needed
  * src/gcompris/images_selector.c: (gcompris_images_selector_start),
  (gcompris_images_selector_stop), (display_image),
  (display_image_set), (free_stuff), (item_event_imageset_selector),
  (parseImage), (parse_doc), (read_xml_file): complete rework to support dataset in the xml
   file and display them.
parent d4e4e658
......@@ -64,10 +64,6 @@ se trompe de wagon, il faut recommencer au d
- Aussi, il y a un cas ou malgres qu'on mettes la bonne solution,
il ne trouve pas que c'est OK.
- dans le jeu du train, c'est très drôle de cliquer sur "replay" quand le
jeu montre le train, mais après, les trains vont de plus en plus vite, même
les trains suivants, et ça va beaucoup trop vite !
- si on ajoute beaucoup de wagons, ils dépassent de l'écran et on ne les
voit plus. Quand on enlève les wagons qui dépassent, il se passe des choses
bizarres : ils disparaissent tous en même temps !
......@@ -75,9 +71,6 @@ bizarres : ils disparaissent tous en m
- le bouton "dé" est beaucoup trop près des boutons "replay" et "pouce",
dont on se sert plus souvent.
- décidément, cette grosse flèche n'est pas pratique du tout pour cliquer
sur le wagon plein de voitures !
- dans le labyrinthe, quand on laisse le doigt appuyé sur la touche pour
aller vite à la sortie, Tux marche tout seul dans le labyrinthe suivant (il
faut vider le tampon du clavier au début du tableau)
......
<?xml version="1.0" encoding="UTF-8"?>
<GCompris>
<Board
name="mrpatate"
type="dataset"
icon="mrpatate/mrpatate_icon.png"
author="Bruno Coudoin (bruno.coudoin@free.fr)">
<title>Mister Patatoe</title>
<description>Mister Patatoe Image data set</description>
</Board>
<Image filename="mrpatate/barbe12.png"/>
<Image filename="mrpatate/barbe1.png"/>
<Image filename="mrpatate/body.png"/>
<Image filename="mrpatate/bouc1.png"/>
<Image filename="mrpatate/bouche1.png"/>
<Image filename="mrpatate/bouche2.png"/>
<Image filename="mrpatate/bouche3.png"/>
<Image filename="mrpatate/bouche4.png"/>
<Image filename="mrpatate/bouche9.png"/>
<Image filename="mrpatate/cheveux1.png"/>
<Image filename="mrpatate/cheveux2.png"/>
<Image filename="mrpatate/cheveux3.png"/>
<Image filename="mrpatate/cheveux4.png"/>
<Image filename="mrpatate/cheveux5.png"/>
<Image filename="mrpatate/cil1.png"/>
<Image filename="mrpatate/larme.png"/>
<Image filename="mrpatate/lunette1.png"/>
<Image filename="mrpatate/lunette1_sun.png"/>
<Image filename="mrpatate/lunette_girl.png"/>
<Image filename="mrpatate/lunette_girl_sun.png"/>
<Image filename="mrpatate/mousta1.png"/>
<Image filename="mrpatate/nez1.png"/>
<Image filename="gcompris/misc/egg.png"/>
<Image filename="gcompris/misc/peer.png"/>
<Image filename="mrpatate/noeye.png"/>
<Image filename="mrpatate/eyeball.png"/>
<Image filename="mrpatate/oeuil1.png"/>
<Image filename="mrpatate/oeuil2.png"/>
<Image filename="mrpatate/oeuil3.png"/>
<Image filename="mrpatate/oeuil4.png"/>
<Image filename="gcompris/misc/raquette.png"/>
<Image filename="gcompris/misc/flower.png"/>
<Image filename="imageid/cartable.png"/>
<Image filename="mrpatate/watch.png"/>
<Image filename="mrpatate/ear_jewell.png"/>
<Image filename="mrpatate/hat.png"/>
<Image filename="mrpatate/sherif.png"/>
</GCompris>
<ImageSetRoot>
<ImageSet filename="mrpatate/body.png">
<Image filename="mrpatate/barbe12.png"/>
<Image filename="mrpatate/barbe1.png"/>
<Image filename="mrpatate/body.png"/>
<Image filename="mrpatate/bouc1.png"/>
<Image filename="mrpatate/bouche1.png"/>
<Image filename="mrpatate/bouche2.png"/>
<Image filename="mrpatate/bouche3.png"/>
<Image filename="mrpatate/bouche4.png"/>
<Image filename="mrpatate/bouche9.png"/>
<Image filename="mrpatate/cheveux1.png"/>
<Image filename="mrpatate/cheveux2.png"/>
<Image filename="mrpatate/cheveux3.png"/>
<Image filename="mrpatate/cheveux4.png"/>
<Image filename="mrpatate/cheveux5.png"/>
<Image filename="mrpatate/cil1.png"/>
<Image filename="mrpatate/larme.png"/>
<Image filename="mrpatate/lunette1.png"/>
<Image filename="mrpatate/lunette1_sun.png"/>
<Image filename="mrpatate/lunette_girl.png"/>
<Image filename="mrpatate/lunette_girl_sun.png"/>
<Image filename="mrpatate/mousta1.png"/>
<Image filename="mrpatate/nez1.png"/>
<Image filename="gcompris/misc/egg.png"/>
<Image filename="gcompris/misc/peer.png"/>
<Image filename="mrpatate/noeye.png"/>
<Image filename="mrpatate/eyeball.png"/>
<Image filename="mrpatate/oeuil1.png"/>
<Image filename="mrpatate/oeuil2.png"/>
<Image filename="mrpatate/oeuil3.png"/>
<Image filename="mrpatate/oeuil4.png"/>
<Image filename="gcompris/misc/raquette.png"/>
<Image filename="gcompris/misc/flower.png"/>
<Image filename="imageid/cartable.png"/>
<Image filename="mrpatate/watch.png"/>
<Image filename="mrpatate/ear_jewell.png"/>
<Image filename="mrpatate/hat.png"/>
<Image filename="mrpatate/sherif.png"/>
<Image filename="gcompris/misc/tux.png"/>
<Image filename="gcompris/misc/parachute.png"/>
</ImageSet>
<ImageSet filename="gcompris/misc/car.png">
<Image filename="gcompris/misc/car.png"/>
<Image filename="gcompris/misc/minivan.png"/>
<Image filename="gcompris/misc/bicycle.png"/>
<Image filename="gcompris/misc/tuxboat.png"/>
<Image filename="gcompris/misc/fishingboat.png"/>
<Image filename="gcompris/misc/sailingboat.png"/>
<Image filename="gcompris/misc/fusee.png"/>
<Image filename="gcompris/misc/tuxhelico.png"/>
<Image filename="gcompris/misc/tuxloco.png"/>
<Image filename="gcompris/misc/tuxplane.png"/>
</ImageSet>
<ImageSet filename="gcompris/misc/house.png">
<Image filename="gcompris/misc/house.png"/>
<Image filename="gcompris/misc/lighthouse.png"/>
<Image filename="gcompris/misc/castle.png"/>
<Image filename="gcompris/misc/crown.png"/>
<Image filename="gcompris/misc/flowerpot.png"/>
<Image filename="gcompris/misc/eggpot.png"/>
<Image filename="gcompris/misc/football.png"/>
<Image filename="gcompris/misc/glass.png"/>
<Image filename="gcompris/misc/lamp.png"/>
<Image filename="gcompris/misc/light.png"/>
<Image filename="gcompris/misc/pencil.png"/>
<Image filename="gcompris/misc/plane.png"/>
<Image filename="gcompris/misc/postcard.png"/>
<Image filename="gcompris/misc/postpoint.png"/>
<Image filename="gcompris/misc/rape.png"/>
<Image filename="gcompris/misc/raquette.png"/>
<Image filename="gcompris/misc/sofa.png"/>
</ImageSet>
<ImageSet filename="gcompris/misc/apple.png">
<Image filename="gcompris/misc/apple.png"/>
<Image filename="gcompris/misc/peer.png"/>
<Image filename="gcompris/misc/carot.png"/>
<Image filename="gcompris/misc/bottle.png"/>
<Image filename="gcompris/misc/cerise.png"/>
<Image filename="gcompris/misc/cocotier.png"/>
<Image filename="gcompris/misc/cloud.png"/>
<Image filename="gcompris/misc/star.png"/>
<Image filename="gcompris/misc/egg.png"/>
<Image filename="gcompris/misc/flower.png"/>
<Image filename="gcompris/misc/sapin.png"/>
<Image filename="gcompris/misc/tree.png"/>
<Image filename="gcompris/misc/strawberry.png"/>
</ImageSet>
</ImageSetRoot>
......@@ -9,11 +9,13 @@
author="Bruno Coudoin (bruno.coudoin@free.fr)"
boarddir="watercycle">
<_title>Learn the water cycle</_title>
<_description>You have to bring back the water system up before Tux goes home</_description>
<_description>You have to bring back the water system up.
Tux comes from a long fishing party on his boat. Help him to have a shower.</_description>
<_prerequisite></_prerequisite>
<_goal>Learn the water cycle</_goal>
<_manual>Click on different active elements : sun, cloud, water pump station,
water cleanup station in order to reactivate the whole
water system.</_manual>
water system.
When done and Tux is in his shower, push the shower button for him.</_manual>
</Board>
</GCompris>
......@@ -13,7 +13,6 @@ class Gcompris_watercycle:
def __init__(self, gcomprisBoard):
self.gcomprisBoard = gcomprisBoard
self.canvasitems = {}
print("Gcompris_watercycle __init__.")
......
......@@ -154,8 +154,9 @@ static void start_board (GcomprisBoard *agcomprisBoard) {
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);
gtk_signal_connect(GTK_OBJECT(gcomprisBoard->canvas), "event", (GtkSignalFunc) item_event, NULL);
read_colors_next_level();
pause_board(FALSE);
}
......@@ -173,6 +174,9 @@ static void end_board () {
// 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;
}
gcomprisBoard = NULL;
}
......
/* gcompris - images_selector.c
*
* Time-stamp: <2003/02/16 23:21:10 bruno>
* Time-stamp: <2003/10/20 01:23:17 bcoudoin>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -35,12 +35,17 @@
static gint item_event_images_selector(GnomeCanvasItem *item,
GdkEvent *event,
gpointer data);
static gint item_event_imageset_selector(GnomeCanvasItem *item,
GdkEvent *event,
gpointer data);
static gboolean read_xml_file(gchar *fname);
static void display_image(gchar *imagename);
static void display_image(gchar *imagename, GnomeCanvasItem *rootitem);
static void free_stuff (GtkObject *obj, GList *data);
static gboolean images_selector_displayed = FALSE;
static GnomeCanvasItem *rootitem = NULL;
static GnomeCanvasItem *current_root_set = NULL;
static GnomeCanvasItem *item_content = NULL;
static ImageSelectorCallBack imageSelectorCallBack = NULL;
......@@ -64,10 +69,9 @@ static ImageSelectorCallBack imageSelectorCallBack = NULL;
#define IMAGE_WIDTH (DRAWING_AREA_X2-DRAWING_AREA_X1)/HORIZONTAL_NUMBER_OF_IMAGE-IMAGE_GAP
#define IMAGE_HEIGHT (DRAWING_AREA_Y2-DRAWING_AREA_Y1)/VERTICAL_NUMBER_OF_IMAGE-IMAGE_GAP
static GList *imagelist; /* List of Images */
static guint ix = DRAWING_AREA_X1;
static guint iy = DRAWING_AREA_Y1;
static guint ix = DRAWING_AREA_X1;
static guint iy = DRAWING_AREA_Y1;
static guint isy = DRAWING_AREA_Y1;
/*
* Main entry point
......@@ -125,7 +129,7 @@ void gcompris_images_selector_start (GcomprisBoard *gcomprisBoard, gchar *datase
y_start += 110;
pixmap = gcompris_load_skin_pixmap("button_large_selected.png");
pixmap = gcompris_load_skin_pixmap("button_large.png");
// OK
......@@ -163,15 +167,13 @@ void gcompris_images_selector_start (GcomprisBoard *gcomprisBoard, gchar *datase
images_selector_displayed = TRUE;
/* Initial image position */
ix = DRAWING_AREA_X1;
iy = DRAWING_AREA_Y1;
ix = DRAWING_AREA_X1;
iy = DRAWING_AREA_Y1;
isy = DRAWING_AREA_Y1;
/* Read the given data set */
read_xml_file(dataset);
/* Display the images */
g_list_foreach (imagelist, (GFunc) display_image, NULL);
}
/*
......@@ -196,9 +198,7 @@ void gcompris_images_selector_stop ()
gtk_object_destroy(GTK_OBJECT(rootitem));
}
rootitem = NULL;
g_list_free(imagelist);
imagelist=NULL;
current_root_set = NULL;
gcompris_bar_hide(FALSE);
images_selector_displayed = FALSE;
......@@ -211,7 +211,7 @@ void gcompris_images_selector_stop ()
/*-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------*/
static void display_image(gchar *imagename)
static void display_image(gchar *imagename, GnomeCanvasItem *root_item)
{
GdkPixbuf *pixmap = NULL;
......@@ -222,7 +222,6 @@ static void display_image(gchar *imagename)
if (imagename==NULL)
return;
pixmap = gcompris_load_pixmap(imagename);
iw = IMAGE_WIDTH;
......@@ -233,7 +232,7 @@ static void display_image(gchar *imagename)
yratio = (double) (((double)gdk_pixbuf_get_height(pixmap))/ih);
xratio = MAX(yratio,xratio);
item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(root_item),
gnome_canvas_pixbuf_get_type (),
"pixbuf", pixmap,
"x", (double)ix,
......@@ -260,6 +259,130 @@ static void display_image(gchar *imagename)
}
}
/*
* Same as display_image but for the dataset
* The imagelist contains the list of images to be displayed when this dataset is selected
*/
static void display_image_set(gchar *imagename, GList *imagelist)
{
GdkPixbuf *pixmap = NULL;
GnomeCanvasItem *item;
GnomeCanvasItem *rootitem_set;
double xratio, yratio;
double iw, ih;
if (imagename==NULL)
return;
pixmap = gcompris_load_pixmap(imagename);
iw = IMAGE_WIDTH;
ih = IMAGE_HEIGHT;
/* Calc the max to resize width or height */
xratio = (double) (((double)gdk_pixbuf_get_width(pixmap))/iw);
yratio = (double) (((double)gdk_pixbuf_get_height(pixmap))/ih);
xratio = MAX(yratio,xratio);
item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
gnome_canvas_pixbuf_get_type (),
"pixbuf", pixmap,
"x", (double)20,
"y", (double)isy,
"width", (double) gdk_pixbuf_get_width(pixmap)/xratio,
"height", (double) gdk_pixbuf_get_height(pixmap)/xratio,
"width_set", TRUE,
"height_set", TRUE,
NULL);
gdk_pixbuf_unref(pixmap);
g_object_set_data (G_OBJECT (item), "imagelist", imagelist);
gtk_signal_connect(GTK_OBJECT(item), "event",
(GtkSignalFunc) item_event_imageset_selector,
imagename);
gtk_signal_connect(GTK_OBJECT(item), "event",
(GtkSignalFunc) gcompris_item_event_focus,
NULL);
isy+=IMAGE_HEIGHT + IMAGE_GAP;
/* Create a root item to put the image list in it */
rootitem_set = \
gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
gnome_canvas_group_get_type (),
"x", (double)0,
"y", (double)0,
NULL);
g_object_set_data (G_OBJECT (item), "rootitem", rootitem_set);
g_object_set_data (G_OBJECT (item), "imageset_done", GINT_TO_POINTER (0));
g_signal_connect (item, "destroy",
G_CALLBACK (free_stuff),
imagelist);
}
static void
free_stuff (GtkObject *obj, GList *list)
{
while (g_list_length(list) > 0) {
g_free(g_list_nth_data(list,0));
list = g_list_remove(list, g_list_nth_data(list,0));
}
g_list_free(list);
}
/* Callback when an image set is selected */
static gint
item_event_imageset_selector(GnomeCanvasItem *item, GdkEvent *event, gpointer data)
{
GList *image_list;
GnomeCanvasItem *rootitem_set;
guint imageset_done;
switch (event->type)
{
case GDK_ENTER_NOTIFY:
break;
case GDK_LEAVE_NOTIFY:
break;
case GDK_BUTTON_PRESS:
{
/* We must display the list of images for this set */
image_list = (GList *)g_object_get_data (G_OBJECT (item), "imagelist");
g_return_if_fail (image_list != NULL);
/* We must display the list of images for this set */
rootitem_set = (GList *)g_object_get_data (G_OBJECT (item), "rootitem");
g_return_if_fail (rootitem_set != NULL);
imageset_done = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "imageset_done"));
/* Hide the previous image set if any */
if (current_root_set != NULL) {
gnome_canvas_item_hide(current_root_set);
}
/* Not yet displayed this set */
if(!imageset_done) {
g_list_foreach (image_list, (GFunc) display_image, rootitem_set);
g_object_set_data (G_OBJECT (item), "imageset_done", GINT_TO_POINTER (1));
}
gnome_canvas_item_show(rootitem_set);
current_root_set = rootitem_set;
/* Back to the initial image position */
ix = DRAWING_AREA_X1;
iy = DRAWING_AREA_Y1;
}
default:
break;
}
return FALSE;
}
/* Callback when an image is selected */
static gint
item_event_images_selector(GnomeCanvasItem *item, GdkEvent *event, gpointer data)
......@@ -290,45 +413,52 @@ item_event_images_selector(GnomeCanvasItem *item, GdkEvent *event, gpointer data
}
/*
* Thanks for George Lebl <jirka@5z.com> for his Genealogy example
* for all the XML stuff there
*/
void
parseImage (xmlDocPtr doc, xmlNodePtr cur) {
gchar *imageSetName = NULL;
gchar *filename;
GList *imageList = NULL; /* List of Images */
/* get the filename of this ImageSet */
imageSetName = xmlGetProp(cur,"filename");
cur = cur->xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur->name, (const xmlChar *)"Image"))) {
/* get the filename of this ImageSet */
filename = xmlGetProp(cur,"filename");
imageList = g_list_append (imageList, filename);
}
cur = cur->next;
}
static void
add_image(xmlNodePtr xmlnode, GNode * child)
{
char *filename;
display_image_set(imageSetName, imageList);
if(/* if the node has no name */
!xmlnode->name ||
/* or if the name is not "Data" */
(g_strcasecmp(xmlnode->name,"Image")!=0)
)
return;
/* get the filename of this data */
filename = xmlGetProp(xmlnode,"filename");
imagelist = g_list_append (imagelist, filename);
return;
}
/* parse the doc, add it to our internal structures and to the clist */
static void
parse_doc(xmlDocPtr doc)
{
xmlNodePtr node;
/* find <Shape> nodes and add them to the list, this just
loops through all the children of the root of the document */
for(node = doc->children->children; node != NULL; node = node->next) {
/* add the shape to the list, there are no children so
we pass NULL as the node of the child */
add_image(node,NULL);
parse_doc(xmlDocPtr doc) {
xmlNodePtr cur;
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
fprintf(stderr,"empty document\n");
xmlFreeDoc(doc);
return;
}
}
cur = cur->xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur->name, (const xmlChar *)"ImageSet"))){
parseImage (doc, cur);
}
cur = cur->next;
}
return;
}
/* read an xml file into our memory structures and update our view,
......@@ -359,8 +489,8 @@ read_xml_file(gchar *fname)
!doc->children ||
/* if it doesn't have a name */
!doc->children->name ||
/* if it isn't a GCompris node */
g_strcasecmp(doc->children->name,"GCompris")!=0) {
/* if it isn't the good node */
g_strcasecmp(doc->children->name,"ImageSetRoot")!=0) {
xmlFreeDoc(doc);
return FALSE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment