Beispiel #1
0
/* ==================================== */
static gboolean
animate_step()
{

  if(!gcomprisBoard)
    return FALSE;

  GooCanvasBounds bounds;
  goo_canvas_item_get_bounds(timer_item, &bounds);

  if(GOO_IS_CANVAS_SVG(timer_item))
    goo_canvas_item_translate(timer_item, timer_step_x1, timer_step_y1);
  else if(GOO_IS_CANVAS_RECT(timer_item))
    g_object_set(timer_item,
		 "x", bounds.x1 + timer_step_x1,
		 "y", bounds.y1 + timer_step_y1,
		 "height", bounds.y2 - bounds.y1 - timer_step_y1,
		 NULL);

  /* Special case for raising/lowering the boat */
  if(boat_position==BOAT_POS_MIDDLE && timer_item==canal_middle_item)
    {
      goo_canvas_item_translate(tuxboat_item, 0, timer_step_y1);
      gc_item_focus_remove(tuxboat_item, NULL);
    }

  if((bounds.y1 >= timer_item_limit_y && timer_step_y1 > 0) ||
     (bounds.y1 <= timer_item_limit_y && timer_step_y1 < 0))
    {
      gtk_timeout_remove (timer_id);
      timer_id = 0;
      animation = FALSE;
      update_water();
      gc_item_focus_init(tuxboat_item, NULL);
      g_object_set (tuxboat_item,
		    "svg-id", "#BOAT_NO_SAIL", NULL);
    }
  else if((bounds.x1 >= timer_item_limit_x && timer_step_x1 > 0) ||
     (bounds.x1 <= timer_item_limit_x && timer_step_x1 < 0))
    {
      gtk_timeout_remove (timer_id);
      timer_id = 0;
      animation = FALSE;
      update_water();
      if (gamewon)
        {
          gc_bonus_display(TRUE, GC_BONUS_FLOWER);
          gamewon = FALSE;
        }
      gc_item_focus_init(tuxboat_item, NULL);
      g_object_set (tuxboat_item,
		    "svg-id", "#BOAT_NO_SAIL", NULL);
    }

  return TRUE;
}
Beispiel #2
0
static void start_frigate_anim()
{
  GdkPixbuf *pixmap;
  int w;
  if (frigate_item)
    stop_frigate_anim();

  // the antisubmarine warfare frigate
  pixmap = gc_pixmap_load("submarine/asw_frigate.png");
  w = gdk_pixbuf_get_width(pixmap);

  frigate_item = goo_canvas_image_new (goo_canvas_get_root_item(gcomprisBoard->canvas),
				       pixmap,
				       0,
				       0,
				       NULL);
  goo_canvas_item_translate(frigate_item, BOARDWIDTH, 6);
  goo_canvas_item_animate(frigate_item,
			  -w,
			  2.0,
			  1,
			  0,
			  TRUE,
			  100*1000,
			  100,
			  GOO_CANVAS_ANIMATE_RESTART);
#if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24
  gdk_pixbuf_unref(pixmap);
#else
  g_object_unref(pixmap);
#endif
}
void ApplicationModel::snapToGrid(void)
{
    GooCanvasItemModel* model = (GooCanvasItemModel*) this->gobj();    
    GooCanvas* canvas = (GooCanvas*) parentWindow->m_Canvas->gobj();
    if(model && canvas)
    {
        GooCanvasItem* item = goo_canvas_get_item(canvas, model); 
        GooCanvasBounds bi;
        goo_canvas_item_get_bounds(item, &bi);
        double xs, ys;
        g_object_get (parentWindow->m_Grid,
               "x_step", &xs,
               "y_step", &ys,
               NULL);
        double c_x = (int) (((int)bi.x1) % (int)xs);
        double c_y = (int) (((int)bi.y1) % (int)ys);
        //printf("cx:%f, cy:%f\n", c_x, c_y);
        //printf("x:%f, y:%f\n", bi.x1, bi.y1);
        if(parentWindow->m_snapToGrid)
            goo_canvas_item_translate(item, -c_x, -c_y); 
        // force update
        goo_canvas_item_get_bounds(item, &bi);
        this->points.clear();
        GyPoint pt;
        pt.x = bi.x1;
        pt.y = bi.y1;
        this->points.push_back(pt);
        updateCoordination();
    }
}
Beispiel #4
0
/* Move the plane */
static void planegame_move_plane(GooCanvasItem *item)
{
    GooCanvasBounds bounds;

    goo_canvas_item_get_bounds(item, &bounds);

    if(plane_x > BOARDWIDTH - (bounds.x2 - bounds.x1)
            && planespeed_x > 0)
        planespeed_x=0;

    if(plane_x < 0 && planespeed_x < 0)
        planespeed_x = 0;

    if(plane_y > BOARDHEIGHT - (bounds.y2 - bounds.y1)
            && planespeed_y > 0)
        planespeed_y = 0;

    if(plane_y < 0 && planespeed_y < 0)
        planespeed_y=0;

    goo_canvas_item_translate(item,
                              planespeed_x,
                              planespeed_y);
    plane_x += planespeed_x;
    plane_y += planespeed_y;
}
Beispiel #5
0
static void
display_image(gchar *imagename, GooCanvasItem *root_item)
{
  GdkPixbuf *pixmap = NULL;
  GooCanvasItem *item;
  double xratio, yratio;
  double iw, ih;

  if (imagename==NULL || !images_selector_displayed)
    return;

  pixmap = gc_pixmap_load_or_null(imagename);

  /* Sad, the image is not found */
  if(!pixmap)
    return;

  iw = IMAGE_WIDTH * gc_zoom_factor_get();
  ih = IMAGE_HEIGHT * gc_zoom_factor_get();

  /* Calc the max to resize width or height */
  xratio = (double) ((iw/(double)gdk_pixbuf_get_width(pixmap)));
  yratio = (double) ((ih/(double)gdk_pixbuf_get_height(pixmap)));
  xratio = MIN(yratio, xratio);

  item = goo_canvas_image_new (root_item,
			       pixmap,
			       0,
			       0,
			       NULL);
  goo_canvas_item_translate(item, ix, iy);
  goo_canvas_item_scale(item, xratio, xratio);
#if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24
  gdk_pixbuf_unref(pixmap);
#else
  g_object_unref(pixmap);
#endif

  g_signal_connect(item, "button_press_event",
		   (GCallback) item_event_images_selector,
		   imagename);
  gc_item_focus_init(item, NULL);

  ix += iw + IMAGE_GAP;
  if(ix >= (DRAWING_AREA_X2 - DRAWING_AREA_X1)
     * gc_zoom_factor_get() - IMAGE_GAP)
    {
      ix = 0;
      iy += ih + IMAGE_GAP;
    }

  /* Cannot use GINT_TO_POINTER with a constant calculation */
  guint iy_calc = iy + (ih + IMAGE_GAP)*2;
  g_object_set_data (G_OBJECT (root_item), "iy", GINT_TO_POINTER (iy_calc));
}
Beispiel #6
0
static void
create_demo_table (GooCanvasItem *root,
		   gdouble        x,
		   gdouble        y,
		   gdouble        width,
		   gdouble        height)
{
  GooCanvasItem *table, *square, *circle, *triangle;

  table = goo_canvas_table_new (root,
                                "row-spacing", 4.0,
                                "column-spacing", 4.0,
				"width", width,
				"height", height,
                                NULL);
  goo_canvas_item_translate (table, x, y);

  square = goo_canvas_rect_new (table, 0.0, 0.0, 50.0, 50.0,
				"fill-color", "red",
				NULL);
  goo_canvas_item_set_child_properties (table, square,
					"row", 0,
					"column", 0,
					"x-shrink", TRUE,
					NULL);
  g_object_set_data (G_OBJECT (square), "id", "Red square");
  g_signal_connect (square, "button_press_event",
		    G_CALLBACK (on_button_press), NULL);

  circle = goo_canvas_ellipse_new (table, 0.0, 0.0, 25.0, 25.0,
				   "fill-color", "blue",
				   NULL);
  goo_canvas_item_set_child_properties (table, circle,
					"row", 0,
					"column", 1,
					"x-shrink", TRUE,
					NULL);
  g_object_set_data (G_OBJECT (circle), "id", "Blue circle");
  g_signal_connect (circle, "button_press_event",
		    G_CALLBACK (on_button_press), NULL);

  triangle = goo_canvas_polyline_new (table, TRUE, 3,
				      25.0, 0.0, 0.0, 50.0, 50.0, 50.0,
				      "fill-color", "yellow",
				      NULL);
  goo_canvas_item_set_child_properties (table, triangle,
					"row", 0,
					"column", 2,
					"x-shrink", TRUE,
					NULL);
  g_object_set_data (G_OBJECT (triangle), "id", "Yellow triangle");
  g_signal_connect (triangle, "button_press_event",
		    G_CALLBACK (on_button_press), NULL);
}
Beispiel #7
0
static void
create_width_for_height_table (GooCanvasItem *root,
			       gdouble        x,
			       gdouble        y,
			       gdouble        width,
			       gdouble        height,
			       gdouble        rotation)
{
  GooCanvasItem *table, *item;
  gchar *text = "This is a long paragraph that will have to be split over a few lines so we can see if its allocated height changes when its allocated width is changed.";

  table = goo_canvas_table_new (root,
#if 1
				"width", width,
				"height", height,
#endif
                                NULL);
  goo_canvas_item_translate (table, x, y);
  goo_canvas_item_rotate (table, rotation, 0, 0);

  item = goo_canvas_rect_new (table, 0.0, 0.0, width - 2, 10.0,
			      "fill-color", "red",
			      NULL);
  goo_canvas_item_set_child_properties (table, item,
					"row", 0,
					"column", 0,
					"x-shrink", TRUE,
					NULL);

#if 1
  item = goo_canvas_text_new (table, text, 0, 0, -1, GOO_CANVAS_ANCHOR_NW, NULL);
  goo_canvas_item_set_child_properties (table, item,
					"row", 1,
					"column", 0,
					"x-expand", TRUE,
					"x-fill", TRUE,
					"x-shrink", TRUE,
					"y-expand", TRUE,
					"y-fill", TRUE,
					NULL);
  g_object_set_data (G_OBJECT (item), "id", "Text Item");
  g_signal_connect (item, "button_press_event",
		    G_CALLBACK (on_button_press), NULL);
#endif

  item = goo_canvas_rect_new (table, 0.0, 0.0, width - 2, 10.0,
			      "fill-color", "red",
			      NULL);
  goo_canvas_item_set_child_properties (table, item,
					"row", 2,
					"column", 0,
					"x-shrink", TRUE,
					NULL);
}
Beispiel #8
0
/*
 * Same as draw rect but for an image
 */
static void move_image(GooCanvasItem *group,
		       int x, int y, GooCanvasItem *item)
{
  int x1,y1;
  y1=cellsize*(y)-hoogte + board_border_y;
  x1=cellsize*(x)-breedte + board_border_x;

  goo_canvas_item_set_transform(item, NULL);
  goo_canvas_item_translate(item,
  			    x1, y1);

  goo_canvas_item_raise(item, NULL);
}
Beispiel #9
0
static void display_paying_note(guint note, guint x, guint y)
{
  gchar *note_str = g_strdup_printf("money/n%de.svgz", note);
  RsvgHandle *svg_handle;
  svg_handle = gc_rsvg_load(note_str);
  GooCanvasItem *item = goo_canvas_svg_new(boardRootItem,
					   svg_handle,
					   NULL);
  goo_canvas_item_translate(item, x, y);
  goo_canvas_item_scale(item, 0.25, 0.25);
  g_object_unref(svg_handle);
  g_free(note_str);
}
Beispiel #10
0
static void
scramble (GtkObject *object, gpointer data)
{
	GooCanvas *canvas;
	GooCanvasItem **board;
	int i;
	int pos, oldpos;
	int dir;
	int x, y;

	srand (time (NULL));

	canvas = data;
	board = g_object_get_data (G_OBJECT (canvas), "board");

	/* First, find the blank spot */

	for (pos = 0; pos < 16; pos++)
		if (board[pos] == NULL)
			break;

	/* "Move the blank spot" around in order to scramble the pieces */

	for (i = 0; i < SCRAMBLE_MOVES; i++) {
retry_scramble:
		dir = rand () % 4;

		x = y = 0;

		if ((dir == 0) && (pos > 3)) /* up */
			y = -1;
		else if ((dir == 1) && (pos < 12)) /* down */
			y = 1;
		else if ((dir == 2) && ((pos % 4) != 0)) /* left */
			x = -1;
		else if ((dir == 3) && ((pos % 4) != 3)) /* right */
			x = 1;
		else
			goto retry_scramble;

		oldpos = pos + y * 4 + x;
		board[pos] = board[oldpos];
		board[oldpos] = NULL;
		g_object_set_data (G_OBJECT (board[pos]), "piece_pos",
				   GINT_TO_POINTER (pos));

		goo_canvas_item_translate (board[pos], -x * PIECE_SIZE,
					   -y * PIECE_SIZE);
		pos = oldpos;
	}
}
Beispiel #11
0
static void gletters_move_item(GooCanvasItem *item)
{
  GooCanvasBounds bounds;

  goo_canvas_item_translate(item, 0, 2.0);

  goo_canvas_item_get_bounds (item,
			      &bounds);

  if(bounds.y1>BOARDHEIGHT) {
    item2del_list = g_list_append (item2del_list, item);
    player_loose();
  }
}
Beispiel #12
0
/** Setting the bar location
 * @param[in] x the bar x coordinate, -1 to set the default
 * @param[in] y the bar y coordinate, -1 to set the default
 * @param[in] zoom the bar zoom factor, -1 to set the default
 */
static void
bar_location (int x, int y, double zoom)
{
  // Make the y coord be assigned at its bottom
  int ny = (y == -1 ? _default_y : y);
  ny += BARHEIGHT - (zoom == -1 ? _default_zoom : zoom) * BARHEIGHT;

  goo_canvas_item_set_transform(rootitem, NULL);

  GooCanvasBounds bounds;
  goo_canvas_item_get_bounds(rootitem, &bounds);
  int nx = (x == -1 ? (BOARDWIDTH - (bounds.x2 - bounds.x1))/2 : x);
  goo_canvas_item_translate(rootitem, nx, ny);
  goo_canvas_item_scale(rootitem,
			(zoom == -1 ? _default_zoom : zoom),
			(zoom == -1 ? _default_zoom : zoom));
  //#endif
}
Beispiel #13
0
// This is called when the textbox data was moved. Update the view accordingly.
static void textbox_moved_callback (ItemData *data, Coords *pos, SheetItem *item)
{
	TextboxItem *textbox_item;

	g_return_if_fail (data != NULL);
	g_return_if_fail (IS_ITEM_DATA (data));
	g_return_if_fail (item != NULL);
	g_return_if_fail (IS_TEXTBOX_ITEM (item));

	if (pos == NULL)
		return;

	textbox_item = TEXTBOX_ITEM (item);

	// Move the canvas item and invalidate the bbox cache.
	goo_canvas_item_translate (GOO_CANVAS_ITEM (item), pos->x, pos->y);
	textbox_item->priv->cache_valid = FALSE;
}
Beispiel #14
0
static void
scramble (GooCanvasItem **board, guint number_of_scrambles)
{
  int i;
  int pos, oldpos;
  int dir;
  int x, y;

  /* g_random are initialised in gcompris launch */
  /* srand (time (NULL)); */

  /* First, find the blank spot */

  for (pos = 0; pos < 16; pos++)
    if (board[pos] == NULL)
      break;

  /* "Move the blank spot" around in order to scramble the pieces */

  for (i = 0; i < number_of_scrambles; i++) {
  retry_scramble:
    dir = g_random_int () % 4;

    x = y = 0;

    if ((dir == 0) && (pos > 3)) /* up */
      y = -1;
    else if ((dir == 1) && (pos < 12)) /* down */
      y = 1;
    else if ((dir == 2) && ((pos % 4) != 0)) /* left */
      x = -1;
    else if ((dir == 3) && ((pos % 4) != 3)) /* right */
      x = 1;
    else
      goto retry_scramble;

    oldpos = pos + y * 4 + x;
    board[pos] = board[oldpos];
    board[oldpos] = NULL;
    g_object_set_data (G_OBJECT (board[pos]), "piece_pos", GINT_TO_POINTER (pos));
    goo_canvas_item_translate (board[pos], -x * PIECE_SIZE, -y * PIECE_SIZE);
    pos = oldpos;
  }
}
Beispiel #15
0
/* =====================================================================
 *
 * =====================================================================*/
static GooCanvasItem *
maze_create_item(GooCanvasItem *parent)
{
  gchar *message;

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

  mazegroup = goo_canvas_group_new(boardRootItem,
				   NULL);

  goo_canvas_item_translate(mazegroup,
			    breedte,
			    hoogte);

  tuxgroup = goo_canvas_group_new(mazegroup,
				   NULL);

  wallgroup = goo_canvas_group_new(boardRootItem,
				   NULL);

  if(modeIsInvisible) {
    message = _("Look at your position, then switch back to invisible mode to continue your moves");
  } else {
    message = _("Look at your position, then switch back to 3D mode to continue your moves");
  }

  warning_item = goo_canvas_text_new (boardRootItem,
				      message,
				      (double) BOARDWIDTH/2,
				      (double) BOARDHEIGHT-BARHEIGHT-25,
				      -1,
				      GTK_ANCHOR_CENTER,
				      "font", gc_skin_font_board_tiny,
				      "fill_color_rgba", gc_skin_color_content,
				      NULL);
  g_object_set (warning_item, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL);

  return NULL;
}
Beispiel #16
0
/* Called with items_lock locked */
static void wordsgame_move_item(LettersItem *item)
{
  GooCanvasBounds bounds;


  goo_canvas_item_translate(item->rootitem, 0, 2.0);

  goo_canvas_item_get_bounds (item->rootitem,
			      &bounds);

  if(bounds.y1>BOARDHEIGHT) {

    if (item == item_on_focus)
      item_on_focus = NULL;

    g_ptr_array_remove (items, item);
    g_ptr_array_add (items2del, item);
    g_timeout_add (100,(GSourceFunc) wordsgame_delete_items, NULL);

    player_loose();
  }
}
void ExternalPortModel::snapToGrid(void)
{
    GooCanvasItemModel* model = (GooCanvasItemModel*) this->gobj();    
    GooCanvas* canvas = (GooCanvas*) parentWindow->m_Canvas->gobj();
    if(model && canvas)
    {
        GooCanvasItem* item = goo_canvas_get_item(canvas, model); 
        GooCanvasBounds bi;
        goo_canvas_item_get_bounds(item, &bi);
        double xs, ys;
        g_object_get (parentWindow->m_Grid,
               "x_step", &xs,
               "y_step", &ys,
               NULL);
        double c_x = (int) (((int)bi.x1) % (int)xs);
        double c_y = (int) (((int)bi.y1) % (int)ys);
        if(parentWindow->m_snapToGrid)
            goo_canvas_item_translate(item, -c_x, -c_y); 
        // force update
        goo_canvas_item_get_bounds(item, &bi);
        updateArrowCoordination();
    }
}
Beispiel #18
0
static void
setup_canvas (GtkWidget *canvas)
{
  GooCanvasItem *root;

  root = goo_canvas_get_root_item (GOO_CANVAS (canvas));

  /* Absolute. */
  ellipse1 = goo_canvas_ellipse_new (root, 0, 0, 25, 15,
				     "fill-color", "blue",
				     NULL);
  goo_canvas_item_translate (ellipse1, 100, 100);
  g_signal_connect (ellipse1, "animation_finished",
		    G_CALLBACK (on_animation_finished), NULL);

  rect1 = goo_canvas_rect_new (root, -10, -10, 20, 20,
			       "fill-color", "blue",
			       NULL);
  goo_canvas_item_translate (rect1, 100, 200);

  rect3 = goo_canvas_rect_new (root, -10, -10, 20, 20,
			       "fill-color", "blue",
			       NULL);
  goo_canvas_item_translate (rect3, 200, 200);

  /* Relative. */
  ellipse2 = goo_canvas_ellipse_new (root, 0, 0, 25, 15,
				     "fill-color", "red",
				     NULL);
  goo_canvas_item_translate (ellipse2, 100, 400);

  rect2 = goo_canvas_rect_new (root, -10, -10, 20, 20,
			       "fill-color", "red",
			       NULL);
  goo_canvas_item_translate (rect2, 100, 500);

  rect4 = goo_canvas_rect_new (root, -10, -10, 20, 20,
			       "fill-color", "red",
			       NULL);
  goo_canvas_item_translate (rect4, 200, 500);
}
Beispiel #19
0
/* ==================================== */
static GooCanvasItem *superbrain_create_item(GooCanvasItem *parent)
{
  int i, j;
  double x;
  double x1, x2;
  GooCanvasItem *item = NULL;
  Piece *piece = NULL;

  listPiecesClear();

  if(current_y_position < SCROLL_LIMIT)
    {
      goo_canvas_item_translate(boardRootItem, 0.0, Y_STEP);
    }

  x = (BOARDWIDTH - number_of_piece*(PIECE_WIDTH*2+PIECE_GAP))/2 + PLAYING_AREA_X;

  /* Draw a line to separate cleanly */
  x1 = x + PIECE_WIDTH;
  x2 = (BOARDWIDTH + (number_of_piece-1)*(PIECE_WIDTH*2+PIECE_GAP))/2 - PIECE_WIDTH + PLAYING_AREA_X;

  goo_canvas_polyline_new (boardRootItem, FALSE, 2,
			   x1, current_y_position + PIECE_HEIGHT + PIECE_GAP/2,
			   x2, current_y_position + PIECE_HEIGHT + PIECE_GAP/2,
			   "stroke-color", "white",
			   "line-width", 1.0,
			   NULL);


  goo_canvas_polyline_new (boardRootItem, FALSE, 2,
			   x1 + 2, current_y_position + PIECE_HEIGHT + PIECE_GAP/2 + 1,
			   x2 + 2, current_y_position + PIECE_HEIGHT + PIECE_GAP/2 + 1,
			   "stroke-color", "black",
			   "line-width", 1.0,
			   NULL);

  /* Continuing the line */
  x1 = PLAYING_HELP_X;
  x2 = x1 + number_of_piece*PIECE_WIDTH;


  goo_canvas_polyline_new (boardRootItem, FALSE, 2,
			   x1, current_y_position + PIECE_HEIGHT + PIECE_GAP/2,
			   x2, current_y_position + PIECE_HEIGHT + PIECE_GAP/2,
			   "stroke-color", "white",
			   "line-width", 1.0,
			   NULL);


  goo_canvas_polyline_new (boardRootItem, FALSE, 2,
			   x1 + 2, current_y_position + PIECE_HEIGHT + PIECE_GAP/2 + 1,
			   x2 + 2, current_y_position + PIECE_HEIGHT + PIECE_GAP/2 + 1,
			   "stroke-color", "black",
			   "line-width", 1.0,
			   NULL);

  /* Draw the pieces */

  for(i=0; i<number_of_piece; i++)
    {

      piece = g_new(Piece, 1);
      piece->listitem = NULL;
      listPieces = g_list_append(listPieces, piece);

      piece->rootitem = goo_canvas_group_new (parent,
					      NULL);


      // Good
      piece->good = goo_canvas_rect_new (piece->rootitem,
					 x + i*(PIECE_WIDTH*2 + PIECE_GAP) - PIECE_WIDTH - PIECE_GAP_GOOD,
					 current_y_position - PIECE_HEIGHT - PIECE_GAP_GOOD,
					 PIECE_WIDTH*2 + PIECE_GAP_GOOD*2,
					 PIECE_HEIGHT*2 + PIECE_GAP_GOOD*2,
					 "fill_color_rgba", COLOR_GOOD,
					 "stroke-color", "white",
					 "line-width", 1.0,
					 "tooltip", _("This item is well placed"),
					 NULL);
      g_object_set (piece->good, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL);

      // Misplaced
      piece->misplaced = goo_canvas_rect_new (piece->rootitem,
					      x + i*(PIECE_WIDTH*2 + PIECE_GAP) - PIECE_WIDTH - PIECE_GAP_GOOD,
					      current_y_position - PIECE_HEIGHT - PIECE_GAP_GOOD,
					      PIECE_WIDTH*2 + PIECE_GAP_GOOD*2,
					      PIECE_HEIGHT*2 + PIECE_GAP_GOOD*2,
					      "fill_color_rgba", COLOR_MISPLACED,
					      "stroke-color", "black",
					      "line-width", 1.0,
					      "tooltip", _("This item is misplaced"),
					      NULL);
      g_object_set (piece->misplaced, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL);

      for(j=0; j<number_of_color; j++)
	{
	  item = goo_canvas_ellipse_new (piece->rootitem,
					 x + i*(PIECE_WIDTH*2 + PIECE_GAP),
					 current_y_position,
					 PIECE_WIDTH,
					 PIECE_HEIGHT,
					 "fill_color_rgba", colors[j],
					 "stroke-color", "white",
					 "line-width", (double)1,
					 NULL);
	  gc_item_focus_init(item, NULL);

	  g_object_set (item, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL);
	  piece->listitem = g_list_append(piece->listitem, item);

	  g_signal_connect(item, "button-press-event",
			   (GCallback) item_event, piece);
	}

      piece->selecteditem = 0;
      item = g_list_nth_data(piece->listitem,
			     piece->selecteditem);
      g_object_set (item, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL);

    }

  return NULL;
}
Beispiel #20
0
static GooCanvasItem*
create_table (GooCanvasItem *parent,
	      gint           row,
	      gint           column,
	      gint           embedding_level,
	      gdouble        x,
	      gdouble        y,
	      gdouble        rotation,
	      gdouble        scale,
	      gint           demo_item_type,
	      gboolean       show_grid_lines)
{
  GooCanvasItem *table;

  /* Add a few simple items. */
  table = goo_canvas_table_new (parent,
				"row-spacing", 4.0,
				"column-spacing", 4.0,
				NULL);

  if (show_grid_lines)
    g_object_set (table,
		  "horz-grid-line-width", 1.0f,
		  "vert-grid-line-width", 1.0f,
		  NULL);

  goo_canvas_item_translate (table, x, y);
#if 1
  goo_canvas_item_rotate (table, rotation, 0, 0);
#endif
#if 1
  goo_canvas_item_scale (table, scale, scale);
#endif

  if (row != -1)
    goo_canvas_item_set_child_properties (parent, table,
					  "row", row,
					  "column", column,
#if 1
					  "x-expand", TRUE,
					  "x-fill", TRUE,
#endif
#if 0
					  "y-expand", TRUE,
					  "y-fill", TRUE,
#endif
					  NULL);

  if (embedding_level)
    {
      gint level = embedding_level - 1;
      create_table (table, 0, 0, level, 50, 50, 0, 0.7, demo_item_type,
		    show_grid_lines);
      create_table (table, 0, 1, level, 50, 50, 45, 1.0, demo_item_type,
		    show_grid_lines);
      create_table (table, 0, 2, level, 50, 50, 90, 1.0, demo_item_type,
		    show_grid_lines);
      create_table (table, 1, 0, level, 50, 50, 135, 1.0, demo_item_type,
		    show_grid_lines);
      create_table (table, 1, 1, level, 50, 50, 180, 1.5, demo_item_type,
		    show_grid_lines);
      create_table (table, 1, 2, level, 50, 50, 225, 1.0, demo_item_type,
		    show_grid_lines);
      create_table (table, 2, 0, level, 50, 50, 270, 1.0, demo_item_type,
		    show_grid_lines);
      create_table (table, 2, 1, level, 50, 50, 315, 1.0, demo_item_type,
		    show_grid_lines);
      create_table (table, 2, 2, level, 50, 50, 360, 2.0, demo_item_type,
		    show_grid_lines);
    }
  else if (demo_item_type == DEMO_TEXT_ITEM_2)
    {
      create_demo_item (table, demo_item_type, 0, 0, 1, 1,
			"(0.0,0.0)\nleft\naligned",
			-1, 0, 0, PANGO_ALIGN_LEFT);
      create_demo_item (table, demo_item_type, 0, 1, 1, 1,
			"(0.5,0.0)\ncenter\naligned",
			-1, 0.5, 0, PANGO_ALIGN_CENTER);
      create_demo_item (table, demo_item_type, 0, 2, 1, 1,
			"(1.0,0.0)\nright\naligned",
			-1, 1, 0, PANGO_ALIGN_RIGHT);

      /* The layout width shouldn't really make any difference in this test. */
      create_demo_item (table, demo_item_type, 1, 0, 1, 1,
			"(0.5,0.5)\ncenter\naligned",
			50, 0.5, 0.5, PANGO_ALIGN_CENTER);
      create_demo_item (table, demo_item_type, 1, 1, 1, 1,
			"(0.0,1.0)\nright\naligned",
			100, 0, 1.0, PANGO_ALIGN_RIGHT);
      create_demo_item (table, demo_item_type, 1, 2, 1, 1,
			"(0.0,0.5)\nleft\naligned",
			200, 0, 0.5, PANGO_ALIGN_LEFT);

      create_demo_item (table, demo_item_type, 2, 0, 1, 1,
			"(1.0,1.0)\ncenter\naligned",
			-1, 1, 1, PANGO_ALIGN_CENTER);
      create_demo_item (table, demo_item_type, 2, 1, 1, 1,
			"(1,0.5)\nright\naligned",
			-1, 1.0, 0.5, PANGO_ALIGN_RIGHT);
      create_demo_item (table, demo_item_type, 2, 2, 1, 1,
			"(0.0,0.0)\nleft\naligned",
			-1, 0, 0, PANGO_ALIGN_LEFT);
    }
  else if (demo_item_type == DEMO_TEXT_ITEM_3)
    {
      create_demo_item (table, demo_item_type, 0, 0, 1, 1,
			"width 50 align 0.0, 0.0 text left aligned",
			50, 0, 0, PANGO_ALIGN_LEFT);
      create_demo_item (table, demo_item_type, 0, 1, 1, 1,
			"width 100 align 0.5, 0.0 text center aligned",
			100, 0.5, 0, PANGO_ALIGN_CENTER);
      create_demo_item (table, demo_item_type, 0, 2, 1, 1,
			"width 150 align 1.0, 0.0 text right aligned",
			150, 1, 0, PANGO_ALIGN_RIGHT);

      create_demo_item (table, demo_item_type, 1, 0, 1, 1,
			"width 50 align 0.5, 0.5 text center aligned",
			50, 0.5, 0.5, PANGO_ALIGN_CENTER);
      create_demo_item (table, demo_item_type, 1, 1, 1, 1,
			"width 100 align 0.0, 1.0 text right aligned",
			100, 0, 1.0, PANGO_ALIGN_RIGHT);
      create_demo_item (table, demo_item_type, 1, 2, 1, 1,
			"width 200 align 0.0, 0.5 text left aligned",
			200, 0, 0.5, PANGO_ALIGN_LEFT);

      create_demo_item (table, demo_item_type, 2, 0, 1, 1,
			"width 50 align 1.0, 1.0 text center aligned",
			50, 1, 1, PANGO_ALIGN_CENTER);
      create_demo_item (table, demo_item_type, 2, 1, 1, 1,
			"width 100 align 1, 0.5 text right aligned",
			100, 1.0, 0.5, PANGO_ALIGN_RIGHT);
      create_demo_item (table, demo_item_type, 2, 2, 1, 1,
			"width 50 align 0.0, 0.0 text left aligned",
			50, 0, 0, PANGO_ALIGN_LEFT);
    }
  else
    {
      create_demo_item (table, demo_item_type, 0, 0, 1, 1, "(0,0)",
			-1, 0, 0.5, PANGO_ALIGN_LEFT);
      create_demo_item (table, demo_item_type, 0, 1, 1, 1, "(1,0)",
			-1, 0, 0.5, PANGO_ALIGN_LEFT);
      create_demo_item (table, demo_item_type, 0, 2, 1, 1, "(2,0)",
			-1, 0, 0.5, PANGO_ALIGN_LEFT);
      create_demo_item (table, demo_item_type, 1, 0, 1, 1, "(0,1)",
			-1, 0, 0.5, PANGO_ALIGN_LEFT);
      create_demo_item (table, demo_item_type, 1, 1, 1, 1, "(1,1)",
			-1, 0, 0.5, PANGO_ALIGN_LEFT);
      create_demo_item (table, demo_item_type, 1, 2, 1, 1, "(2,1)",
			-1, 0, 0.5, PANGO_ALIGN_LEFT);
      create_demo_item (table, demo_item_type, 2, 0, 1, 1, "(0,2)",
			-1, 0, 0.5, PANGO_ALIGN_LEFT);
      create_demo_item (table, demo_item_type, 2, 1, 1, 1, "(1,2)",
			-1, 0, 0.5, PANGO_ALIGN_LEFT);
      create_demo_item (table, demo_item_type, 2, 2, 1, 1, "(2,2)",
			-1, 0, 0.5, PANGO_ALIGN_LEFT);
    }

  return table;
}
Beispiel #21
0
static void
change_transform_clicked (GtkWidget *button, gpointer data)
{
  goo_canvas_item_translate (move_item, 25.0, 25.0);
}
Beispiel #22
0
static VALUE
rg_translate(VALUE self, VALUE tx, VALUE ty)
{
    goo_canvas_item_translate(SELF(self), NUM2DBL(tx), NUM2DBL(ty));
    return self;
}
Beispiel #23
0
GtkWidget *
create_canvas_features (void)
{
	GtkWidget *vbox;
	GtkWidget *w;
	GtkWidget *alignment;
	GtkWidget *frame;
	GtkWidget *canvas;
	GooCanvasItem *root, *item;
	GooCanvasItem *parent1;
	GooCanvasItem *parent2;
	GooCanvasItem *group;

	vbox = gtk_vbox_new (FALSE, 4);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
	gtk_widget_show (vbox);

	/* Instructions */

	w = gtk_label_new ("Reparent test:  click on the items to switch them between parents");
	gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
	gtk_widget_show (w);

	/* Frame and canvas */

	alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
	gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
	gtk_widget_show (alignment);

	frame = gtk_frame_new (NULL);
	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
	gtk_container_add (GTK_CONTAINER (alignment), frame);
	gtk_widget_show (frame);

	canvas = goo_canvas_new ();
	root = goo_canvas_get_root_item (GOO_CANVAS (canvas));

	gtk_widget_set_size_request (canvas, 400, 200);
	goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 400, 200);
	gtk_container_add (GTK_CONTAINER (frame), canvas);
	gtk_widget_show (canvas);

	/* First parent and box */

	parent1 = goo_canvas_group_new (root, NULL);

	goo_canvas_rect_new (parent1, 0, 0, 200, 200,
			     "fill_color", "tan",
			     NULL);

	/* Second parent and box */

	parent2 = goo_canvas_group_new (root, NULL);
	goo_canvas_item_translate (parent2, 200, 0);

	goo_canvas_rect_new (parent2, 0, 0, 200, 200,
			     "fill_color", "#204060",
			     NULL);

	/* Big circle to be reparented */

	item = goo_canvas_ellipse_new (parent1, 100, 100, 90, 90,
				       "stroke_color", "black",
				       "fill_color", "mediumseagreen",
				       "line-width", 3.0,
				       NULL);
	g_object_set_data (G_OBJECT (item), "parent1", parent1);
	g_object_set_data (G_OBJECT (item), "parent2", parent2);
	g_signal_connect (item, "button_press_event",
			  G_CALLBACK (on_button_press), NULL);

	/* A group to be reparented */

	group = goo_canvas_group_new (parent2, NULL);
	goo_canvas_item_translate (group, 100, 100);

	goo_canvas_ellipse_new (group, 0, 0, 50, 50,
				"stroke_color", "black",
				"fill_color", "wheat",
				"line_width", 3.0,
				NULL);
	goo_canvas_ellipse_new (group, 0, 0, 25, 25,
				"fill_color", "steelblue",
				NULL);

	g_object_set_data (G_OBJECT (group), "parent1", parent1);
	g_object_set_data (G_OBJECT (group), "parent2", parent2);
	g_signal_connect (group, "button_press_event",
			  G_CALLBACK (on_button_press), NULL);

	return vbox;
}
Beispiel #24
0
// show_weight:
// 0 -> no unit,
// 1 -> display g, 1000 -> display kg,
// 10000 -> random (weighted 1:2)
static ScaleItem *
scale_list_add_weight(GooCanvasItem *group,
		      gint weight, int show_weight)
{
  ScaleItem *new_item;
  GdkPixbuf *pixmap;
  gchar *weight_text;
  double x, y;
  GList *last;

  last = g_list_last(item_list);
  if(last)
    {
      new_item = last->data;
      x = new_item->x + ITEM_W;
      y = new_item->y;
      if(x > ITEM_X_MAX)
        {
	  x = ITEM_X_MIN;
	  y += ITEM_H;
	  if(y > ITEM_Y_MAX)
	    g_warning("No more place for new item");
        }
    }
  else
    {
      x = ITEM_X_MIN;
      y = ITEM_Y_MIN;
    }

  new_item = g_new0(ScaleItem, 1);
  new_item->x = x;
  new_item->y = y;
  new_item->weight = weight;

  /* If selected, display multiples of 500g as 'g' or 'kg' randomly */
  if (show_weight > 9999) {
    if ((weight % 500) == 0)
  	show_weight = g_random_int_range(1,3000);
    else
	show_weight = 1;
  }

  if (show_weight < 1000) {
    	weight_text = g_strdup_printf("%d%s", weight, show_weight ? "\n  g" : "");
  } else {
  	int thousand = weight / 1000;
  	int hundred = (weight % 1000) / 100;
    	weight_text = g_strdup_printf("%c %c\n  kg", '0' + thousand, '0' + hundred);
  }
  pixmap = gc_pixmap_load("scale/masse.png");

  new_item->item = goo_canvas_group_new(group, NULL);
  goo_canvas_image_new(new_item->item,
		       pixmap,
		       0, 0,
		       NULL);
  goo_canvas_text_new(new_item->item,
		      weight_text,
		      18,
		      35,
		      -1,
		      GTK_ANCHOR_CENTER,
		      "font", "sans 10",
		      "fill_color_rgba", 0x000000FFL,
		      NULL);

  goo_canvas_item_translate(new_item->item,
			    new_item->x,
			    new_item->y);
  gdk_pixbuf_unref(pixmap);
  g_free(weight_text);

  gc_item_focus_init(new_item->item, NULL);
  g_signal_connect(new_item->item, "button_press_event",
		   (GtkSignalFunc)gc_drag_event, new_item);
  g_signal_connect(new_item->item, "button_release_event",
		   (GtkSignalFunc)gc_drag_event, new_item);
  g_signal_connect(new_item->item, "button_press_event",
  		   (GtkSignalFunc) scale_item_event, new_item);

  item_list = g_list_append(item_list, new_item);
  return new_item;
}
Beispiel #25
0
void
scale_anim_plate(void)
{
  double delta_y;
  double angle;
  double scale;
  int diff;

  // in MODE_WEIGHT the granularity is gramm, so we use a different factor
  scale = (board_mode == MODE_WEIGHT) ? 2000.0 : 10.0;
  diff = get_weight_plate(0);
  delta_y = CLAMP(PLATE_Y_DELTA / scale * diff,
		  -PLATE_Y_DELTA, PLATE_Y_DELTA);

  if(get_weight_plate(1) == 0)
    delta_y = -PLATE_Y_DELTA;

  /* Update the sign */
  if (diff == 0)
    g_object_set(sign, "text", "=", NULL);
  else if (diff < 0)
    g_object_set(sign, "text", "<", NULL);
  else
    g_object_set(sign, "text", ">", NULL);


  if(last_delta != delta_y)
    {
      goo_canvas_item_translate(group_g, 0, -last_delta);
      goo_canvas_item_translate(group_d, 0, last_delta);

      last_delta = delta_y;

      angle = tan(delta_y / 138) * 180 / M_PI;

      goo_canvas_item_translate(group_g, 0, delta_y);
      goo_canvas_item_translate(group_d, 0, -delta_y);

      gc_item_rotate_with_center(bras, -angle, 138, 84);
    }

  if(diff == 0 && ask_for_answer)
    {

      double x_offset = BOARDWIDTH/2;
      double y_offset = BOARDHEIGHT*0.7;

      GooCanvasItem *item = goo_canvas_svg_new (boardRootItem,
						gc_skin_rsvg_get(),
						"svg-id", "#BUTTON_TEXT",
						NULL);
      SET_ITEM_LOCATION_CENTER(item,
			       x_offset / 2,
			       y_offset);
      goo_canvas_item_scale(item, 2, 1);

      answer_item = goo_canvas_text_new(boardRootItem,
					"",
					x_offset,
					y_offset,
					-1,
					GTK_ANCHOR_CENTER,
					"font", gc_skin_font_board_title_bold,
					"fill-color", "white",
					NULL);

      answer_string = g_string_new(NULL);
      key_press(0, NULL, NULL);
    }
  else if(diff == 0)
    process_ok();
}
Beispiel #26
0
void
money_widget_add (MoneyWidget *moneyWidget, MoneyEuroType value)
{
  GooCanvasItem *item;
  RsvgHandle    *svg_handle;
  RsvgDimensionData dimension;
  double	 xratio, yratio, ratio;
  double	 block_width, block_height;
  MoneyItem	*moneyitem;
  guint		 i, length;

  g_return_if_fail (moneyWidget != NULL);

  /* Search for an hidden item with the same value */
  length = g_list_length(moneyWidget->priv->moneyItemList);
  for(i=0; i<length; i++)
    {
      moneyitem = \
	(MoneyItem *)g_list_nth_data(moneyWidget->priv->moneyItemList,
				     i);

      if(moneyitem && !moneyitem->inPocket && moneyitem->value == value)
	{
	  g_object_set (moneyitem->item,
			"visibility", GOO_CANVAS_ITEM_VISIBLE, NULL);
	  moneyitem->inPocket = TRUE;
	  moneyWidget->priv->total += euroList[value].value;
	  money_display_total(moneyWidget);
	  return;
	}
    }

  /* There is no already suitable item create, create a new one */

  if(moneyWidget->priv->next_spot
     > moneyWidget->priv->columns * moneyWidget->priv->lines)
    g_message("More money items requested than the pocket size\n");

  block_width  = \
    (moneyWidget->priv->x2 - moneyWidget->priv->x1)
    / moneyWidget->priv->columns;
  block_height = \
    (moneyWidget->priv->y2 - moneyWidget->priv->y1) / moneyWidget->priv->lines;

  svg_handle = gc_rsvg_load(euroList[value].image);

  rsvg_handle_get_dimensions(svg_handle, &dimension);

  xratio =  block_width  / (dimension.width + BORDER_GAP);
  yratio =  block_height / (dimension.height + BORDER_GAP);
  ratio = yratio = MIN(xratio, yratio);

  item =  goo_canvas_svg_new(moneyWidget->priv->rootItem,
			   svg_handle,
			   NULL);

  goo_canvas_item_translate(item,
			    moneyWidget->priv->x1 +
			    (moneyWidget->priv->next_spot % moneyWidget->priv->columns) * block_width
			    +  block_width/2 - (dimension.width * ratio)/2,
			    moneyWidget->priv->y1 +
			    (moneyWidget->priv->next_spot / moneyWidget->priv->columns)
			    * (block_height + BORDER_GAP)
			    + block_height/2 - (dimension.height * ratio)/2);
  goo_canvas_item_scale(item,
			ratio,
  			ratio);

  moneyitem = g_malloc(sizeof(MoneyItem));
  moneyitem->moneyWidget = moneyWidget;
  moneyitem->item   = item;
  moneyitem->value  = value;
  moneyitem->inPocket = TRUE;

  moneyWidget->priv->moneyItemList = \
    g_list_append (moneyWidget->priv->moneyItemList,
		   moneyitem);

  g_signal_connect(item,
		   "button_press_event", (GCallback) item_event,
		   moneyitem);

  g_object_unref(svg_handle);

  moneyWidget->priv->next_spot++;

  moneyWidget->priv->total += euroList[value].value;

  money_display_total(moneyWidget);
}
Beispiel #27
0
/*
 * Do all the bar display and register the events
 */
void
gc_config_start ()
{
  GcomprisProperties	*properties = gc_prop_get();
  gint y_start = 0;
  gint x_start = 0;
  gint x_text_start = 0;
  gint y = 0;
  GooCanvasItem *item;

  /* Pause the board */
  gc_board_pause(TRUE);

  if(rootitem)
  {
    gc_config_stop();
    return;
  }

  gc_bar_hide(TRUE);

  rootitem = goo_canvas_group_new (goo_canvas_get_root_item(gc_get_canvas()),
				   NULL);

  item = goo_canvas_svg_new (rootitem,
			     gc_skin_rsvg_get(),
			     "svg-id", "#DIALOG",
			     "pointer-events", GOO_CANVAS_EVENTS_NONE,
			     NULL);

  GooCanvasBounds bounds;
  goo_canvas_item_get_bounds(item, &bounds);
  x_start = bounds.x1;
  y_start = bounds.y1;

  y = bounds.y2 - 26;

  goo_canvas_text_new (rootitem,
		       _("GCompris Configuration"),
		       (gdouble) BOARDWIDTH/2,
		       (gdouble) y_start + 40,
		       -1,
		       GTK_ANCHOR_CENTER,
		       "font", gc_skin_font_title,
		       "fill-color-rgba", gc_skin_color_title,
		       NULL);

  pixmap_checked   = "#CHECKED";
  pixmap_unchecked = "#UNCHECKED";
  pixmap_width = 30;

  x_start += 60;
  x_text_start = x_start + 80;

  //--------------------------------------------------
  // Locale
  y_start += 105;

  display_previous_next(x_start, y_start, "locale_previous", "locale_next");

  y_flag_start = y_start - pixmap_width/2;

  /* A repeat icon to reset the selection */
  item = goo_canvas_svg_new (rootitem,
			     gc_skin_rsvg_get(),
			     "svg-id", "#REPEAT",
			     NULL);
    goo_canvas_item_get_bounds(item, &bounds);
    double zoom = 0.50;
    goo_canvas_item_scale(item, zoom, zoom);
    goo_canvas_item_translate(item,
			      (-1 * bounds.x1 + x_start - 100) * zoom,
			      (-1 * bounds.y1 + y_start - 145) * zoom);
  g_signal_connect(item, "button_press_event",
		   (GCallback) item_event_ok,
		   "locale_reset");
  gc_item_focus_init(item, NULL);

  /*
   * The current locale is the one found in the config file
   */
  current_locale = properties->locale;
  set_locale_flag(current_locale);

  item_locale_text = goo_canvas_text_new (rootitem,
					  gc_locale_get_name(current_locale),
					  (gdouble) x_text_start,
					  (gdouble) y_start,
					  -1,
					  GTK_ANCHOR_WEST,
					  "font", gc_skin_font_content,
					  "fill-color-rgba", gc_skin_color_content,
					  NULL);

  // Fullscreen / Window
  y_start += Y_GAP;

  item = goo_canvas_svg_new (rootitem,
			     gc_skin_rsvg_get(),
			     "svg-id", (properties->fullscreen ? pixmap_checked : pixmap_unchecked),
			     NULL);
  SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2);

  g_signal_connect(item, "button_press_event",
		   (GCallback) item_event_ok,
		   "fullscreen");
  gc_item_focus_init(item, NULL);


  goo_canvas_text_new (rootitem,
		       _("Fullscreen"),
		       (gdouble) x_text_start,
		       (gdouble) y_start,
		       -1,
		       GTK_ANCHOR_WEST,
		       "font", gc_skin_font_content,
		       "fill-color-rgba", gc_skin_color_content,
		       NULL);

  // Rememberlevel
  y_start += Y_GAP;

  item = goo_canvas_svg_new (rootitem,
			     gc_skin_rsvg_get(),
			     "svg-id", (properties->rememberlevel ? pixmap_checked : pixmap_unchecked),
			     NULL);
  SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2);

  g_signal_connect(item, "button_press_event",
		   (GCallback) item_event_ok,
		   "rememberlevel");
  gc_item_focus_init(item, NULL);


  goo_canvas_text_new (rootitem,
		       _("Remember level for default user"),
		       (gdouble) x_text_start,
		       (gdouble) y_start,
		       -1,
		       GTK_ANCHOR_WEST,
		       "font", gc_skin_font_content,
		       "fill-color-rgba", gc_skin_color_content,
		       NULL);


  // Music
  y_start += Y_GAP;

  item = goo_canvas_svg_new (rootitem,
			     gc_skin_rsvg_get(),
			     "svg-id", (properties->music ? pixmap_checked : pixmap_unchecked),
			     NULL);
  SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2);

  g_signal_connect(item, "button_press_event",
		   (GCallback) item_event_ok,
		   "music");
  gc_item_focus_init(item, NULL);


  goo_canvas_text_new (rootitem,
		       _("Music"),
		       (gdouble) x_text_start,
		       (gdouble) y_start,
		       -1,
		       GTK_ANCHOR_WEST,
		       "font", gc_skin_font_content,
		       "fill-color-rgba", gc_skin_color_content,
		       NULL);

  // Effect
  y_start += Y_GAP;

  item = goo_canvas_svg_new (rootitem,
			     gc_skin_rsvg_get(),
			     "svg-id", (properties->fx ? pixmap_checked : pixmap_unchecked),
			     NULL);
  SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2);

  g_signal_connect(item, "button_press_event",
		   (GCallback) item_event_ok,
		   "effect");
  gc_item_focus_init(item, NULL);


  goo_canvas_text_new (rootitem,
		       _("Effect"),
		       (gdouble) x_text_start,
		       (gdouble) y_start,
		       -1,
		       GTK_ANCHOR_WEST,
		       "font", gc_skin_font_content,
		       "fill-color-rgba", gc_skin_color_content,
		       NULL);

  // Zoom
  y_start += Y_GAP;

  item = goo_canvas_svg_new (rootitem,
			     gc_skin_rsvg_get(),
			     "svg-id", (properties->zoom ? pixmap_checked : pixmap_unchecked),
			     NULL);
  SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2);

  g_signal_connect(item, "button_press_event",
		   (GCallback) item_event_ok,
		   "zoom");
  gc_item_focus_init(item, NULL);

  goo_canvas_text_new (rootitem,
		       _("Zoom"),
		       (gdouble) x_text_start,
		       (gdouble) y_start,
		       -1,
		       GTK_ANCHOR_WEST,
		       "font", gc_skin_font_content,
		       "fill-color-rgba", gc_skin_color_content,
		       NULL);

  // Timer
  y_start += Y_GAP;

  display_previous_next(x_start, y_start, "timer_previous", "timer_next");

  item_timer_text = goo_canvas_text_new (rootitem,
					 gettext(timername[properties->timer]),
					 (gdouble) x_text_start,
					 (gdouble) y_start,
					 -1,
					 GTK_ANCHOR_WEST,
					 "font", gc_skin_font_content,
					 "fill-color-rgba", gc_skin_color_content,
					 NULL);

  // Font
  y_start += Y_GAP;
  {
    int i;
    PangoFontFamily ** families;
    int n_families;
    PangoFontMap * fontmap;
    const gchar *current_familly_name = NULL;

    fontmap = pango_cairo_font_map_get_default();
    pango_font_map_list_families (fontmap, & families, & n_families);
    for (i = 0; i < n_families; i++) {
        PangoFontFamily * family = families[i];
        const gchar * family_name;
        family_name = pango_font_family_get_name (family);

	/* Skip font to exclude */
	guint j = 0;
	gboolean exclude = FALSE;
	while(excluded_fonts[j] != NULL) {
	  if( !g_ascii_strncasecmp(excluded_fonts[j], family_name,
				   strlen(excluded_fonts[j])) ) {
	    exclude = TRUE;
	    break;
	  }
	  j++;
	}
	if(exclude)
	  continue;
	fontlist = g_list_insert_sorted (fontlist, (gpointer)family_name,
					 (GCompareFunc)strcmp);
	if(!strcmp(properties->fontface, family_name))
	  current_familly_name = family_name;
    }
    g_free (families);

    current_font_index = font_index = g_list_index(fontlist, current_familly_name);
    display_previous_next(x_start, y_start, "font_previous", "font_next");

    /* A repeat icon to reset the selection */
    item = goo_canvas_svg_new (rootitem,
			       gc_skin_rsvg_get(),
			       "svg-id", "#REPEAT",
			       NULL);
    goo_canvas_item_get_bounds(item, &bounds);
    double zoom = 0.50;
    goo_canvas_item_scale(item, zoom, zoom);
    goo_canvas_item_translate(item,
			      (-1 * bounds.x1 + x_start - 100) * zoom,
			      (-1 * bounds.y1 + y_start + 650) * zoom);
    g_signal_connect(item, "button_press_event",
		     (GCallback) item_event_ok,
		     "fontface_reset");
    gc_item_focus_init(item, NULL);

    gchar *first_font_name = g_strdup_printf(_("Font: %s"), (char *)g_list_nth_data(fontlist, font_index));
    item_font_text = goo_canvas_text_new (rootitem,
					  first_font_name,
					  (gdouble) x_text_start,
					  (gdouble) y_start,
					  -1,
					  GTK_ANCHOR_WEST,
					  "font", gc_skin_font_content,
					  "fill-color-rgba", gc_skin_color_content,
					  NULL);
  }

  // Difficulty Filter
  y_start += Y_GAP;

  stars_group_x = x_start + 45;
  stars_group_y = y_start - 25;
  gchar *text = g_strdup_printf("<i>%s</i>", gettext(filtername));
  item_filter_text = goo_canvas_text_new (rootitem,
					  text,
					  x_text_start,
					  y_start,
					  400,
					  GTK_ANCHOR_WEST,
					  "use-markup", TRUE,
					  "font", gc_skin_font_content,
					  "fill-color-rgba", gc_skin_color_content,
					  NULL);
  g_free(text);


  // OK
  gc_util_button_text_svg(rootitem,
			  BOARDWIDTH * 0.5,
			  y,
			  "#BUTTON_TEXT",
			  _("OK"),
			  (GCallback) item_event_ok,
			  "ok");

  is_displayed = TRUE;
}
Beispiel #28
0
/* =====================================================================
 * set initial values for the next level
 * =====================================================================*/
static void maze_next_level() {
  GdkPixbuf *pixmap = NULL;

  maze_destroy_all_items();
  gc_bar_set_level(gcomprisBoard);
  setlevelproperties();

  mapActive = FALSE;

  ind = 0;
  gamewon = FALSE;
  initMaze();
  generateMaze((g_random_int()%breedte),(g_random_int()%hoogte));
  removeSet();
  /* Try the next level */
  maze_create_item(goo_canvas_get_root_item(gcomprisBoard->canvas));
  draw_background(wallgroup);

  if(modeIsInvisible) {
    g_object_set (wallgroup, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL);
  }

  /* make a new group for the items */
  begin=g_random_int()%hoogte;
  end=g_random_int()%hoogte;

  /* Draw the tux */
  RsvgHandle *svg_handle = gc_rsvg_load("maze/tux_top_south.svg");
  tuxitem = goo_canvas_svg_new (tuxgroup, svg_handle,
				NULL);
  g_object_unref (svg_handle);

  goo_canvas_item_translate(tuxgroup,
			    cellsize*(0)-breedte + board_border_x,
			    cellsize*(begin)-hoogte + board_border_y);

  g_signal_connect(tuxitem,
		   "button_press_event",
		   (GCallback) tux_event, NULL);

  if(run_fast_possible) {
	  /* Load the tux shoes */
	  svg_handle = gc_rsvg_load("maze/tux_shoes_top_south.svgz");
	  tuxshoes = goo_canvas_svg_new (tuxgroup, svg_handle,
					"pointer-events", GOO_CANVAS_EVENTS_NONE, NULL);
	  g_object_unref (svg_handle);

	  /* Load fast-mode switch button */
	  svg_handle = gc_rsvg_load("maze/fast-mode-button.svgz");
	  fast_mode_button = goo_canvas_svg_new (boardRootItem, svg_handle,
					NULL);
	  g_object_unref (svg_handle);
	  goo_canvas_item_translate(fast_mode_button, 10, 10);
	  g_signal_connect(fast_mode_button,
			   "button_press_event",
			   (GCallback) on_fast_mode_button_press, NULL);
	  gc_item_focus_init(fast_mode_button, NULL);
  }

  /* Draw the target */
  pixmap = gc_pixmap_load("maze/door.png");
  if(pixmap)
    {
      draw_image(mazegroup,breedte-1,end,pixmap);
#if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24
      gdk_pixbuf_unref(pixmap);
#else
      g_object_unref(pixmap);
#endif
    }

  position[ind][0]=0;
  position[ind][1]=begin;
  Maze[0][begin]=Maze[0][begin]+SET;
  viewing_direction=EAST;
  threeDactive=FALSE;

  if(run_fast_possible) {
	  // run_fast-mode should be initialized at every level, whether TRUE or FALSE
	  if (gcomprisBoard->level < 14) set_run_fast(FALSE);
	  if (gcomprisBoard->level >= 14) set_run_fast(TRUE);
  }

  update_tux(viewing_direction);

  if(!modeIs2D)
    threeDdisplay();

}
Beispiel #29
0
static GooCanvasItem *planegame_create_item(GooCanvasItem *parent)
{
    RsvgHandle *svg_handle;
    RsvgDimensionData dimension;
    GooCanvasItem *itemgroup;
    GooCanvasItem *item;
    char *number = NULL;
    int i, min;
    guint y;

    /* Random cloud number */
    if(g_random_int()%2==0)
    {
        /* Put the target */
        i = plane_target;
    }
    else
    {
        min = MAX(1, plane_target - 1);
        i   = min + g_random_int()%(plane_target - min + 3);
    }
    number = g_strdup_printf("%d", i);

    itemgroup = goo_canvas_group_new (parent, NULL);

    g_object_set_data (G_OBJECT (itemgroup),
                       "cloud_number", GINT_TO_POINTER (i));

    svg_handle = gc_rsvg_load("planegame/cloud.svgz");
    rsvg_handle_get_dimensions(svg_handle, &dimension);

    y = (g_random_int()%(BOARDHEIGHT - 40 -
                         (guint)(dimension.height * imageZoom)));

    goo_canvas_item_translate(itemgroup,
                              BOARDWIDTH,
                              y);

    item = goo_canvas_svg_new (itemgroup,
                               svg_handle,
                               NULL);
    goo_canvas_item_scale(item, imageZoom, imageZoom);

    g_object_unref(svg_handle);

    g_object_set_data (G_OBJECT (item),
                       "cloud_number", GINT_TO_POINTER (i));

    item = goo_canvas_text_new (itemgroup,
                                number,
                                dimension.width*imageZoom/2,
                                dimension.height*imageZoom/2,
                                -1,
                                GTK_ANCHOR_CENTER,
                                "font", gc_skin_font_board_big,
                                "fill-color", "red",
                                NULL);

    g_object_set_data (G_OBJECT (item),
                       "cloud_number", GINT_TO_POINTER (i));

    goo_canvas_item_animate(itemgroup,
                            -dimension.width*imageZoom,
                            y,
                            1.0,
                            0,
                            TRUE,
                            40*BOARDWIDTH,
                            40,
                            GOO_CANVAS_ANIMATE_FREEZE);

    /* The plane is always on top */
    goo_canvas_item_raise(itemgroup, NULL);
    goo_canvas_item_raise(planeitem, NULL);

    g_free (number);

    return (itemgroup);
}
Beispiel #30
0
/* set initial values for the next level */
static void planegame_next_level()
{
    RsvgHandle *svg_handle = NULL;
    GooCanvasItem *item;

    gc_bar_set_level(gcomprisBoard);

    planegame_destroy_all_items();

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

    clouds_rootitem = goo_canvas_group_new (rootitem, NULL);

    /* Try the next level */
    speed=100+(40/(gcomprisBoard->level));
    fallSpeed=10000-gcomprisBoard->level*200;
    /* Make the images tend to 0.5 ratio */
    imageZoom=0.3+(0.5/(gcomprisBoard->level));

    /* Setup and Display the plane */
    planespeed_y = 0;
    planespeed_x = 0;
    svg_handle = gc_rsvg_load("planegame/tuxhelico.svgz");
    plane_x = 50;
    plane_y = 300;

    planeitem = goo_canvas_group_new (rootitem,
                                      NULL);

    goo_canvas_item_translate(planeitem, plane_x, plane_y);

    item = goo_canvas_svg_new (planeitem,
                               svg_handle,
                               NULL);

    goo_canvas_item_scale(item,
                          0.4 * imageZoom,
                          0.4 * imageZoom);

    g_object_unref(svg_handle);

    /* Game rules */
    plane_target = 1;
    plane_last_target = 10;

    gcomprisBoard->number_of_sublevel=plane_last_target;

    gcomprisBoard->sublevel=plane_target;

    if(gcomprisBoard->level>1)
    {
        /* No scoring after level 1 */
        gc_score_end();
    }
    else
    {
        gc_score_start(SCORESTYLE_NOTE,
                       BOARDWIDTH - 195,
                       BOARDHEIGHT - 30,
                       gcomprisBoard->number_of_sublevel);
        gc_score_set(gcomprisBoard->sublevel);
    }

}