Re: Anti-Aliased 2D drawing



There is an example in the demos directory of the libgnomecanvas
sources. 

You may also want to have a look at the documentation for the
GGAD book, which, although for Gnome-1 still has some valid code
for the gnome canvas. Look for the create_canvas_items() function
at: http://developer.gnome.org/doc/GGAD/z177.html . It shows
you the basic method:

   /* Create the canvas and set it up so that 0,0 is in the topleft   
    * corner.
    */
   GtkWidget *canvas = gnome_canvas_new_aa();
   gtk_widget_set_size_request(w_canvas,
                               CANVAS_WIDTH, CANVAS_HEIGHT);
   gnome_canvas_set_scroll_region(GNOME_CANVAS(w_canvas),
                                  0.0, 0.0, CANVAS_WIDTH, CANVAS_HEIGHT);


   /* Get the root group */
   GnomeCanvasGroup *root = gnome_canvas_root(GNOME_CANVAS(canvas));

   /* Read the image into a pixbuf */
   GdkPixbuf *pb = gdk_pixbuf_new_from_file(image, &err);
   
   /* Create an canvas item containing the image */
   image = gnome_canvas_item_new (root,
                                  gnome_canvas_pixbuf_get_type (),
                                   "pixbuf", pb,
                                   "x", 0.0,
                                   "y", 0.0,
                                   "width", (double) gdk_pixbuf_get_width(pb),
                                   "height", (double) gdk_pixbuf_get_height(pb),
                                   NULL);

   /* create lines etc on top of the image *
   GnomeCanvasPoints* points = gnome_canvas_points_new (2);

   points->coords[0] = 0.0;
   points->coords[1] = 150.0;
   points->coords[2] = 600.0;
   points->coords[3] = 150.0;

   gnome_canvas_item_new (group,
                          gnome_canvas_line_get_type (),
                          "points", points,
                          "fill_color", "black",
                          "width_units", 4.0,
                           NULL);


If you want to tie events to the canvas items you of course have to
assign these to variables and bind these seperately.

Hope this helps.

Regards,
Dov
     
On Mon, May 16, 2005 at 03:17:17PM -0400, Scott Robert Ladd wrote:
> Roger Leigh wrote:
> > Have you taken a look at libgnomecanvas?  Despite the name, it only
> > depends on GTK+, and it allows anti-aliased line drawings of arbitrary
> > size.
> > 
> > I don't know, but I suspect it will be replaced by, or depend upon,
> > Cairo at some point, but it's mature and usable right now.
> 
> My only problem is in finding a reasonable tutorial for GnomeCanvas. If
> you know of one, I'd appreciate a pointer to it.
> 
> I'm just drawing lins on top of an existing pixbuf; nothing terribly
> complex. I think I'm doing everything right, but the line doesn't show
> up. A quick tutorial will probably show me the obvious.
> 
> ..Scott
> 
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list



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