[gcompris-devel] shapegame patch

Ehreth Imre imre.ehreth at sysdata.siemens.hu
Wed Apr 3 02:54:02 UTC 2002


Hello

  I promised I will hunt problems. I have found some (possible) in
shapegame:

  * The closest target is not always correct. (There was a typo in
find_closest_shape)

  * When in the puzzle board a piece of puzzle is grabbed, the image is
made smaller but by leaving its center at the target point. So the
pointer is far from the image and when the closest target is looked up
the position of the pointer is checked. This can be misleading for small
childrens. I have made modifications to place the picture under the
pointer. (I have made this only for images)

I have created and attached a patch against the latest version found at
anoncvs. If you like it please apply it.

Beast regards
   Imre Ehreth

PS: I hope I will have time to make Hungarian translation

-------------- next part --------------
--- src/boards/shapegame.c	Wed Apr  3 14:53:31 2002
+++ src/boards/shapegame.c.new	Wed Apr  3 14:51:24 2002
@@ -552,7 +552,7 @@
 static Shape *find_closest_shape(double x, double y, double limit)
 {
   GList *list;
-  double goodDist = limit;
+  double goodDist = powf(limit,2);
   Shape *candidateShape = NULL;
 
   /* loop through all our shapes */
@@ -563,7 +563,7 @@
     if(shape->type==SHAPE_TARGET)
       {
 	/* Calc the distance between this shape and the given coord */
-	dist = sqrtf(powf((shape->x-x),2)*powf((shape->y-y),2));
+	dist = powf((shape->x-x),2) + powf((shape->y-y),2);
 	
 	if(dist<goodDist)
 	  {
@@ -646,6 +646,9 @@
 	     {
 	       x = item_x;
 	       y = item_y;
+
+	       item_x = shape->x;
+	       item_y = shape->y;
 	       
 	       switch(shape->type)
 		 {
@@ -656,7 +659,14 @@
 		   if( shape->icon_shape!=NULL)
 		     {
 		       item = shape->icon_shape->item;
-		       gnome_canvas_item_show(item);
+		       item_x = x - (x - shape->x) * shape->icon_shape->w /
+			  shape->w;
+		       item_y = y - (y - shape->y) * shape->icon_shape->h /
+			  shape->h;
+		       gnome_canvas_item_move( item,
+					       item_x - shape->x,
+					       item_y - shape->y );
+		       gnome_canvas_item_show( item );
 		       gcompris_set_image_focus(item, TRUE);
 		       shape->icon_shape=NULL;
 		     }
@@ -665,8 +675,8 @@
 		   break;
 		 }
 	       /* This records the offset between the mouse pointer and the grabbed item center */
-	       offset_x = x - shape->x;
-	       offset_y = y - shape->y;
+	       offset_x = x - item_x;
+	       offset_y = y - item_y;
 	       
 	       if(item==NULL)
 		 return FALSE;
@@ -946,17 +956,16 @@
       if(strcmp(shape->targetfile, UNDEFINED)!=0)
 	{
 	  targetpixmap = gcompris_load_pixmap(shape->targetfile);
+	  shape->w = (double)gdk_pixbuf_get_width(targetpixmap) * shape->zoomx;
+	  shape->h = (double)gdk_pixbuf_get_height(targetpixmap) *shape->zoomy;
+	  
 	  item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(shape_root_item),
 					gnome_canvas_pixbuf_get_type (),
 					"pixbuf", targetpixmap, 
-					"x", (double)shape->x - 
-					(gdk_pixbuf_get_width(targetpixmap) * shape->zoomx)/2,
-					"y", (double)shape->y -
-					(gdk_pixbuf_get_height(targetpixmap) * shape->zoomy)/2,
-					"width", (double) gdk_pixbuf_get_width(targetpixmap) 
-					* shape->zoomx,
-					"height", (double) gdk_pixbuf_get_height(targetpixmap) 
-					* shape->zoomy,
+					"x", shape->x - shape->w / 2,
+					"y", shape->y - shape->h / 2,
+					"width",  shape->w,
+					"height", shape->h,
 					"width_set", TRUE, 
 					"height_set", TRUE,
 					NULL);
@@ -1002,16 +1011,19 @@
 	  printf("  Yes it is an image \n");
 	  pixmap = gcompris_load_pixmap(shape->pixmapfile);
 	  if(pixmap)
-	    {	
+	    {
+	      shape->w = (double)gdk_pixbuf_get_width(pixmap) * shape->zoomx;
+	      shape->h = (double)gdk_pixbuf_get_height(pixmap) * shape->zoomy;
+	       
 	      /* Display the shape itself but hide it until the user puts the right shape on it */
 	      /* I have to do it this way for the positionning (lower/raise) complexity          */
 	      item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(shape_root_item),
 					    gnome_canvas_pixbuf_get_type (),
 					    "pixbuf", pixmap, 
-					    "x", (double)shape->x-(gdk_pixbuf_get_width(pixmap) * shape->zoomx)/2,
-					    "y", (double)shape->y-(gdk_pixbuf_get_height(pixmap) * shape->zoomy)/2,
-					    "width", (double) gdk_pixbuf_get_width(pixmap) * shape->zoomx,
-					    "height", (double) gdk_pixbuf_get_height(pixmap) * shape->zoomy,
+					    "x", shape->x - shape->w / 2,
+					    "y", shape->y - shape->h / 2,
+					    "width", shape->w,
+					    "height", shape->h,
 					    "width_set", TRUE, 
 					    "height_set", TRUE,
 					    NULL);


More information about the Gcompris-devel mailing list