target.c 18.1 KB
Newer Older
1 2
/* gcompris - target.c
 *
3
 * Copyright (C) 2001, 2008 Bruno Coudoin
4 5 6
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
7
 *   the Free Software Foundation; either version 3 of the License, or
8 9 10 11 12 13 14 15
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
16
 *   along with this program; if not, see <http://www.gnu.org/licenses/>.
17 18 19 20 21 22
 */

#include "gcompris/gcompris.h"

#define SOUNDLISTFILE PACKAGE

23 24
static GcomprisBoard *gcomprisBoard = NULL;
static gboolean board_paused = TRUE;
25

26 27 28 29 30
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);
31
static int gamewon;
32
static void		 game_won(void);
33 34 35 36 37

#define VERTICAL_SEPARATION	30
#define HORIZONTAL_SEPARATION	30
#define TEXT_COLOR		"white"

38
static GooCanvasItem *boardRootItem = NULL;
39
static GooCanvasItem *valueRootItem = NULL;
40
static GooCanvasItem *speedRootItem = NULL;
41
static GooCanvasItem *tooltipItem = NULL;
42

43 44
static double wind_speed;
static double ang;
45

46
static GooCanvasItem  *answer_item = NULL;
47 48 49
static gchar		 answer_string[10];
static guint		 answer_string_index = 0;

50
static GooCanvasItem *animate_item = NULL;
51 52 53 54 55 56 57 58 59 60 61 62 63 64
static gint		animate_id = 0;
static gint		animate_item_distance = 0;
static gint		animate_item_size = 0;
static double		animate_item_x = 0;
static double		animate_item_y = 0;
#define MAX_DART_SIZE 20
#define MIN_DART_SIZE 3

static guint		user_points = 0;

/*
 * Functions Definition
 */
static void		process_ok(void);
65
static gint		key_press(guint keyval, gchar *commit_str, gchar *preedit_str);
66
static GooCanvasItem *target_create_item(GooCanvasItem *parent);
67 68
static void		target_destroy_all_items(void);
static void		target_next_level(void);
69 70 71 72
static gboolean		item_event (GooCanvasItem  *item,
				    GooCanvasItem  *target,
				    GdkEventButton *event,
				    gpointer data);
73 74 75 76
static gboolean		tooltip_event (GooCanvasItem  *item,
				       GooCanvasItem  *target,
				       GdkEventButton *event,
				       gpointer gpoint);
77 78 79 80
static void		animate_items(void);
static void		launch_dart(double item_x, double item_y);

/*
81
 * distance to target, min wind speed, max wind speed, target1 width(center),
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
 * value1 (for target1), ... to target10, value10
 *
 * a target width of 0 means no such target
 */
#define MAX_NUMBER_OF_TARGET 10

typedef struct {
  guint number_of_arrow;
  guint target_distance;
  guint target_min_wind_speed;
  guint target_max_wind_speed;
  gint target_width_value[MAX_NUMBER_OF_TARGET*2];
} TargetDefinition;


/*
 * Definition of targets one line by level based on TargetDefinition
99
 */
100 101 102 103 104 105 106 107 108
static TargetDefinition targetDefinition[] =
{
  { 3, 100, 2, 5,  { 40, 5 , 80, 3, 150, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
  { 5, 150, 2, 7,  { 30, 10, 50, 5, 150, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
  { 7, 200, 4, 9,  { 20, 10, 40, 5, 60, 3, 150, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
  { 7, 200, 5, 10, { 15, 100, 35, 50, 55, 10, 75, 5, 150, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }
};
#define NUMBER_OF_TARGET 4

109 110
#define TARGET_CENTER_X	235.0
#define TARGET_CENTER_Y	260.0
111

112 113
#define SPEED_CENTER_X	660.0
#define SPEED_CENTER_Y	125.0
114 115

static guint target_colors[] = {
116 117 118 119
  0xAA0000FF, 0x00AA00FF, 0x0000AAFF,
  0xAAAA00FF, 0x00AAAAFF, 0xAA00AAFF,
  0xAA0000FF, 0x00AA00FF, 0x0000AAFF,
  0xAA0000AF
120 121 122 123 124
};

static guint number_of_arrow = 0;

/* Description of this plugin */
125
static BoardPlugin menu_bp =
126 127 128
  {
    NULL,
    NULL,
129 130
    "Practice addition with a target game",
    "Hit the target and count your points",
131 132 133 134 135 136 137 138 139 140
    "Bruno Coudoin <bruno.coudoin@free.fr>",
    NULL,
    NULL,
    NULL,
    NULL,
    start_board,
    pause_board,
    end_board,
    is_our_board,
    key_press,
141
    NULL,
142 143
    set_level,
    NULL,
144 145
    NULL,
    NULL,
146 147 148 149 150 151 152 153 154
    NULL
  };

/*
 * Main entry point mandatory for each Gcompris's game
 * ---------------------------------------------------
 *
 */

155
GET_BPLUGIN_INFO(target)
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195

/*
 * in : boolean TRUE = PAUSE : FALSE = CONTINUE
 *
 */
static void pause_board (gboolean pause)
{
  if(gcomprisBoard==NULL)
    return;

  if(gamewon == TRUE && pause == FALSE) /* the game is won */
    {
      game_won();
    }

  if(pause)
    {
      if (animate_id) {
	gtk_timeout_remove (animate_id);
	animate_id = 0;
      }
    }
  else
    {
      if(animate_item) {
	animate_id = gtk_timeout_add (200, (GtkFunction) animate_items, NULL);
      }
    }

  board_paused = pause;
}

/*
 */
static void start_board (GcomprisBoard *agcomprisBoard)
{

  if(agcomprisBoard!=NULL)
    {
      gcomprisBoard=agcomprisBoard;
196 197 198 199

      /* disable im_context */
      gcomprisBoard->disable_im_context = TRUE;

200 201 202 203 204
      gcomprisBoard->level=1;
      gcomprisBoard->maxlevel=NUMBER_OF_TARGET;
      gcomprisBoard->sublevel=1;
      gcomprisBoard->number_of_sublevel=1; /* Go to next level after this number of 'play' */

205 206
      gc_set_background(goo_canvas_get_root_item(gcomprisBoard->canvas),
			"target/target_background.svgz");
207

208 209 210
      gc_bar_set(GC_BAR_LEVEL);
      gc_bar_location(BOARDWIDTH-200, -1, 0.8);

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
      target_next_level();

      gamewon = FALSE;
      pause_board(FALSE);
    }
}
/* ======================================= */
static void end_board ()
{
  if(gcomprisBoard!=NULL)
    {
      pause_board(TRUE);
      target_destroy_all_items();
    }
  gcomprisBoard = NULL;
}

/* ======================================= */
static void set_level (guint level)
{

  if(gcomprisBoard!=NULL)
    {
      gcomprisBoard->level=level;
      gcomprisBoard->sublevel=1;
      target_next_level();
    }
}


/* ======================================= */
242
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str)
243 244 245
{
  guint c;

246
  if(!gcomprisBoard || gamewon == TRUE)
247
    return FALSE;
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267

  /* Add some filter for control and shift key */
  switch (keyval)
    {
      /* Avoid all this keys to be interpreted by this game */
    case GDK_Shift_L:
    case GDK_Shift_R:
    case GDK_Control_L:
    case GDK_Control_R:
    case GDK_Caps_Lock:
    case GDK_Shift_Lock:
    case GDK_Meta_L:
    case GDK_Meta_R:
    case GDK_Alt_L:
    case GDK_Alt_R:
    case GDK_Super_L:
    case GDK_Super_R:
    case GDK_Hyper_L:
    case GDK_Hyper_R:
    case GDK_Num_Lock:
268
      return FALSE;
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
    case GDK_KP_Enter:
    case GDK_Return:
      process_ok();
      return TRUE;
    case GDK_Right:
    case GDK_Left:
      break;
    case GDK_BackSpace:
      if(answer_string_index>0)
	{
	  answer_string_index--;
	  answer_string[answer_string_index] = 0;
	}
      break;
    }

285
  c = tolower(keyval);
286

Bruno Coudoin's avatar
Bruno Coudoin committed
287 288
  /* Limit the user entry to 5 digits */
  if(c>='0' && c<='9' && answer_string_index<5)
289 290 291 292 293 294
    {
      answer_string[answer_string_index++] = c;
      answer_string[answer_string_index] = 0;
    }

  if(answer_item)
295 296
    {
      gchar *tmpstr = g_strdup_printf(_("Points = %s"), answer_string);
297 298 299
      g_object_set(answer_item,
		   "text", tmpstr,
		   NULL);
300
      g_free(tmpstr);
301
      process_ok();
302
    }
303 304 305 306 307 308

  return TRUE;
}


/* ======================================= */
309
static gboolean is_our_board (GcomprisBoard *gcomprisBoard)
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
{
  if (gcomprisBoard)
    {
      if(g_strcasecmp(gcomprisBoard->type, "target")==0)
	{
	  /* Set the plugin entry */
	  gcomprisBoard->plugin=&menu_bp;

	  return TRUE;
	}
    }
  return FALSE;
}

/*-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------*/
/* set initial values for the next level */
static void target_next_level()
{

330
  gc_bar_set_level(gcomprisBoard);
331 332 333 334 335

  target_destroy_all_items();
  gamewon = FALSE;

  /* Try the next level */
336
  target_create_item(goo_canvas_get_root_item(gcomprisBoard->canvas));
337 338 339 340 341 342
}
/* ==================================== */
/* Destroy all the items */
static void target_destroy_all_items()
{
  if(boardRootItem!=NULL)
Bruno Coudoin's avatar
Bruno Coudoin committed
343
    goo_canvas_item_remove(boardRootItem);
344 345 346 347

  boardRootItem = NULL;

  if(speedRootItem!=NULL)
Bruno Coudoin's avatar
Bruno Coudoin committed
348
    goo_canvas_item_remove(speedRootItem);
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364

  animate_item = NULL;
  answer_item = NULL;
  answer_string_index = 0;
  user_points = 0;

  speedRootItem = NULL;
}

/*
 * Display a random wind speed
 */
static void display_windspeed()
{
  guint second = 0;
  guint needle_zoom = 15;
365
  gchar *tmpstr;
Bruno Coudoin's avatar
Bruno Coudoin committed
366
  GooCanvasPoints *canvasPoints;
367
  canvasPoints = goo_canvas_points_new (2);
368 369

  if(speedRootItem!=NULL)
Bruno Coudoin's avatar
Bruno Coudoin committed
370 371 372 373 374
    goo_canvas_item_remove(speedRootItem);

  speedRootItem = goo_canvas_group_new (goo_canvas_get_root_item(gcomprisBoard->canvas),
					NULL);

375 376

  /* Speed orientation */
377
  second = g_random_int()%60;
378 379 380 381
  ang = second * M_PI / 30;

  /* Speed force */
  wind_speed = targetDefinition[gcomprisBoard->level-1].target_min_wind_speed \
382
    + g_random_int()%(targetDefinition[gcomprisBoard->level-1].target_max_wind_speed \
383 384 385 386 387 388
	      - targetDefinition[gcomprisBoard->level-1].target_min_wind_speed);

  canvasPoints->coords[0]=SPEED_CENTER_X;
  canvasPoints->coords[1]=SPEED_CENTER_Y;
  canvasPoints->coords[2]=SPEED_CENTER_X + wind_speed * sin(ang) * needle_zoom;
  canvasPoints->coords[3]=SPEED_CENTER_Y - wind_speed * cos(ang) * needle_zoom;
389 390 391
  double w = 4.0;
  goo_canvas_polyline_new (speedRootItem, FALSE, 0,
			   "points", canvasPoints,
392 393
			   "stroke-color-rgba", 0Xa05a2cffL,
			   "fill-color-rgba", 0Xa05a2cffL,
394 395 396 397 398 399
			   "line-width", w,
			   "end-arrow", TRUE,
			   "arrow-tip-length", 7.0,
			   "arrow-length", 5.0,
			   "arrow-width", 4.0,
			   NULL);
400

Bruno Coudoin's avatar
Bruno Coudoin committed
401
  goo_canvas_points_unref(canvasPoints);
402

403
  /* Draw the center of the speedometer */
404 405 406 407 408
  goo_canvas_ellipse_new (speedRootItem,
			 SPEED_CENTER_X,
			 SPEED_CENTER_Y,
			 10.0,
			 10.0,
409 410 411
			 "fill_color_rgba", 0Xa05a2cffL,
			 "stroke-color", "black",
			 "line-width", (double)2,
412 413
			 NULL);

414
  tmpstr = g_strdup_printf(_("Wind speed = %d\nkilometers/hour"), (guint)wind_speed);
415 416 417 418 419 420 421
  goo_canvas_text_new (speedRootItem,
		       tmpstr,
		       (double) SPEED_CENTER_X,
		       (double) SPEED_CENTER_Y + 110,
		       -1,
		       GTK_ANCHOR_CENTER,
		       "font", gc_skin_font_board_medium,
Bruno Coudoin's avatar
Bruno Coudoin committed
422
		       "fill-color", "white",
423
		       NULL);
424
  g_free(tmpstr);
425 426 427 428 429 430

}



/* ==================================== */
431
static GooCanvasItem *target_create_item(GooCanvasItem *parent)
432 433
{
  int i;
434
  gchar *tmpstr;
435
  GooCanvasItem *item = NULL;
436

437
  boardRootItem = goo_canvas_group_new (parent, NULL);
438
  valueRootItem = goo_canvas_group_new (boardRootItem, NULL);
439 440 441 442
  goo_canvas_item_translate(boardRootItem,
			    TARGET_CENTER_X,
			    TARGET_CENTER_Y);

443 444 445 446
  for(i=0; i<MAX_NUMBER_OF_TARGET; i++)
    {
      if(targetDefinition[gcomprisBoard->level-1].target_width_value[i*2]>0)
	{
447 448 449 450 451 452 453 454 455 456 457 458 459
	  item = \
	    goo_canvas_ellipse_new (boardRootItem,
				    0.0,
				    0.0,
				    (double)targetDefinition[gcomprisBoard->level-1].target_width_value[i*2],
				    (double)targetDefinition[gcomprisBoard->level-1].target_width_value[i*2],
				    "fill_color_rgba", target_colors[i],
				    "stroke-color", "black",
				    "line-width", 1.0,
				    NULL);

	  goo_canvas_item_lower(item, NULL);
	  g_signal_connect(item, "button-press-event", (GtkSignalFunc) item_event, NULL);
460

461
	  /* Display the value for this target */
462 463
	  tmpstr = g_strdup_printf("%d",
				   targetDefinition[gcomprisBoard->level-1].target_width_value[i*2+1]);
464
	  item = goo_canvas_text_new (valueRootItem,
465 466 467 468 469 470
				      tmpstr,
				      (double) 0,
				      (double) targetDefinition[gcomprisBoard->level-1].target_width_value[i*2] - 10,
				      -1,
				      GTK_ANCHOR_CENTER,
				      "font", gc_skin_font_board_medium,
Bruno Coudoin's avatar
Bruno Coudoin committed
471
				      "fill-color", "white",
472
				      NULL);
473
	  g_free(tmpstr);
474

475
	  g_signal_connect(item, "button-press-event", (GtkSignalFunc) item_event, NULL);
476 477 478 479 480
	}
    }

  number_of_arrow = targetDefinition[gcomprisBoard->level-1].number_of_arrow;

481 482
  tmpstr = g_strdup_printf(_("Distance to target = %d meters"),
			   targetDefinition[gcomprisBoard->level-1].target_distance);
483 484 485 486 487 488 489
  goo_canvas_text_new (boardRootItem,
		       tmpstr,
		       (double) 0,
		       (double) BOARDHEIGHT-TARGET_CENTER_Y -45,
		       -1,
		       GTK_ANCHOR_CENTER,
		       "font", gc_skin_font_board_medium,
490
		       "fill-color", "black",
491
		       NULL);
492
  g_free(tmpstr);
493 494 495

  display_windspeed();

496 497 498 499 500 501 502 503 504 505 506 507
  /* Tooltip */
  tooltipItem =
    goo_canvas_text_new (boardRootItem,
			 "",
			 150,
			 -140,
			 -1,
			 GTK_ANCHOR_CENTER,
			 "font", gc_skin_font_board_title_bold,
			 "fill-color", "white",
			 NULL);

508 509 510 511 512 513 514 515 516 517 518
  return NULL;
}
/* ==================================== */
static void game_won()
{
  gcomprisBoard->sublevel++;

  if(gcomprisBoard->sublevel>gcomprisBoard->number_of_sublevel) {
    /* Try the next level */
    gcomprisBoard->sublevel=1;
    gcomprisBoard->level++;
519 520 521
    if(gcomprisBoard->level>gcomprisBoard->maxlevel)
	gcomprisBoard->level = gcomprisBoard->maxlevel;

522
    gc_sound_play_ogg ("sounds/bonus.wav", NULL);
523 524 525 526
  }
  target_next_level();
}

527 528 529 530 531 532
static void bonus()
{
  gc_bonus_display(gamewon, GC_BONUS_SMILEY);
  animate_id = 0;
}

533 534 535 536
static void process_ok()
{
  guint answer_points = atoi(answer_string);

537
  if(answer_item) {
538

539 540 541
    if(answer_points == user_points)
      {
	gamewon = TRUE;
542
	animate_id = gtk_timeout_add (200, (GtkFunction) bonus, NULL);
543 544
      }
  }
545 546 547 548 549 550 551 552 553

}

/*
 * Request score
 *
 */
static void request_score()
{
554 555
  double x_offset = 390;
  double y_offset = 150;
556
  gchar *tmpstr;
557

558 559
  /* Set the maximum text to calc the background */
  tmpstr =  g_strdup_printf(_("Points = %s"), "00000");
560 561
  answer_item = goo_canvas_text_new (boardRootItem,
				     tmpstr,
562 563
				     (double) x_offset,
				     (double) y_offset,
564 565 566
				     -1,
				     GTK_ANCHOR_CENTER,
				     "font", gc_skin_font_board_title_bold,
Bruno Coudoin's avatar
Bruno Coudoin committed
567
				     "fill-color", "white",
568
				     NULL);
569
  g_free(tmpstr);
570

571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
  GooCanvasBounds bounds;
  goo_canvas_item_get_bounds (answer_item, &bounds);
  goo_canvas_convert_to_item_space(goo_canvas_item_get_canvas(answer_item),
				   answer_item,
				   &bounds.x1, &bounds.y1);
  goo_canvas_convert_to_item_space(goo_canvas_item_get_canvas(answer_item),
				   answer_item,
				   &bounds.x2, &bounds.y2);

  int gap = 15;
  GooCanvasItem *item =				\
    goo_canvas_rect_new (boardRootItem,
			 bounds.x1 - gap,
			 bounds.y1 - gap,
			 (bounds.x2 - bounds.x1) + gap*2,
			 (bounds.y2 - bounds.y1) + gap*2,
			 "stroke_color_rgba", 0xFFFFFFFFL,
588
			 "fill_color_rgba", 0X5599FFCCL,
589 590 591 592 593 594 595 596 597 598 599 600
			 "line-width", (double) 2,
			 "radius-x", (double) 10,
			 "radius-y", (double) 10,
			 NULL);
  goo_canvas_item_raise(answer_item, item);

  /* Set the correct initial text */
  tmpstr = g_strdup_printf(_("Points = %s"), answer_string);
  g_object_set(answer_item,
	       "text", tmpstr,
	       NULL);
  g_free(tmpstr);
601 602
}

603
static guint add_points(double x, double y)
604 605 606
{
  guint i;
  double diametre;
607
  guint points = 0;
608 609 610

  // Calculate the distance
  diametre = sqrt(x*x+y*y);
Bruno Coudoin's avatar
Bruno Coudoin committed
611

612 613 614 615
  for(i=0; i<MAX_NUMBER_OF_TARGET; i++)
    {
      if(diametre < targetDefinition[gcomprisBoard->level-1].target_width_value[i*2])
	{
616 617
	  points = targetDefinition[gcomprisBoard->level-1].target_width_value[i*2+1];
	  user_points += points;
618 619 620 621
	  break;
	}
    }

622
  return points;
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
}


/*
 * Dart animation
 *
 */
static void animate_items()
{
  if(board_paused)
    return;

  if(!animate_item)
    return;

  // Apply the wind move
  animate_item_x = animate_item_x + wind_speed * sin(ang);
  animate_item_y = animate_item_y - wind_speed * cos(ang);

642
  g_object_set (animate_item,
643 644 645 646 647
		"center-x", (double)animate_item_x,
		"center-y", (double)animate_item_y,
		"radius-x", (double)animate_item_size,
		"radius-y", (double)animate_item_size,
		NULL);
648

649 650 651
  if(animate_item_size>MIN_DART_SIZE)
    animate_item_size--;

652
  if(--animate_item_distance == 0)
653
    {
654 655
      gc_sound_play_ogg ("sounds/brick.wav", NULL);

656 657 658 659 660 661 662 663 664 665 666 667
      // Calc the point for this dart
      guint points = add_points(animate_item_x, animate_item_y);

      // Add a tooltip on this dart to let the children
      // see how we count it
      g_signal_connect(animate_item,
		       "enter_notify_event", (GtkSignalFunc) tooltip_event,
		       GINT_TO_POINTER(points));
      g_signal_connect(animate_item,
		       "leave_notify_event", (GtkSignalFunc) tooltip_event,
		       GINT_TO_POINTER(-1));

668 669 670 671 672 673 674 675 676 677 678
      gtk_timeout_remove (animate_id);
      animate_id = 0;
      animate_item = NULL;

      // Change the wind for the next target
      display_windspeed();
    }

}

/*
679
 *
680 681 682 683 684 685 686 687 688
 */
static void launch_dart(double item_x, double item_y)
{

  animate_item_x	= item_x;
  animate_item_y	= item_y;
  animate_item_size	= MAX_DART_SIZE;
  animate_item_distance	= targetDefinition[gcomprisBoard->level-1].target_distance/10;

689 690
  gc_sound_play_ogg ("sounds/line_end.wav", NULL);

691 692 693 694 695
  animate_item = goo_canvas_ellipse_new (boardRootItem,
					(double)item_x,
					(double)item_y,
					(double)MAX_DART_SIZE,
					(double)MAX_DART_SIZE,
696
					"fill_color_rgba", 0xFF80FFFF,
Bruno Coudoin's avatar
Bruno Coudoin committed
697 698
					"stroke-color", "white",
					"line-width", (double)1,
699
					NULL);
700 701
  /* Make sure the target values stay on top */
  goo_canvas_item_lower(animate_item, valueRootItem);
702 703 704 705 706 707
  animate_id = gtk_timeout_add (200, (GtkFunction) animate_items, NULL);

  if(--number_of_arrow == 0)
    {
      request_score();
    }
708

709 710 711
}

/* ==================================== */
712 713 714 715 716
static gboolean
item_event (GooCanvasItem  *item,
	    GooCanvasItem  *target,
	    GdkEventButton *event,
	    gpointer data)
717 718
{
  double item_x, item_y;
719

720 721 722 723 724 725 726
  if(board_paused)
    return FALSE;

  /* Is there already a dart on air */
  if(number_of_arrow == 0 || animate_item)
    return FALSE;

727
  switch(event->button)
728
    {
729 730 731 732 733 734
    case 1:
    case 2:
    case 3:
      item_x = event->x;
      item_y = event->y;
      //goo_canvas_convert_to_item_space(item->parent, &item_x, &item_y);
735

736
      launch_dart(item_x, item_y);
737

738
      break;
739 740 741
    default:
      break;
    }
742

743 744
  return FALSE;
}
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767

static gboolean
tooltip_event (GooCanvasItem  *item,
	       GooCanvasItem  *target,
	       GdkEventButton *event,
	       gpointer gpoint)
{
  gint point = GPOINTER_TO_INT(gpoint);

  if (point >= 0) {
    gchar *tmpstr = g_strdup_printf("%d", point);
    g_object_set(tooltipItem,
		 "text", tmpstr,
		 NULL);
    g_free(tmpstr);
  } else {
    g_object_set(tooltipItem,
		 "text", "",
		 NULL);
  }

  return TRUE;
}