Re: Help on GnomeCanvasImage



>  I'm writing a game and am using the GnomeCanvas and GnomeCanvasItem functions
>  significantly. In this code snippet, I'm trying to add a GnomeCanvasImage
>  to my GnomeCanvas. I get no compiler or run-time errors. But the image
>  never gets displayed. What am I doing wrong?

[snip]

>    GtkWidget             *board;
>    board = gnome_canvas_item_new (gnome_canvas_root(canvas),
>                                   GNOME_TYPE_CANVAS_IMAGE,
>                                   "image", board_image,
>                                   "x", 0, "y", 0, "width", 400, "height", 400,
>                                   "anchor", GTK_ANCHOR_NW,
>                                   NULL);

The coordinates and dimensions must be specified as doubles.  Change
the fourth line to be
				    "x", 0.0,
				    "y", 0.0,
				    "width", 400.0,
				    "height", 400.0,

Also, "GtkWidget *board;" is incorrect, since gnome_canvas_item_new()
returns a GnomeCanvasItem *.

>    gtk_widget_show(board); // Actually not needed because the CanvasItem is
>                            // is visible by default.

This will give you a runtime type error, since a canvas item is not a
widget.  Canvas items are shown and hidden with
gnome_canvas_item_{show,hide}(), respectively; they are shown by
default, so you do not need to show them initially.

  Federico



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]